Skip to content

Commit ee3d397

Browse files
authored
Merge pull request #597 from jeremyd2019/jeremyd2019-quick-remove
pacman-helper.sh: add quick_remove mode
2 parents e85dbf3 + 0ef4d2a commit ee3d397

File tree

1 file changed

+110
-27
lines changed

1 file changed

+110
-27
lines changed

pacman-helper.sh

Lines changed: 110 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ die () {
3030

3131
mode=
3232
case "$1" in
33-
lock|unlock|break_lock|quick_add)
33+
lock|unlock|break_lock|quick_add|quick_remove)
3434
mode="$1"
3535
shift
3636
;;
3737
*)
38-
die "Usage:\n%s\n%s\n" \
38+
die "Usage:\n%s\n%s\n%s\n" \
3939
" $0 quick_add <package>..." \
40+
" $0 quick_remove <package>..." \
4041
" $0 ( lock | unlock <id> | break_lock )"
4142
;;
4243
esac
@@ -107,6 +108,23 @@ repo_add () {
107108
"$this_script_dir/repo-add" "$@"
108109
}
109110

111+
repo_remove () {
112+
if test ! -s "$this_script_dir/repo-remove"
113+
then
114+
# Make sure that GPGKEY is used unquoted
115+
sed 's/"\(\${\?GPGKEY}\?\)"/\1/g' </usr/bin/repo-remove >"$this_script_dir/repo-remove"
116+
fi &&
117+
"$this_script_dir/repo-remove" $(for arg
118+
do
119+
# repo-remove only accepts package _names_, but we are potentially given _files_.
120+
# Handle this by distilling the package names from filenames.
121+
case "$arg" in
122+
*.pkg.tar.xz|*.pkg.tar.zst) echo "${arg%-*-*-*}";;
123+
*) echo "$arg";;
124+
esac
125+
done)
126+
}
127+
110128
sanitize_db () { # <file>...
111129
perl -e '
112130
foreach my $path (@ARGV) {
@@ -174,10 +192,17 @@ sanitize_db () { # <file>...
174192
fi
175193
}
176194

177-
quick_add () { # <file>...
178-
test $# -gt 0 ||
195+
quick_action () { # <action> <file>...
196+
test $# -gt 1 ||
179197
die "Need at least one file"
180198

199+
label="$1"
200+
shift
201+
case "$label" in
202+
add|remove) action=repo_$label;;
203+
*) die "Unknown action '$action'";;
204+
esac
205+
181206
if test -z "$PACMANDRYRUN$azure_blobs_token"
182207
then
183208
azure_blobs_token="$(cat "$HOME"/.azure-blobs-token)" &&
@@ -212,7 +237,8 @@ quick_add () { # <file>...
212237
x86_64_msys=
213238
all_files=
214239

215-
# Copy the file(s) to the temporary directory, and schedule their addition to the appropriate index(es)
240+
# Copy the file(s) to the temporary directory, and schedule their addition to the appropriate index(es),
241+
# or for `remove`: schedule their removal from the appropriate index(es).
216242
for path in "$@"
217243
do
218244
file="${path##*/}"
@@ -248,6 +274,22 @@ quick_add () { # <file>...
248274
# skip explicit signatures; we copy them automatically
249275
continue
250276
;;
277+
*-i686|*-x86_64|*-aarch64)
278+
test remove = "$label" || die "Cannot add $path"
279+
arch=${file##*-}
280+
file=${file%-$arch}
281+
file=${file%-[0-9]*-[0-9]*}
282+
key=${arch}_msys
283+
;;
284+
mingw-w64-i686-*|mingw-w64-x86_64-*|mingw-w64-clang-aarch64-*)
285+
test remove = "$label" || die "Cannot add $path"
286+
arch=${file#mingw-w64-}
287+
arch=${arch#clang-}
288+
arch=${arch%%-*}
289+
file=${file%-any}
290+
file=${file%-[0-9]*-[0-9]*}
291+
key=${arch}_mingw
292+
;;
251293
*)
252294
echo "Skipping unknown file: $file" >&2
253295
continue
@@ -259,12 +301,12 @@ quick_add () { # <file>...
259301
*) echo "Skipping file with unknown arch: $file" >&2; continue;;
260302
esac
261303

262-
echo "Copying $file to $arch/..." >&2
263304
test -z "$key" || eval "$key=\$$key\\ $file"
264305
all_files="$all_files $arch/$file"
265306

266307
if test ! -d "$dir/$arch"
267308
then
309+
echo "Initializing $dir/$arch..." >&2
268310
git -C "$dir" rev-parse --quiet --verify refs/remotes/origin/$arch >/dev/null ||
269311
git -C "$dir" fetch --depth=1 origin x86_64 aarch64 i686 ||
270312
die "$dir: could not fetch from pacman-repo"
@@ -273,14 +315,23 @@ quick_add () { # <file>...
273315
die "Could not initialize $dir/$arch"
274316
fi
275317

318+
case "$label" in
319+
remove)
320+
test -z "$GPGKEY" ||
321+
all_files="$all_files $arch/$file.sig"
322+
continue
323+
;;
324+
esac
325+
326+
echo "Copying $file to $arch/..." >&2
276327
cp "$path" "$dir/$arch" ||
277328
die "Could not copy $path to $dir/$arch"
278329

279330
if test -f "$path".sig
280331
then
281332
cp "$path".sig "$dir/$arch/" ||
282333
die "Could not copy $path.sig to $dir/$arch"
283-
all_files="$all_files $arch/$file.sig"
334+
all_files="$all_files $arch/$file.sig"
284335
elif test -n "$GPGKEY"
285336
then
286337
echo "Signing $arch/$file..." >&2
@@ -293,7 +344,7 @@ quick_add () { # <file>...
293344
PACMAN_DB_LEASE="$(lock)" ||
294345
die 'Could not obtain a lock for uploading'
295346

296-
# Verify that the package databases are synchronized and add files
347+
# Verify that the package databases are synchronized and add or remove files
297348
sign_option=
298349
test -z "$GPGKEY" || sign_option=--sign
299350
dbs=
@@ -355,8 +406,8 @@ quick_add () { # <file>...
355406
git diff-index --quiet HEAD -- ||
356407
die "The package databases in $arch differ between Azure Blobs and pacman-repo"
357408

358-
# Now add the files to the Pacman database
359-
repo_add $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
409+
# Now add or remove the files to the Pacman database
410+
$action $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
360411
{ test ! -h git-for-windows-$arch.db || rm git-for-windows-$arch.db; } &&
361412
cp git-for-windows-$arch.db.tar.xz git-for-windows-$arch.db && {
362413
test -z "$sign_option" || {
@@ -366,7 +417,7 @@ quick_add () { # <file>...
366417
} &&
367418
if test -n "$db2"
368419
then
369-
repo_add $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
420+
$action $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
370421
{ test ! -h git-for-windows-$db2.db || rm git-for-windows-$db2.db; } &&
371422
cp git-for-windows-$db2.db.tar.xz git-for-windows-$db2.db && {
372423
test -z "$sign_option" || {
@@ -376,20 +427,41 @@ quick_add () { # <file>...
376427
}
377428
fi &&
378429

379-
# Remove previous versions from the Git branch
430+
# Remove the existing versions from the Git branch
380431
printf '%s\n' $msys $mingw |
381-
sed 's/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/' |
432+
sed '/\.pkg\.tar/{
433+
s/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/
434+
b1
435+
}
436+
s/$/-[0-9]*/
437+
:1
438+
p
439+
# Prevent false positives (e.g. deleting `msys2-runtime-3.3` when
440+
# updating `msys2-runtime`) by requiring the suffix to be of the form
441+
# `-<pkgver>-<pkgrel>-<arch><pkgext>`. Sadly, there are no non-greedy
442+
# wildcards, therefore do this via an "exclude pattern" instead:
443+
# `:(exclude)<pkgname>-[0-9]*-*-*-*`
444+
s/$/-*-*-*/
445+
s/^/:(exclude)/' |
382446
xargs git rm --sparse --cached -- ||
383-
die "Could not remove previous versions from the Git branch in $arch"
447+
die "Could not remove the existing versions from the Git branch in $arch"
384448

385449
# Now add the files to the Git branch
386-
git add --sparse $msys $mingw \*.sig ':(exclude)*.old.sig' &&
387-
msg="$(printf 'Update %s package(s)\n\n%s\n' \
388-
$(printf '%s\n' $msys $mingw | wc -l) \
389-
"$(printf '%s\n' $msys $mingw |
390-
sed 's/^\(.*\)-\([^-]*-[^-]*\)-[^-]*\.pkg\.tar\.\(xz\|zst\)$/\1 -> \2/')")" &&
450+
case "$label" in
451+
add)
452+
git add --sparse $msys $mingw \*.sig ':(exclude)*.old.sig' &&
453+
msg="$(printf 'Update %s package(s)\n\n%s\n' \
454+
$(printf '%s\n' $msys $mingw | wc -l) \
455+
"$(printf '%s\n' $msys $mingw |
456+
sed 's/^\(.*\)-\([^-]*-[^-]*\)-[^-]*\.pkg\.tar\.\(xz\|zst\)$/\1 -> \2/')")"
457+
;;
458+
remove)
459+
msg="$(printf 'Remove %s package(s)\n\n%s\n' \
460+
$(printf '%s\n' $msys $mingw | wc -l) \
461+
"$(printf '%s\n' $msys $mingw)")"
462+
esac &&
391463
git commit -asm "$msg") ||
392-
die "Could not add $msys $mingw to db in $arch"
464+
die "Could not ${label} $msys $mingw to/from db in $arch"
393465
done
394466

395467
test -n "$to_push" || die "No packages to push?!"
@@ -427,11 +499,14 @@ quick_add () { # <file>...
427499

428500
eval "msys=\$${arch}_msys" &&
429501
eval "mingw=\$${arch}_mingw" &&
430-
printf '%s\n' $msys $mingw |
431-
sed 's/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/' |
432-
xargs -r git restore --ignore-skip-worktree-bits -- &&
433-
434-
repo_add $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
502+
case "$label" in
503+
add)
504+
printf '%s\n' $msys $mingw |
505+
sed 's/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/' |
506+
xargs -r git restore --ignore-skip-worktree-bits --
507+
;;
508+
esac &&
509+
$action $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
435510
{ test ! -h git-for-windows-$arch.db || rm git-for-windows-$arch.db; } &&
436511
cp git-for-windows-$arch.db.tar.xz git-for-windows-$arch.db && {
437512
test -z "$sign_option" || {
@@ -441,7 +516,7 @@ quick_add () { # <file>...
441516
} &&
442517
if test -n "$db2"
443518
then
444-
repo_add $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
519+
$action $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
445520
{ test ! -h git-for-windows-$db2.db || rm git-for-windows-$db2.db; } &&
446521
cp git-for-windows-$db2.db.tar.xz git-for-windows-$db2.db && {
447522
test -z "$sign_option" || {
@@ -483,7 +558,7 @@ quick_add () { # <file>...
483558
echo "Would upload $path to release" >&2
484559
continue
485560
fi
486-
echo "Uploading $path to release $id" >&2
561+
echo "Uploading $path to release $id" >&2
487562
case "$path" in
488563
*.sig) content_type=application/pgp-signature;;
489564
*) content_type=application/x-xz;;
@@ -551,6 +626,14 @@ quick_add () { # <file>...
551626
die "Could not remove $dir/"
552627
}
553628

629+
quick_add () {
630+
quick_action add "$@"
631+
}
632+
633+
quick_remove () {
634+
quick_action remove "$@"
635+
}
636+
554637
lock () { #
555638
test -z "$PACMANDRYRUN" || {
556639
echo "upload: wingit-snapshot-helper.sh wingit x86-64 <token> lock git-for-windows.db" >&2

0 commit comments

Comments
 (0)