Pull up CVS idents from FreeBSD to match our current version.
[dragonfly.git] / usr.bin / pkg_search / pkg_search.sh
blob1c9415b2bfec1461b6fd4b7b0d68f3f31a7956da
1 #!/bin/sh
3 # Copyright (c) 2007 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.
8 # All rights reserved.
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.5 2008/01/03 16:42:43 matthias Exp $
36 UNAME=`uname -s`
37 VERSION=`uname -r | cut -d '.' -f 1,2`
38 NO_INDEX=0
39 PORTSDIR=/usr/pkgsrc
40 PKGSUM=${PORTSDIR}/pkg_summary
41 PKGSRCBOX1=http://pkgbox.dragonflybsd.org/packages/${UNAME}-${VERSION}/i386/
42 PKGSRCBOX2=http://pkgbox.dragonflybsd.org/packages/DragonFly-1.10.1/i386/
43 INDEXFILE=INDEX
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
48 mkdir -p ${PORTSDIR}
49 fetch -o ${PKGSUM}.bz2 ${FETCHPATH}
50 if [ $? -ne 0 ]; then
51 FETCHPATH=${PKGSRCBOX2}/All/pkg_summary.bz2
52 fetch -o ${PKGSUM}.bz2 ${FETCHPATH}
54 if [ $? -ne 0 ]; then
55 echo "Unable to fetch pkg_summary(5) file."
56 exit 1
58 bunzip2 < ${PKGSUM}.bz2 > ${PKGSUM}
59 rm -f ${PKGSUM}.bz2
60 NO_INDEX=1
62 if [ -e ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then
63 NO_INDEX=1
66 # Perform simple search in pkg_summary
67 bin_simple_search()
69 awk -F= -v name="$1" '{
70 if ($1 == "PKGNAME") {
71 if ($2 ~ name) {
72 printf("%-20s\t", $2);
73 found = 1;
75 else found = 0;
77 if (found == 1 && $1 == "COMMENT") printf("%-25s\n", $2);
78 }' ${PKGSUM}
81 # Perform extended search in pkg_summary
82 bin_ext_search()
84 awk -F= -v name="$1" '{
85 if ($1 == "PKGNAME")
86 if ($2 ~ name) {
87 printf("\nName\t: %-50s\n", $2);
88 found = 1;
90 else found = 0;
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);
98 }' ${PKGSUM}
101 # Perform extended search in INDEX
102 index_v_search()
104 if [ ${KFLAG} -eq 0 ]; then
105 awk -F\| -v name="$1" '{
106 if ($1 ~ name) {
107 split($2, a, "/");
108 printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\
109 "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2,
110 $4, $12, $9);
112 }' ${PORTSDIR}/${INDEXFILE}
113 else
114 awk -F\| -v name="$1" '{
115 if ($1 ~ name || $4 ~ name || $12 ~ name) {
116 split($2, a, "/");
117 printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\
118 "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2,
119 $4, $12, $9);
121 }' ${PORTSDIR}/${INDEXFILE}
125 # Perform simple search in INDEX
126 index_search()
128 if [ ${KFLAG} -eq 0 ]; then
129 awk -F\| -v name="$1" '{
130 if ($1 ~ name) {
131 split($2, a, "/");
132 printf("%-20s\t%-25s\n", $1, $4);
134 }' ${PORTSDIR}/${INDEXFILE}
135 else
136 awk -F\| -v name="$1" '{
137 if ($1 ~ name || $4 ~ name || $12 ~ name) {
138 split($2, a, "/");
139 printf("%-20s\t%-25s\n", $1, $4);
141 }' ${PORTSDIR}/${INDEXFILE}
145 usage()
147 echo "usage: $0 [-k | -v] package"
148 exit 1
151 args=`getopt kv $*`
153 KFLAG=0
154 VFLAG=0
156 set -- $args
157 for i; do
158 case "$i" in
160 KFLAG=1; shift;;
162 VFLAG=1; shift;;
164 shift; break;;
165 esac
166 done
168 if [ -z ${1} ]; then
169 usage
172 if [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 1 ]; then
173 bin_simple_search $1
174 elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 1 ]; then
175 bin_ext_search $1
176 elif [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 0 ]; then
177 index_search $1
178 elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 0 ]; then
179 index_v_search $1
182 exit $?