| Commit | Line | Data |
|---|---|---|
| 674a427d MD |
1 | #!/bin/sh |
| 2 | # | |
| b0ec74b2 | 3 | # Copyright (c) 2007-09 The DragonFly Project. All rights reserved. |
| 9765f86e MS |
4 | # |
| 5 | # This code is derived from software contributed to The DragonFly Project | |
| a016e194 | 6 | # by Matthias Schmidt <matthias@dragonflybsd.org>, University of Marburg. |
| 674a427d MD |
7 | # |
| 8 | # All rights reserved. | |
| 9 | # | |
| 4faa2bb3 | 10 | # Redistribution and use in source and binary forms, with or without |
| 674a427d MD |
11 | # modification, are permitted provided that the following conditions are met: |
| 12 | # | |
| 4faa2bb3 | 13 | # - Redistributions of source code must retain the above copyright notice, |
| 674a427d | 14 | # this list of conditions and the following disclaimer. |
| 4faa2bb3 MS |
15 | # - Redistributions in binary form must reproduce the above copyright notice, |
| 16 | # this list of conditions and the following disclaimer in the documentation | |
| 674a427d | 17 | # and/or other materials provided with the distribution. |
| 9765f86e MS |
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. | |
| 674a427d MD |
21 | # |
| 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. | |
| 33 | # | |
| 83cc1f74 | 34 | # $DragonFly: src/usr.bin/pkg_search/pkg_search.sh,v 1.11 2008/09/04 10:33:50 matthias Exp $ |
| 674a427d | 35 | |
| 13a8f106 | 36 | UNAME=`uname -s` |
| 0bc904b6 | 37 | VERSION=`uname -r | awk -F - '{ print $1; }'` |
| 3d62c9e3 | 38 | CPU=`uname -p | awk -F - '{ print $1; }'` |
| a016e194 MS |
39 | NO_INDEX=0 |
| 40 | PORTSDIR=/usr/pkgsrc | |
| 41 | PKGSUM=${PORTSDIR}/pkg_summary | |
| 0bc904b6 | 42 | if [ -z "$BINPKG_SITES" ]; then |
| 3d62c9e3 | 43 | BINPKG_SITES=http://avalon.dragonflybsd.org/packages/${CPU}/${UNAME}-${VERSION}/stable/ |
| 0bc904b6 MS |
44 | [ -f /etc/settings.conf ] && . /etc/settings.conf |
| 45 | fi | |
| 46 | PKGSRCBOX1=$BINPKG_SITES | |
| 3d62c9e3 | 47 | PKGSRCBOX2=http://avalon.dragonflybsd.org/packages/i386/DragonFly-2.2.0/stable/ |
| a016e194 | 48 | INDEXFILE=INDEX |
| 13a8f106 | 49 | |
| b0ec74b2 MS |
50 | # Download the pkg_summary file |
| 51 | download_summary() | |
| 52 | { | |
| 53 | echo "Fetching pkg_summary(5) file." | |
| a016e194 | 54 | FETCHPATH=${PKGSRCBOX1}/All/pkg_summary.bz2 |
| a016e194 MS |
55 | fetch -o ${PKGSUM}.bz2 ${FETCHPATH} |
| 56 | if [ $? -ne 0 ]; then | |
| 57 | FETCHPATH=${PKGSRCBOX2}/All/pkg_summary.bz2 | |
| 13a8f106 | 58 | fetch -o ${PKGSUM}.bz2 ${FETCHPATH} |
| 13a8f106 | 59 | fi |
| a016e194 MS |
60 | if [ $? -ne 0 ]; then |
| 61 | echo "Unable to fetch pkg_summary(5) file." | |
| 62 | exit 1 | |
| 13a8f106 | 63 | fi |
| a016e194 MS |
64 | bunzip2 < ${PKGSUM}.bz2 > ${PKGSUM} |
| 65 | rm -f ${PKGSUM}.bz2 | |
| b0ec74b2 | 66 | } |
| a016e194 MS |
67 | |
| 68 | # Perform simple search in pkg_summary | |
| 69 | bin_simple_search() | |
| 70 | { | |
| 71 | awk -F= -v name="$1" '{ | |
| 72 | if ($1 == "PKGNAME") { | |
| a5da7f43 | 73 | if (tolower($2) ~ name) { |
| a016e194 MS |
74 | printf("%-20s\t", $2); |
| 75 | found = 1; | |
| 76 | } | |
| 77 | else found = 0; | |
| 78 | } | |
| 79 | if (found == 1 && $1 == "COMMENT") printf("%-25s\n", $2); | |
| 80 | }' ${PKGSUM} | |
| 81 | } | |
| 82 | ||
| 83 | # Perform extended search in pkg_summary | |
| 84 | bin_ext_search() | |
| 85 | { | |
| 86 | awk -F= -v name="$1" '{ | |
| 87 | if ($1 == "PKGNAME") | |
| a5da7f43 | 88 | if (tolower($2) ~ name) { |
| a016e194 MS |
89 | printf("\nName\t: %-50s\n", $2); |
| 90 | found = 1; | |
| 91 | } | |
| 92 | else found = 0; | |
| 4faa2bb3 | 93 | |
| a016e194 MS |
94 | if (found == 1 && $1 == "COMMENT") |
| 95 | printf("Desc\t: %-50s\n", $2); | |
| 96 | if (found == 1 && $1 == "PKGPATH") | |
| 97 | printf("Path\t: %-50s\n", $2); | |
| 98 | if (found == 1 && $1 == "HOMEPAGE") | |
| 99 | printf("URL\t: %-50s\n", $2); | |
| 100 | }' ${PKGSUM} | |
| 101 | } | |
| 102 | ||
| 103 | # Perform extended search in INDEX | |
| 104 | index_v_search() | |
| 105 | { | |
| 106 | if [ ${KFLAG} -eq 0 ]; then | |
| 107 | awk -F\| -v name="$1" '{ | |
| a5da7f43 | 108 | if (tolower($1) ~ name) { |
| a016e194 | 109 | printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\ |
| 4faa2bb3 | 110 | "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2, |
| a016e194 MS |
111 | $4, $12, $9); |
| 112 | } | |
| 113 | }' ${PORTSDIR}/${INDEXFILE} | |
| 114 | else | |
| 115 | awk -F\| -v name="$1" '{ | |
| a5da7f43 MS |
116 | if (tolower($1) ~ name || tolower($4) ~ name || |
| 117 | tolower($12) ~ name) { | |
| a016e194 | 118 | printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s"\ |
| 4faa2bb3 | 119 | "\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2, |
| a016e194 MS |
120 | $4, $12, $9); |
| 121 | } | |
| 122 | }' ${PORTSDIR}/${INDEXFILE} | |
| 123 | fi | |
| 124 | } | |
| 125 | ||
| 126 | # Perform simple search in INDEX | |
| 127 | index_search() | |
| 128 | { | |
| 129 | if [ ${KFLAG} -eq 0 ]; then | |
| 130 | awk -F\| -v name="$1" '{ | |
| a5da7f43 | 131 | if (tolower($1) ~ name) { |
| a016e194 MS |
132 | printf("%-20s\t%-25s\n", $1, $4); |
| 133 | } | |
| 134 | }' ${PORTSDIR}/${INDEXFILE} | |
| 135 | else | |
| 136 | awk -F\| -v name="$1" '{ | |
| a5da7f43 MS |
137 | if (tolower($1) ~ name || tolower($4) ~ name || |
| 138 | tolower($12) ~ name) { | |
| a016e194 MS |
139 | printf("%-20s\t%-25s\n", $1, $4); |
| 140 | } | |
| 141 | }' ${PORTSDIR}/${INDEXFILE} | |
| 142 | fi | |
| 143 | } | |
| 674a427d | 144 | |
| 4faa2bb3 MS |
145 | show_description() |
| 146 | { | |
| 147 | PDESC=`awk -F\| -v name="$1" '{ | |
| 148 | if (tolower($1) == name) { | |
| 149 | split($2, ppath, "/"); | |
| 150 | printf("%s\n", $5); | |
| 151 | } | |
| 152 | }' ${PORTSDIR}/${INDEXFILE}` | |
| 153 | if [ -f "${PORTSDIR}/${PDESC}" ]; then | |
| 154 | cat "${PORTSDIR}/${PDESC}" | |
| 155 | else | |
| 156 | echo "Unable to locate package $1. Please provide the exact" | |
| 157 | echo "package name as given by pkg_search(1). You need the" | |
| 158 | echo "complete pkgsrc(7) tree to perform this operation." | |
| 159 | fi | |
| 160 | } | |
| 161 | ||
| a016e194 MS |
162 | usage() |
| 163 | { | |
| 83cc1f74 MS |
164 | echo "usage: `basename $0` [-kv] package" |
| 165 | echo " `basename $0` -s package" | |
| b0ec74b2 | 166 | echo " `basename $0` -d" |
| 4faa2bb3 | 167 | exit 1 |
| a016e194 | 168 | } |
| 674a427d | 169 | |
| b0ec74b2 MS |
170 | if [ ! -f ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then |
| 171 | echo "No pkgsrc(7) tree found." | |
| 172 | mkdir -p ${PORTSDIR} | |
| 173 | download_summary | |
| 174 | NO_INDEX=1 | |
| 175 | fi | |
| 176 | if [ -e ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then | |
| 177 | NO_INDEX=1 | |
| 178 | fi | |
| 179 | ||
| 180 | args=`getopt dksv $*` | |
| 674a427d | 181 | |
| 4faa2bb3 | 182 | SFLAG=0 |
| a016e194 MS |
183 | KFLAG=0 |
| 184 | VFLAG=0 | |
| b0ec74b2 | 185 | DFLAG=0 |
| 7896f28d | 186 | |
| a016e194 MS |
187 | set -- $args |
| 188 | for i; do | |
| 189 | case "$i" in | |
| b0ec74b2 MS |
190 | -d) |
| 191 | DFLAG=1; shift;; | |
| a016e194 MS |
192 | -k) |
| 193 | KFLAG=1; shift;; | |
| 4faa2bb3 MS |
194 | -s) |
| 195 | SFLAG=1; shift;; | |
| 7896f28d | 196 | -v) |
| a016e194 MS |
197 | VFLAG=1; shift;; |
| 198 | --) | |
| 199 | shift; break;; | |
| 200 | esac | |
| 201 | done | |
| 13a8f106 | 202 | |
| b0ec74b2 | 203 | if [ ${DFLAG} -eq 0 -a -z ${1} ]; then |
| a016e194 MS |
204 | usage |
| 205 | fi | |
| 206 | ||
| b0ec74b2 MS |
207 | if [ ${DFLAG} -eq 1 ]; then |
| 208 | download_summary | |
| 209 | exit $? | |
| 210 | fi | |
| 211 | ||
| a016e194 MS |
212 | if [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 1 ]; then |
| 213 | bin_simple_search $1 | |
| 214 | elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 1 ]; then | |
| 215 | bin_ext_search $1 | |
| 4faa2bb3 MS |
216 | elif [ ${SFLAG} -eq 1 -a ${NO_INDEX} -eq 0 ]; then |
| 217 | show_description $1 | |
| a016e194 MS |
218 | elif [ ${VFLAG} -eq 0 -a ${NO_INDEX} -eq 0 ]; then |
| 219 | index_search $1 | |
| 220 | elif [ ${VFLAG} -eq 1 -a ${NO_INDEX} -eq 0 ]; then | |
| 221 | index_v_search $1 | |
| 222 | fi | |
| 674a427d MD |
223 | |
| 224 | exit $? |