3 # Copyright (c) 2007-08 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.8.2.2 2008/08/27 13:15:21 matthias Exp $
37 VERSION
=`uname -r | cut -d '.' -f 1,2`
40 PKGSUM
=${PORTSDIR}/pkg_summary
41 PKGSRCBOX1
=http
://pkgbox.dragonflybsd.org
/packages
/${UNAME}-${VERSION}/stable
/
42 PKGSRCBOX2
=http
://pkgbox.dragonflybsd.org
/packages
/DragonFly-2.0
/stable
/
45 if [ ! -f ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then
46 echo "No pkgsrc(7) tree found. Fetching pkg_summary(5) file."
47 FETCHPATH
=${PKGSRCBOX1}/All
/pkg_summary.bz2
49 fetch
-o ${PKGSUM}.bz2
${FETCHPATH}
51 FETCHPATH
=${PKGSRCBOX2}/All
/pkg_summary.bz2
52 fetch
-o ${PKGSUM}.bz2
${FETCHPATH}
55 echo "Unable to fetch pkg_summary(5) file."
58 bunzip2
< ${PKGSUM}.bz2
> ${PKGSUM}
62 if [ -e ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then
66 # Perform simple search in pkg_summary
69 awk -F= -v name
="$1" '{
70 if ($1 == "PKGNAME") {
71 if (tolower($2) ~ name) {
72 printf("%-20s\t", $2);
77 if (found == 1 && $1 == "COMMENT") printf("%-25s\n", $2);
81 # Perform extended search in pkg_summary
84 awk -F= -v name
="$1" '{
86 if (tolower($2) ~ name) {
87 printf("\nName\t: %-50s\n", $2);
92 if (found == 1 && $1 == "COMMENT")
93 printf("Desc\t: %-50s\n", $2);
94 if (found == 1 && $1 == "PKGPATH")
95 printf("Path\t: %-50s\n", $2);
96 if (found == 1 && $1 == "HOMEPAGE")
97 printf("URL\t: %-50s\n", $2);
101 # Perform extended search in INDEX
104 if [ ${KFLAG} -eq 0 ]; then
105 awk -F\|
-v name
="$1" '{
106 if (tolower($1) ~ name) {
107 printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\
108 "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2,
111 }' ${PORTSDIR}/${INDEXFILE}
113 awk -F\|
-v name
="$1" '{
114 if (tolower($1) ~ name || tolower($4) ~ name ||
115 tolower($12) ~ name) {
116 printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\
117 "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2,
120 }' ${PORTSDIR}/${INDEXFILE}
124 # Perform simple search in INDEX
127 if [ ${KFLAG} -eq 0 ]; then
128 awk -F\|
-v name
="$1" '{
129 if (tolower($1) ~ name) {
130 printf("%-20s\t%-25s\n", $1, $4);
132 }' ${PORTSDIR}/${INDEXFILE}
134 awk -F\|
-v name
="$1" '{
135 if (tolower($1) ~ name || tolower($4) ~ name ||
136 tolower($12) ~ name) {
137 printf("%-20s\t%-25s\n", $1, $4);
139 }' ${PORTSDIR}/${INDEXFILE}
145 PDESC
=`awk -F\| -v name="$1" '{
146 if (tolower($1) == name) {
147 split($2, ppath, "/");
150 }' ${PORTSDIR}/${INDEXFILE}`
151 if [ -f "${PORTSDIR}/${PDESC}" ]; then
152 cat "${PORTSDIR}/${PDESC}"
154 echo "Unable to locate package $1. Please provide the exact"
155 echo "package name as given by pkg_search(1). You need the"
156 echo "complete pkgsrc(7) tree to perform this operation."
162 echo "usage: $0 [ -k | -s | -v ] package"
190 if [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 1 ]; then
192 elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 1 ]; then
194 elif [ ${SFLAG} -eq 1 -a ${NO_INDEX} -eq 0 ]; then
196 elif [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 0 ]; then
198 elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 0 ]; then