-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist-package
executable file
·348 lines (335 loc) · 9.38 KB
/
list-package
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/bin/bash
# shellcheck disable=SC2010,SC2155,SC2207,SC2012
export LC_ALL=C
export GREP_COLORS="mt=01;32"
set -eu +f
rroot=/ALT
skip="5.1|c[678].*|fm]1|c9m[12]|c9f1|p[567]|.*armh"
[ "$TERM" = screen ] && export COLORTERM=true
export GUM_SPIN_SHOW_OUTPUT=yes GUM_SPIN_SPINNER=minidot
# Package cache. Try to be mediocrely safe with deletion.
tmp=${TMPDIR:-/tmp}/.list-package
mkdir -p "$tmp"
find "$tmp" -maxdepth 3 -fstype tmpfs -name '*.rpm*' -ctime +1 -delete
branch=Sisyphus arch=x86_64
branches='' arches='' packages=''
all_arch='' lsopts='-ltrd' rpmpeek='' lesser='' logs='' dts=''
pattern='' query='' show_pkg='' srpms='' bat=''
SELECTOR="gum choose --height=$((LINES-5))"
unset show_task aptcache spec logdiff offset
for i; do
shift
[ "$i" = s ] && i=Sisyphus
[ "$i" = sisyphus ] && i=Sisyphus
if [ -d "/ALT/$i" ]; then
branch=$i
branches+=" $i"
continue
fi
if [ -d "/ALT/$branch/files/$i" ]; then
arch=$i
arches+=" $i"
continue
fi
case "$i" in
--src|--srpm*) srpms=y ;;
--spec) spec=y; srpms=only ;;
-a|--all-arch*) all_arch=y ;;
--full-time) lsopts+=" $i" ;;
-1|--names) lsopts= ;;
--peek|--rpmpeek) rpmpeek=y; lsopts=; break ;;
--less) lesser=y; lsopts= ;;
-[0-9]) offset=$i ;;
--logdiff) logdiff=log; logtool=logdiff; break ;;
--logdiff2) logdiff=log; logtool=logdiff2; break ;;
--log*) logs=y ;;
--dts | --ver*) dts=y ;;
--task) show_task=--brief ;;
--task-full) show_task= ;;
-p | --pkg | --packages) show_pkg=y ;;
--ls) query=-l ;;
--fzf) SELECTOR='fzf --no-sort --tac --height=~100%' ;;
--bat) bat=y ;;
--changelog | --configfiles | --conflicts | --docfiles | --dump | --enhances \
| --filesbypkg | --info | --last | --obsoletes | --provides \
| --recommends | --requires | --suggests | --supplements | --scripts \
| --state | --triggers | --triggerscripts | --lastchange | --list \
| --qf=* | --queryformat=*)
query=$i ;;
-L ) query=--lastchange ;;
--disttag) query='--qf=%{DISTTAG}' ;;
--ls=* | --list=*) query=-l; pattern=${i#*=} ;;
--whatdepends | --depends | --showpkg | --showsrc | --show | --policy | --pkgnames)
aptcache=${i#--} ;;
--grep=*)
# --grep= also provides 'no match' message.
pattern=${i#*=} ;;
-*) echo "No option $i"; exit 1 ;;
*) packages+=" $i" ;;
esac
done
[ -z "${branches-}" ] && branches=$(cd $rroot; ls | grep -E -vwe "$skip" | sort -fu)
: "${flavours:=*}"
[ -z "$arches" ] && arches="$arch noarch"
gear_describe()
{
local tag='' descr=$(gear --describe 2>&1)
if [ "$descr" = "gear: specsubst directive requires a tag" ]; then
tag=$(git describe --abbrev=0 --tags --exclude '*debug*')
elif [ "$descr" = "gear: No specfiles found" ]; then
tag=$(git tag -l --sort=creatordate '*-alt*' | tail -1)
fi
[ -n "$tag" ] && descr=$(gear --describe -t "$tag")
if [[ "$descr" =~ gear: ]]; then
echo "Error: $descr"
exit 1
fi
# shellcheck disable=SC2086
set -- $descr
NAME=$1
VERSION=$2
RELEASE=$3
export NAME VERSION RELEASE
}
packages=${packages# }
if [ -z "$packages" ]; then
gear_describe
packages=$NAME
fi
# List package in all branches.
set -f
list=()
for package in $packages; do
for b in $branches; do
if [ -n "$all_arch" ]; then
arches=$(ls "$rroot/$b/files/" | grep -v -e - -e SRPMS -e list)
fi
if [ -n "$srpms" ]; then
r=$rroot/$b/files/SRPMS
pat="$r/$package-[0-9]*-alt*.src.rpm"
set +f
for i in $pat; do
test -e "$i" || continue
list+=("$i")
done
set -f
[ "$srpms" != only ] || continue
fi
for a in $arches; do
r=$rroot/$b/files/$a/RPMS
test -d "$r" || continue
pat="$r/$package-[0-9]*-alt*.$a.rpm"
set +f
for i in $pat; do
test -e "$i" || continue
list+=("$i")
done
set -f
done
done
done
[ ${#list[@]} -gt 0 ] || { echo "No match for '$packages'"; exit 1; }
grab_dts() {
DISTTAG=$(rpm -qp "$RPM" --qf '%{DISTTAG}')
if [ "$DISTTAG" == '(none)' ]; then
BUILDHOST=$(rpm -qp "$RPM" --qf '%{BUILDHOST}')
REPO=${BUILDHOST##*-}
REPO=${REPO%.hasher.altlinux.org}
else
IFS=+. read -r REPO TASK SUBTASK _ <<< "$DISTTAG"
fi
if [[ "$RPM" =~ \.src\.rpm$ ]]; then
pkgname=$(rpm -qp "$RPM" --qf '%{N}')
else
SOURCERPM=$(rpm -qp "$RPM" --qf '%{SOURCERPM}')
pkgname=${SOURCERPM%-*-*.*.rpm}
fi
DTS_FILE="/ALT/repo/$REPO/index/src/${pkgname:0:1}/$pkgname/d-t-s-evr.list"
DTS_LIST=$(awk 'OFS="\t" {$1=strftime("%Y-%m-%d",$1); print $0}' "$DTS_FILE" | column -t)
DTS=$DTS_LIST
}
# Download RPM form URL into cache.
cache_rpm() {
local rpm=$1
local tmpd=$tmp/$TASK/$SUBTASK
mkdir -p "$tmpd"
RPM="$tmpd/$rpm" # output
if [ ! -e "$RPM" ]; then
URL+=$rpm
echo >&2 "$URL"
gum spin -- curl -sSf "$URL" -o "$RPM-"
mv "$RPM-" "$RPM"
fi
# Also changes ctime, to make file fesh for the cache.
touch -a "$RPM"
}
# Select one from 'list' (from all branches) and from dts list.
select_one() {
if [ ${#list[@]} -eq 0 ]; then
echo >&2 "No match!"
exit 1
elif [ ${#list[@]} -eq 1 ]; then
# No choice.
# shellcheck disable=SC2128
RPM=$list
elif [ -n "$all_arch" ] && [ -n "$show_pkg" ] && [ -z "$dts" ]; then
# Corner case: we need just some rpm for meta-info.
# shellcheck disable=SC2128
RPM=$list
else
local default=$(ls -1 "${list[@]}" | grep -i -m1 '/sisyphus/')
RPM=$(gum choose --header='Select one:' --cursor='-> ' --selected="$default" "${list[@]}")
fi
if [ -n "$dts" ]; then
grab_dts
export GUM_CHOOSE_SELECTED=$(printf %s "$DTS" | grep -w "${TASK-}")
DTS=$(printf %s "$DTS" | $SELECTOR)
read -r _ TASK SUBTASK _ <<< "$DTS"
[ "${1-}" = --task ] && return
# Download requested RPM into cache.
URL=https://git.altlinux.org/tasks/archive/done/_$((TASK/1024))/$TASK/build/$SUBTASK/$arch/rpms/
echo >&2 "+ $URL"
st_rpms=$(gum spin -- curl -sSf "$URL" | sed -En 's/<[^>]*>//gp' | grep -E '^[[:space:]][^[:space:]/]+.rpm\b')
if [ "${1-}" = --rpms ]; then
printf '%s\n' "$st_rpms" | column -t
return
fi
if [ "$(printf %s "$st_rpms" | grep -c .)" -gt 1 ]; then
choice=$(printf %s "$st_rpms" | $SELECTOR)
else
choice=$st_rpms
fi
choice=$(printf %s "$choice" | awk '{print$1}')
cache_rpm "$choice"
else
DISTTAG=$(rpm -qp "$RPM" --qf '%{DISTTAG}')
if [ "$DISTTAG" == '(none)' ]; then
BUILDHOST=$(rpm -qp "$RPM" --qf '%{BUILDHOST}')
REPO=${BUILDHOST##*-}
REPO=${REPO%.hasher.altlinux.org}
else
IFS=+. read -r REPO TASK SUBTASK _ <<< "$DISTTAG"
fi
fi
}
if [ -n "$rpmpeek" ]; then
select_one
if [ -n "$DISTTAG" ]; then
rpm=${RPM#"$tmp/"}
[ "$rpm" != "$RPM" ] && rpm=$DISTTAG@$(basename "$RPM")
fi
(set -x; rpmpeek -n "$RPM" "$@")
exit
elif [ -n "$lesser" ]; then
select_one
echo >&2 "+ less $RPM"
echo
less "$RPM"
exit
elif [ -n "$bat" ]; then
select_one
f=$(rpm -qvlp -- "$RPM" | fzf +s --tac)
f=${f##* }
rpmpeek "$RPM" bat "${f#/}"
exit
elif [ -n "$logs" ]; then
select_one --task
{
url="https://git.altlinux.org/tasks/$TASK/build/$SUBTASK/$arch/log"
echo >&2 "+ curl $url"
echo
curl -sSf -L "$url"
} |& less
exit
elif [ -v logdiff ]; then
select_one --task
baseurl="https://git.altlinux.org/tasks/$TASK/build/$SUBTASK/$arch"
curl -sSf -L "$baseurl/srpm.log" > "$tmp/log-remote"
curl -sSf -L "$baseurl/log" >> "$tmp/log-remote"
[[ $SELECTOR = *fzf* ]] && offset=
log_local="$tmp/log-local${offset-}"
log ${offset--1} > "$log_local"
for i; do
sed -Ei "$i" "$tmp/log-remote" "$log_local"
done
$logtool "$tmp/log-remote" "$log_local" | delta
exit
elif [ -v show_task ]; then
select_one --task
(set -x; ssh girar task show $show_task "$TASK")
exit
elif [ -n "$show_pkg" ]; then
select_one --rpms
if [ -z "$dts" ]; then
SOURCERPM=$(rpm -qp "$RPM" --qf '%{SOURCERPM}')
srcname=${SOURCERPM%-*-*.src.rpm}
root=$rroot/$REPO/files
SRC_LIST=$root/list/src.list
list=( $(awk -v "R=$root/" "\$1~/^$srcname\$/ {print R\"SRPMS/\"\$3}" "$SRC_LIST") )
BIN_LIST=$root/list/bin.list
[ -z "$all_arch" ] && archpat="(${arches//[[:space:]]/|})" || archpat=".*"
list+=( $(awk -v "R=$root/" "\$5~/^$srcname-[^-]+-[^-]+$/ && \$3~/^$archpat\$/ {print R\$3\"/RPMS/\"\$4}" "$BIN_LIST") )
# Fallthgrough to the ls'er.
else
# Displayed from http by select_one
exit
fi
elif [ -n "$query" ]; then
if [ -n "$dts" ]; then
select_one
list=("$RPM")
fi
list=( $(printf "%s\n" "${list[@]}" | sort -V) )
for rpm in "${list[@]}"; do
prefix=$(basename "$rpm")
if [ -z "${RPM-}" ]; then
repo=${rpm%%/files/*}
repo=${repo##*/}
prefix=$repo/$prefix
else
prefix=$REPO@$prefix
fi
rpm -qp "$query" -- "$rpm" |
if ! sed "s,^,$prefix: ," | grep --color=auto "$pattern"; then
echo "$prefix: no match"
fi
done
exit
elif [ -v aptcache ]; then
if [ -n "$dts" ]; then
select_one
list=("$RPM")
fi
list=( $(printf "%s\n" "${list[@]}" | sort -V) )
sep=
for rpm in "${list[@]}"; do
echo -n "$sep"
NAME=$(rpm -qp --qf "%{NAME}" "$rpm")
(set -x; apt-cache "$aptcache" "$NAME") | grep -Ev '^\s{6}'
sep=$'\n'
done
exit
elif [ -n "$dts" ]; then
# Last resort - just print d-t-s-evr.list
dts='' select_one
grab_dts
printf '%s\n' "- $DTS_FILE" >&2
printf '%s\n' "$DTS_LIST" |& less
exit
elif [ -v spec ]; then
select_one
specfile=$(rpm -q --qf '[-%{FILEFLAGS:fflags} %{FILENAMES}\n]' -p "$RPM" | grep '^\S*s')
specfile=${specfile#* }
rpmpeek "$RPM" cat "$specfile" | view +'set ft=spec' -
exit
fi
if [ -t 1 ]; then
HIGHLIGHT=$'sed -E s!/([Ss]isyphus)/!/\e[1;33m\\1\e[m/!'
else
HIGHLIGHT='cat'
fi
# shellcheck disable=SC2086
ls $lsopts -- "${list[@]}" \
| sed -E 's/^\S+\s+\S+\s+\S+\s+\S+//' \
| $HIGHLIGHT \
| grep -P --color '^|[^-]+-alt[^-]+(?=\.[^.]+(\.src)?\.s?rpm)'