-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpu
executable file
·171 lines (145 loc) · 3.42 KB
/
pu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/sh
## $Id: pu,v 1.1 2002/12/05 17:04:15 yozo Exp $
LS_COMMAND=ls
PKG_ADD=/usr/sbin/pkg_add
PKG_DELETE=/usr/sbin/pkg_delete
PKG_INFO=/usr/sbin/pkg_info
PKGDIR=/usr/ports/packages/`uname -m`/All
EXTENSION=".tgz"
DEBUG=
VERBOSE=
progname=$0
requiredpackages="" ## set inside get_requiredpackages()
OUTPUT_PREFIX=" "
SHOWPACKAGENAME=
usage(){
echo "usage: ${progname} [-help] [-debug] [-prefix string] [-showpackage] [-verbose] pkgname" 1>&2
}
get_requiredpackages(){
pkgname="$1"
requiredpackages=`${PKG_INFO} -R ${pkgname} | \
sed -e '1,/^Required by:/d' -e '/^$/d'`
}
## NOT USED ##
showpkgtree(){
prefix="${PREFIX}"
pkgname="${PACKAGENAME}"
requiredpkglist="${REQUIREDPACKAGES}"
echo "showpkgtree: prefix=(${prefix})"
echo "showpkgtree: pkgname=${pkgname}"
echo "showpkgtree: rpkglist=${requiredpkglist}"
if [ -z "${requiredpkglist}" ]; then
echo "${prefix}${pkgname}"
else
for i in "${requiredpkglist}" ; do
get_requiredpackages ${i}
showpkgtree "${prefix}o " ${i} "${requiredpackages}"
done
fi
}
#### option analysis ####
while [ $# -gt 0 ]; do
## echo "arg: $1" 1>&2
case "$1" in
-d*)
DEBUG="-d"
shift
;;
-h*)
usage
exit 1
;;
-prefix*)
shift
OUTPUT_PREFIX="$1"
shift
;;
-show*)
SHOWPACKAGENAME="-showpackage"
shift
;;
-verb*)
VERBOSE="-v"
shift
;;
--)
if [ -n "${DEBUG}" ]; then
echo "option ended." 1>&2
fi
shift
break
;;
-*)
echo "unknown option ($1)" 1>&2
usage
exit 2
;;
*)
break
;;
esac
done
if [ ! $# -eq 1 ]; then
echo "argument should be only ONE." 1>&2
usage
exit 3
fi
if [ -n ${OUTPUT_PREFIX} ]; then
OUTPUT_PREFIX="${OUTPUT_PREFIX}"
fi
if [ -n "${DEBUG}" ]; then
echo "DEBUG on." 1>&2
echo "${progname}: argument ($1)." 1>&2
echo "OUTPUT_PREFIX: ${OUTPUT_PREFIX}" 1>&2
if [ -n "$VERBOSE}" ]; then
echo "VERBOSE on." 1>&2
else
echo "VERBOSE off." 1>&2
fi
fi
#### check installed package name and new package file ####
packages=`${PKG_INFO} -e "$1"`
if [ ! $? -eq 0 ]; then
echo "${progname}: $1 NOT found."
exit 10
fi
if [ -n "${DEBUG}" ]; then
echo "packages: ${packages}" 1>&2
fi
num=`echo "${packages}" | wc -l`
if [ ! ${num} -eq 1 ]; then
echo "${progname}: too many packages found." 1>&2
echo "${packages}" 1>&2
exit 20
fi
packagename=${packages}
if [ -n "${DEBUG}" ]; then
echo "${progname}: installed package ${packagename}" 1>&2
fi
if [ ! -f ${PKGDIR}/${packagename}${EXTENSION} ]; then
echo "${progname}: new package file NOT found." 1>&2
exit 30
fi
if [ -n "${DEBUG}" ]; then
echo -n "${progname}: new package file: "
ls ${PKGDIR}/${packagename}${EXTENSION}
fi
#### now check how many packages require this package ####
get_requiredpackages ${packagename}
if [ -z "${requiredpackages}" ]; then
if [ -n "${VERBOSE}" ]; then
echo "${progname}: NO packages depend on ${packagename}."
fi
else
if [ -n "${SHOWPACKAGENAME}" ]; then
echo "${OUTPUT_PREFIX}${packagename}:"
fi
for i in ${requiredpackages} ; do
echo "${OUTPUT_PREFIX} <-- ${i}"
${progname} ${DEBUG} -prefix "${OUTPUT_PREFIX}${OUTPUT_PREFIX} " ${i}
done
## ## should be merged to one loop (to be depth-first).
## for i in ${requiredpackages} ; do
## ${progname} ${DEBUG} -prefix "${OUTPUT_PREFIX}${OUTPUT_PREFIX} " ${i}
## done
fi