o Change my personal copyright to the DragonFly copyright
[dragonfly.git] / usr.bin / pkg_search / pkg_search.sh
blobe9d30e5a566cc1da86ad0a85cc76de9dc60ddd37
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 <schmidtm@mathematik.uni-marburg.de>, University of
7 # Marburg.
9 # All rights reserved.
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions are met:
14 # - Redistributions of source code must retain the above copyright notice,
15 # this list of conditions and the following disclaimer.
16 # - Redistributions in binary form must reproduce the above copyright notice,
17 # this list of conditions and the following disclaimer in the documentation
18 # and/or other materials provided with the distribution.
19 # - Neither the name of The DragonFly Project nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific, prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 # $DragonFly: src/usr.bin/pkg_search/pkg_search.sh,v 1.4 2007/12/27 11:52:10 matthias Exp $
37 UNAME=`uname -s`
38 VERSION=`uname -r | cut -d '.' -f 1,2`
39 SIMPLE=0
41 if [ $UNAME = "DragonFly" ]; then
42 PORTSDIR=/usr/pkgsrc
43 PKGSUM=${PORTSDIR}/pkg_summary
44 PKGSRCBOX1=http://pkgbox.dragonflybsd.org/packages/${UNAME}-${VERSION}/i386/
45 PKGSRCBOX2=http://pkgbox.dragonflybsd.org/packages/DragonFly-1.10.1/i386/
46 INDEXFILE=INDEX
47 if [ ! -f ${PKGSUM} ]; then
48 echo "No pkgsrc(7) tree found. Fetching pkg_summary(5) file."
49 FETCHPATH=${PKGSRCBOX1}/All/pkg_summary.bz2
50 mkdir -p ${PORTSDIR}
51 fetch -o ${PKGSUM}.bz2 ${FETCHPATH}
52 if [ $? -ne 0 ]; then
53 FETCHPATH=${PKGSRCBOX2}/All/pkg_summary.bz2
54 fetch -o ${PKGSUM}.bz2 ${FETCHPATH}
56 if [ $? -ne 0 ]; then
57 echo "Unable to fetch pkg_summary"
58 exit 1
60 bunzip2 < ${PKGSUM}.bz2 > ${PKGSUM}
61 rm -f ${PKGSUM}.bz2
62 SIMPLE=1
64 if [ -e ${PKGSUM} -a ! -e ${PORTSDIR}/${INDEXFILE} ]; then
65 SIMPLE=1
69 if [ -z $1 ]; then
70 echo "usage: $0 [-k | -v] package"
71 exit 1
75 case "$1" in
76 -k)
77 if [ ${SIMPLE} -eq 1 ]; then
78 grep "PKGNAME=$2" ${PKGSUM} | cut -d '=' -f 2
79 exit 1
81 awk -F\| -v name="$2" \
82 '{\
83 if ($1 ~ name || $4 ~ name || $10 ~ name) { \
84 split($2, a, "/"); \
85 printf("%-20s\t%-25s\n", $1, $4); \
87 }' ${PORTSDIR}/${INDEXFILE}
90 -v)
91 if [ ${SIMPLE} -eq 1 ]; then
92 grep "PKGNAME=$2" ${PKGSUM} | cut -d '=' -f 2
93 exit 1
95 awk -F\| -v name="$2" \
96 '{\
97 if ($1 ~ name) { \
98 split($2, a, "/"); \
99 printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2, $4, $10, $9); \
101 }' ${PORTSDIR}/${INDEXFILE}
104 if [ ${SIMPLE} -eq 1 ]; then
105 grep "PKGNAME=$1" ${PKGSUM} | cut -d '=' -f 2
106 exit 1
109 awk -F\| -v name="$1" \
111 if ($1 ~ name) { \
112 split($2, a, "/"); \
113 printf("%-20s\t%-25s\n", $1, $4); \
115 }' ${PORTSDIR}/${INDEXFILE}
117 esac
119 exit $?