-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathypkg
executable file
·205 lines (183 loc) · 5.48 KB
/
ypkg
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/sh
## $Id: ypkg,v 1.13 2014/12/14 06:31:45 yozo Exp $
##
PKGDBPATH=/var/db/pkg
PORTSDIR=/usr/ports
VERBOSE="off"
usage(){
echo "usage:"
echo " $0 [-top]"
echo " lists all packages on which no package depends; the default action."
echo " $0 pkgname"
echo " show dependence tree with pkgname as the root."
echo " $0 [-verbose] -check"
echo " lists all packages for which updates are available in ports tree"
}
toplevel(){
for i in ${PKGDBPATH}/* ${PKGDBPATH}/.libs* ; do
if [ -d ${i} -a ! -f ${i}/+REQUIRED_BY ]; then
basename ${i}
fi
done
}
expand_tabs(){
if [ $1 -ge 1 ]; then
echo -n " ";
expand_tabs `expr $1 - 1`
fi
}
## expand_tabs(){
## count=$1
## while [ ${count} -ge 1 ]; do
## echo -n " ";
## count=`expr ${count} - 1`
## done
## }
show_dependents(){ ## arg1: recursion depth, arg2: pkgname, arg3: parent pkgname (when arg1 > 0)
pkgname=`cd "${PKGDBPATH}" && ( ([ -d "$2" ] && echo "$2" ) || (ls -a | grep "$2") )`
pkgnamematched=`echo ${pkgname} | wc -w`
if [ $pkgnamematched -ge 2 ]; then
echo "ERROR! ambiguous package name"
echo "$pkgname"
exit 10
fi
expand_tabs "$1"
if [ -f "${PKGDBPATH}/${pkgname}/+REQUIRED_BY" ]; then
if [ "$1" -eq 0 ]; then
echo -n "*"
elif [ -n "`grep -v "$3" "${PKGDBPATH}/${pkgname}/+REQUIRED_BY"`" ]; then
echo -n "*"
fi
fi
echo "[$1] ${pkgname}"
requiring="${PKGDBPATH}/${pkgname}/+REQUIRING"
if [ -f ${requiring} ]; then
depends=`cat ${requiring}`
depth=`expr 1 + $1`
for i in ${depends}; do
show_dependents `expr 1 + $1` "$i" "${pkgname}"
done
fi
}
## show_dependents_child(){ ## arg1: recursion depth, arg2: pkgname, arg3: parent pkgname
## pkgname=`cd ${PKGDBPATH} && ls | grep $2`
## pkgnamematched=`echo ${pkgname} | wc -w`
## if [ $pkgnamematched -ge 2 ]; then
## echo "ERROR! ambiguous package name"
## echo "$pkgname"
## exit 20
## fi
## expand_tabs "$1"
## if [ -f "${PKGDBPATH}/${pkgname}/+REQUIRED_BY" ]; then
## if [ -n "`grep -v "$3" "${PKGDBPATH}/${pkgname}/+REQUIRED_BY"`" ]; then
## echo -n "*"
## fi
## fi
## echo "[$1] ${pkgname}"
## requiring="${PKGDBPATH}/${pkgname}/+REQUIRING"
## if [ -f ${requiring} ]; then
## depends=`cat ${requiring}`
## depth=`expr 1 + $1`
## for i in ${depends}; do
## ## show_dependents "${depth}" "$i"
## show_dependents_child `expr 1 + $1` "$i" "${pkgname}"
## done
## fi
## }
check(){
cd "${PKGDBPATH}"
for i in * ; do
fullpkgname=
pkgpathfull=
len_pkgpathfull=
pkgpath=
subpack=
flav=
ismystuff=
## echo -n "CHECK: ${i} : "
pkgpathfull=`sed -n '/comment pkgpath=/s/^.* pkgpath=\([^, ][^ ]*\) .*$/\1/p' "${i}"/+CONTENTS`
len_pkgpathfull=`echo "${pkgpathfull}" | wc -l`
if [ "${len_pkgpathfull}" -lt 1 -o 1 -gt "${len_pkgpathfull}" ]; then exit 10; fi
pkgpath=`echo "${pkgpathfull}" | sed -n 's/^\([^,][^,]*\).*$/\1/p'`
packflav=`echo "${pkgpathfull}" | sed -n 's/^[^,][^,]*\(,.*\)$/\1/p'`
## ${packflav} is a comma-separated list of words, where
## the first word may be a subpackage name with prepending "-", remaining are a list of flavor names
if [ -n "${packflav}" ]; then
case "${packflav}" in
,-*)
subpack=`echo "${packflav}" | sed -n 's/,-\([^,][^,]*\).*/\1/p'`
flav=`echo "${packflav}" | sed -n 's/,-[^,][^,]*\(.*\)/\1/p' | sed 's/,/ /g' | sed 's/^ //'`
## echo "CHECK: subpack($subpack) and flav($flav)"
;;
*)
flav=`echo "${packflav}" | sed 's/,/ /g' | sed 's/^ //'`
## echo "CHECK: flav only ($flav)"
;;
esac
fi
if [ x"${VERBOSE}" == x"on" ]; then
echo -n "=== ${pkgpathfull} === ${pkgpath} === ${packflav} === ${subpack} === ${flav} ==="
fi
if [ -d "${PORTSDIR}/mystuff/${pkgpath}" -a -f "${PORTSDIR}/mystuff/${pkgpath}/Makefile" ]; then
pkgpath="${PORTSDIR}/mystuff/${pkgpath}"
ismystuff="*"
elif [ -d "${PORTSDIR}/${pkgpath}" ]; then
pkgpath="${PORTSDIR}/${pkgpath}"
else
fullpkgname="NOPKGPATH"
fi
if [ "NOPKGPATH" = "${fullpkgname}" ]; then
echo "${i} : NO PKGPATH EXISTS..."
else
if [ -n "${flav}" ]; then
if [ -n "${subpack}" ]; then
fullpkgname=`cd "${pkgpath}" && env FLAVOR="${flav}" make show="FULLPKGNAME-${subpack}"`
else
fullpkgname=`cd "${pkgpath}" && env FLAVOR="${flav}" make show=FULLPKGNAME`
fi
else
if [ -n "${subpack}" ]; then
fullpkgname=`cd "${pkgpath}" && make show="FULLPKGNAME-${subpack}"`
else
fullpkgname=`cd "${pkgpath}" && make show=FULLPKGNAME`
fi
fi
if [ x"${VERBOSE}" == x"on" ]; then
echo " ${fullpkgname} ==="
fi
if [ "${i}" != "${fullpkgname}" ]; then
echo "${i} : update available as ${fullpkgname} ${ismystuff}"
fi
fi
done
}
## main routine starts here
while [ $# -ge 0 ]; do
if [ $# -eq 0 ]; then
toplevel
exit 0
fi
case "$1" in
-h*)
usage
exit 0
;;
-top)
toplevel
exit 0
;;
-check)
check
exit 0
;;
-v*)
VERBOSE="on"
echo "CHECK: VERBOSE on"
shift
;;
*)
show_dependents 0 "$1"
exit 0
;;
esac
done