3 # Copyright (c) 2007-09 The DragonFly Project. All rights reserved.
5 # This code is derived from software contributed to The DragonFly Project
6 # by Matthias Schmidt <matthias@dragonflybsd.org>, University of Marburg.
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions are met:
13 # - Redistributions of source code must retain the above copyright notice,
14 # this list of conditions and the following disclaimer.
15 # - Redistributions in binary form must reproduce the above copyright notice,
16 # this list of conditions and the following disclaimer in the documentation
17 # and/or other materials provided with the distribution.
18 # - Neither the name of The DragonFly Project nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific, prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # $DragonFly: src/usr.bin/pkg_search/pkg_search.sh,v 1.11 2008/09/04 10:33:50 matthias Exp $
37 VERSION=`uname -r | awk -F - '{ print $1; }'`
40 PKGSUM=${PORTSDIR}/pkg_summary
41 if [ -z "$BINPKG_SITES" ]; then
42 BINPKG_SITES=http://avalon.dragonflybsd.org/packages/${UNAME}-${VERSION}/stable/
43 [ -f /etc/settings.conf ] && . /etc/settings.conf
45 PKGSRCBOX1=$BINPKG_SITES
46 PKGSRCBOX2=http://avalon.dragonflybsd.org/packages/DragonFly-2.2.0/stable/
49 # Download the pkg_summary file
52 echo "Fetching pkg_summary(5) file."
53 FETCHPATH=${PKGSRCBOX1}/All/pkg_summary.bz2
54 fetch -o ${PKGSUM}.bz2 ${FETCHPATH}
56 FETCHPATH=${PKGSRCBOX2}/All/pkg_summary.bz2
57 fetch -o ${PKGSUM}.bz2 ${FETCHPATH}
60 echo "Unable to fetch pkg_summary(5) file."
63 bunzip2 < ${PKGSUM}.bz2 > ${PKGSUM}
67 # Perform simple search in pkg_summary
70 awk -F= -v name="$1" '{
71 if ($1 == "PKGNAME") {
72 if (tolower($2) ~ name) {
73 printf("%-20s\t", $2);
78 if (found == 1 && $1 == "COMMENT") printf("%-25s\n", $2);
82 # Perform extended search in pkg_summary
85 awk -F= -v name="$1" '{
87 if (tolower($2) ~ name) {
88 printf("\nName\t: %-50s\n", $2);
93 if (found == 1 && $1 == "COMMENT")
94 printf("Desc\t: %-50s\n", $2);
95 if (found == 1 && $1 == "PKGPATH")
96 printf("Path\t: %-50s\n", $2);
97 if (found == 1 && $1 == "HOMEPAGE")
98 printf("URL\t: %-50s\n", $2);
102 # Perform extended search in INDEX
105 if [ ${KFLAG} -eq 0 ]; then
106 awk -F\| -v name="$1" '{
107 if (tolower($1) ~ name) {
108 printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\
109 "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2,
112 }' ${PORTSDIR}/${INDEXFILE}
114 awk -F\| -v name="$1" '{
115 if (tolower($1) ~ name || tolower($4) ~ name ||
116 tolower($12) ~ name) {
117 printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\
118 "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2,
121 }' ${PORTSDIR}/${INDEXFILE}
125 # Perform simple search in INDEX
128 if [ ${KFLAG} -eq 0 ]; then
129 awk -F\| -v name="$1" '{
130 if (tolower($1) ~ name) {
131 printf("%-20s\t%-25s\n", $1, $4);
133 }' ${PORTSDIR}/${INDEXFILE}
135 awk -F\| -v name="$1" '{
136 if (tolower($1) ~ name || tolower($4) ~ name ||
137 tolower($12) ~ name) {
138 printf("%-20s\t%-25s\n", $1, $4);
140 }' ${PORTSDIR}/${INDEXFILE}
146 PDESC=`awk -F\| -v name="$1" '{
147 if (tolower($1) == name) {
148 split($2, ppath, "/");
151 }' ${PORTSDIR}/${INDEXFILE}`
152 if [ -f "${PORTSDIR}/${PDESC}" ]; then
153 cat "${PORTSDIR}/${PDESC}"
155 echo "Unable to locate package $1. Please provide the exact"
156 echo "package name as given by pkg_search(1). You need the"
157 echo "complete pkgsrc(7) tree to perform this operation."
163 echo "usage: `basename $0` [-kv] package"
164 echo " `basename $0` -s package"
165 echo " `basename $0` -d"
169 if [ ! -f ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then
170 echo "No pkgsrc(7) tree found."
175 if [ -e ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then
179 args=`getopt dksv $*`
202 if [ ${DFLAG} -eq 0 -a -z ${1} ]; then
206 if [ ${DFLAG} -eq 1 ]; then
211 if [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 1 ]; then
213 elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 1 ]; then
215 elif [ ${SFLAG} -eq 1 -a ${NO_INDEX} -eq 0 ]; then
217 elif [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 0 ]; then
219 elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 0 ]; then