forked from omniosorg/omnios-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit
executable file
·275 lines (244 loc) · 7.63 KB
/
audit
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/ksh
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
# Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
__SCRIPTDIR="${0%/*}"
cd $__SCRIPTDIR/..
[ ! -d build -o ! -x build/buildctl ] && echo "Cannot find directory" && exit 1
export PATH=/usr/bin:/opt/ooce/bin
IPSROOT=https://pkg.omnios.org
typeset -A targets
typeset -a branches
c_banner="`/usr/gnu/bin/tput setaf 6`"
c_highlight="`/usr/gnu/bin/tput setaf 2`"
c_error="`/usr/gnu/bin/tput setaf 1`"
c_reset="`/usr/gnu/bin/tput sgr0`"
setup()
{
# Determine the current bloody release version as r1510XX.0
bbranch=`pkgrepo -s $IPSROOT/bloody/core list -H -F json SUNWcs \
| jq -r '.[0] | .branch'`
bbranch=${bbranch%%.*}
[ -z "$bbranch" ] && echo "Could not retrieve bloody branch" && exit 1
#echo "Bloody branch: $bbranch"
((lts = bbranch - (bbranch + 2) % 8))
[ $lts -ge $((bbranch - 3)) ] && ((lts = lts - 8))
branches=(bloody r$((bbranch - 1)) r$((bbranch - 3)) r$lts)
#echo "Branches: ${branches[@]}"
}
ord26()
{
typeset asc=`printf '%d' "'$1"`
((asc -= 64))
[ $asc -gt 32 ] && ((asc -= 32))
echo $asc
}
# This is a crude version of the function in funtions.sh that assumes
# omniosorg for the github organisation. It may need extending in the
# future.
github_latest() {
typeset pkg="$1"
typeset ver="$2"
typeset ep=https://api.github.com/repos/omniosorg/${pkg##*/}/releases
typeset filter="map(select (.draft == false)"
if [ "$ver" != github-latest-prerelease ]; then
filter+=" | select (.prerelease == false)"
fi
filter+=") | first | .tag_name"
typeset tag=`curl -s $ep | jq -r "$filter"`
echo "${tag#v}"
}
cf()
{
typeset vv1=(${1//./ })
typeset vv2=(${2//./ })
i=0
while [ $i -lt ${#vv1[@]} ]; do
[ -z "${vv2[$i]}" -o "${vv1[$i]}" -gt "${vv2[$i]}" ] && return 1
[ "${vv1[$i]}" -lt "${vv2[$i]}" ] && return 2
((i++))
done
[ -n "${vv2[$i]}" ] && return 2
return 0
}
add_target()
{
typeset pkg=$1
typeset build=$2
typeset dir="`dirname $build`"
if [[ $build = *.sh ]]; then
ver="`grep ^VER= $build | sed '
1 {
s/VER=//
s/ .*//
q
}'`"
case $pkg:$ver in
ooce/network/openvpn-auth-ldap:*)
ver="`grep '^AUTHLDAPVER=' $build | cut -d= -f2`"
;;
ooce/runtime/expect:*)
ver="`grep '^EXPECTVER=' $build | cut -d= -f2`"
;;
*/ntfs-3g:*)
ver=${ver//AR/}
;;
*/cups:*)
ver=${ver//op/.}
;;
*/munin:*)
pkg+=-server
;;
*/zabbix:*)
pkg+=-server
;;
*/modules/subversion:*)
aver="`grep '^APACHEVER=' $build | cut -d= -f2`"
pkg=ooce/server/apache-${aver//./}/modules/subversion
;;
*/php-XX/*:*)
pver=`grep '^PHPVERSIONS=' $build | cut -d= -f2 \
| cut -d '"' -f2`
for p in $pver; do
targets[${pkg/XX/${p//./}}]=$ver
done
pkg=
;;
*/postgresql-XX/*:*)
pver=`grep '^PGVERSIONS=' $dir/../common.sh | cut -d= -f2 \
| cut -d '"' -f2`
for p in $pver; do
targets[${pkg/XX/${p//./}}]=$ver
done
pkg=
;;
*:github-latest*)
ver=`github_latest $pkg $ver`
;;
esac
if [[ $ver == {4}([0-9])-{2}([0-9])-{2}([0-9])T* ]]; then
## Convert ISO-formatted time
ver=${ver%T*}
ver=${ver//-/.}
elif [[ $ver = *[a-z] ]]; then
## Convert single trailing alpha character
ver="${ver%[a-z]}.`ord26 ${ver#${ver%?}}`"
fi
ver=${ver//-/.}
## Strip leading zeros in version components.
ver=`echo $ver | sed -e 's/\.0*\([1-9]\)/.\1/g;'`
[ -n "$pkg" ] && targets[$pkg]=$ver
elif [[ $build = *.p5m ]]; then
egrep -q 'pkg.obsolete.*true' $build && return
egrep -q 'pkg.renamed.*true' $build && return
# No manifests of interest currently
#echo "P5M:`grep pkg.fmri $build`"
:
else
echo "Unknown target type"
exit 1
fi
}
extract_pkgs()
{
sed -nE '
/##IGNORE##/d
/\<PKG=[^[:space:]]+[[:space:]]*(#.*)?$/ {
s/.*PKG=/PKG=/
s/[[:space:]]+#.+//
s/=/ /g
p
}' $1 | nawk '$1 == "PKG" { print $2 }'
}
add_buildscripts()
{
for build in `find build -name build\*.sh`; do
for PKG in `extract_pkgs $build`; do
add_target $PKG $build
done
done
}
add_targets()
{
#echo "Finding build components..."
add_buildscripts
}
fetch_branches()
{
for b in "${branches[@]}"; do
typeset -A $b
nameref data=$b
#echo "Retrieving package list for $b"
while IFS=" " read pkg ver; do
[ -n "${data[$pkg]}" ] || data[$pkg]="$ver"
done < <( \
pkgrepo -s $IPSROOT/$b/extra list -H -F json \
| jq -r '.[] | [.name, .release] | @tsv'
)
done
}
audit()
{
pkgs=32
vers=12
printf "%-${pkgs}s %${vers}s %${vers}s %${vers}s %${vers}s %${vers}s\n" \
Package Version "${branches[@]}"
printf "%-${pkgs}s %${vers}s %${vers}s %${vers}s %${vers}s %${vers}s\n" \
------- ------- ------ ------- ------- -------
for pkg in "${!targets[@]}"; do
ver="${targets[$pkg]}"
spkg=${pkg#ooce/}
str=`printf "%-${pkgs}s %${vers}s" "${spkg: -$pkgs}" "$ver"`
ok=1
for b in "${branches[@]}"; do
[ $b = bloody ] && r=$bbranch || r=${b#r}
nameref data=$b
pver="${data[$pkg]}"
cf "$ver" "$pver"
case $? in
0) c="$c_highlight" ;;
1) c="$c_error"
case $pkg:$pver in
# clang/llvm-18 are not published until r151049
*/clang-18:|*/llvm-18:|*/zig-013:) [ $r -lt 151049 ] || ok=0 ;;
# clang/llvm-19 are not published until r151051
*/clang-19:|*/llvm-19:) [ $r -lt 151051 ] || ok=0 ;;
# clang/llvm-20 are not published until r151053
*/clang-20:|*/llvm-20:) [ $r -lt 151053 ] || ok=0 ;;
*) ok=0 ;;
esac
;;
2) c="$c_banner"; ok=0 ;;
esac
str+=`printf " %s%${vers}s" "$c" "${pver:---}"`
done
if [ $ok -eq 0 -o $full -eq 1 ] && \
[[ -z "$pattern" || "$pkg" == *${pattern}* ]]; then
echo "$str$c_reset"
fi
done
}
USAGE="[+NAME?audit --- check packages against IPS repositories]"
USAGE+="[f:full?Show all packages, not just problems]"
USAGE+="[p:pkg?Show only packages matching pattern]:[<pattern>]"
full=0
pattern=
while getopts "$USAGE" opt; do
case $opt in
f) full=1 ;;
p) full=1; pattern="$OPTARG" ;;
esac
done
setup
add_targets
fetch_branches
audit
# Vim hints
# vim:ts=4:sw=4:et:fdm=marker