Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / usr.bin / pkg_search / pkg_search.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Matthias Schmidt <schmidtm @ mathematik . uni-marburg.de>
4 #
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without 
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # - Redistributions of source code must retain the above copyright notice, 
11 #   this list of conditions and the following disclaimer.
12 # - Redistributions in binary form must reproduce the above copyright notice, 
13 #   this list of conditions and the following disclaimer in the documentation 
14 #   and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 # $DragonFly: src/usr.bin/pkg_search/pkg_search.sh,v 1.1 2007/12/04 18:24:18 dillon Exp $
29
30 if [ `uname -s` = "FreeBSD" ]; then
31         PORTSDIR=/usr/ports
32         id=`uname -r | cut -d '.' -f 1`
33         INDEXFILE=INDEX-$id
34 elif [ `uname -s` = "DragonFly" ] || [ `uname -s` = "NetBSD" ]; then
35         PORTSDIR=/usr/pkgsrc
36         INDEXFILE=INDEX
37 fi
38
39 if [ -z $1 ]; then 
40         echo "Usage: $0 [ -i | -k ] <name>"
41         exit 1  
42 fi
43
44 if [ ! -d $PORTSDIR ]; then 
45         echo "No Ports Tree Found!  Please install."
46         exit 1  
47 fi
48
49 case "$1" in
50         -i)
51                 awk -F\| -v name="$2" \
52             '{\
53                     if ($1 ~ name) { \
54                             split($2, a, "/"); \
55                             printf("Name\t: %s-50\nDir\t: %-50s\nDesc\t: %-50s\nURL\t: %-50s\nDeps\t: %s\n\n", $1, $2, $4, $10, $9); \
56                     }
57             }' ${PORTSDIR}/${INDEXFILE}
58         ;;
59         -k)
60                 awk -F\| -v name="$2" \
61             '{\
62                     if ($1 ~ name || $4 ~ name || $10 ~ name) { \
63                             split($2, a, "/"); \
64                             printf("%-20s\t%-25s\n", $1, $4); \
65                     }
66             }' ${PORTSDIR}/${INDEXFILE}
67
68         ;;
69         *)
70                 awk -F\| -v name="$1" \
71             '{\
72                     if ($1 ~ name) { \
73                             split($2, a, "/"); \
74                             printf("%-20s\t%-25s\n", $1, $4); \
75                     }
76             }' ${PORTSDIR}/${INDEXFILE}
77         ;;
78 esac
79
80 exit $?