Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 110 additions & 27 deletions pacman-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ die () {

mode=
case "$1" in
lock|unlock|break_lock|quick_add)
lock|unlock|break_lock|quick_add|quick_remove)
mode="$1"
shift
;;
*)
die "Usage:\n%s\n%s\n" \
die "Usage:\n%s\n%s\n%s\n" \
" $0 quick_add <package>..." \
" $0 quick_remove <package>..." \
" $0 ( lock | unlock <id> | break_lock )"
;;
esac
Expand Down Expand Up @@ -107,6 +108,23 @@ repo_add () {
"$this_script_dir/repo-add" "$@"
}

repo_remove () {
if test ! -s "$this_script_dir/repo-remove"
then
# Make sure that GPGKEY is used unquoted
sed 's/"\(\${\?GPGKEY}\?\)"/\1/g' </usr/bin/repo-remove >"$this_script_dir/repo-remove"
fi &&
"$this_script_dir/repo-remove" $(for arg
do
# repo-remove only accepts package _names_, but we are potentially given _files_.
# Handle this by distilling the package names from filenames.
case "$arg" in
*.pkg.tar.xz|*.pkg.tar.zst) echo "${arg%-*-*-*}";;
*) echo "$arg";;
esac
done)
}

sanitize_db () { # <file>...
perl -e '
foreach my $path (@ARGV) {
Expand Down Expand Up @@ -174,10 +192,17 @@ sanitize_db () { # <file>...
fi
}

quick_add () { # <file>...
test $# -gt 0 ||
quick_action () { # <action> <file>...
test $# -gt 1 ||
die "Need at least one file"

label="$1"
shift
case "$label" in
add|remove) action=repo_$label;;
*) die "Unknown action '$action'";;
esac

if test -z "$PACMANDRYRUN$azure_blobs_token"
then
azure_blobs_token="$(cat "$HOME"/.azure-blobs-token)" &&
Expand Down Expand Up @@ -212,7 +237,8 @@ quick_add () { # <file>...
x86_64_msys=
all_files=

# Copy the file(s) to the temporary directory, and schedule their addition to the appropriate index(es)
# Copy the file(s) to the temporary directory, and schedule their addition to the appropriate index(es),
# or for `remove`: schedule their removal from the appropriate index(es).
for path in "$@"
do
file="${path##*/}"
Expand Down Expand Up @@ -248,6 +274,22 @@ quick_add () { # <file>...
# skip explicit signatures; we copy them automatically
continue
;;
*-i686|*-x86_64|*-aarch64)
test remove = "$label" || die "Cannot add $path"
arch=${file##*-}
file=${file%-$arch}
file=${file%-[0-9]*-[0-9]*}
key=${arch}_msys
;;
mingw-w64-i686-*|mingw-w64-x86_64-*|mingw-w64-clang-aarch64-*)
test remove = "$label" || die "Cannot add $path"
arch=${file#mingw-w64-}
arch=${arch#clang-}
arch=${arch%%-*}
file=${file%-any}
file=${file%-[0-9]*-[0-9]*}
key=${arch}_mingw
;;
*)
echo "Skipping unknown file: $file" >&2
continue
Expand All @@ -259,12 +301,12 @@ quick_add () { # <file>...
*) echo "Skipping file with unknown arch: $file" >&2; continue;;
esac

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

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

case "$label" in
remove)
test -z "$GPGKEY" ||
all_files="$all_files $arch/$file.sig"
continue
;;
esac

echo "Copying $file to $arch/..." >&2
cp "$path" "$dir/$arch" ||
die "Could not copy $path to $dir/$arch"

if test -f "$path".sig
then
cp "$path".sig "$dir/$arch/" ||
die "Could not copy $path.sig to $dir/$arch"
all_files="$all_files $arch/$file.sig"
all_files="$all_files $arch/$file.sig"
elif test -n "$GPGKEY"
then
echo "Signing $arch/$file..." >&2
Expand All @@ -293,7 +344,7 @@ quick_add () { # <file>...
PACMAN_DB_LEASE="$(lock)" ||
die 'Could not obtain a lock for uploading'

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

# Now add the files to the Pacman database
repo_add $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
# Now add or remove the files to the Pacman database
$action $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
{ test ! -h git-for-windows-$arch.db || rm git-for-windows-$arch.db; } &&
cp git-for-windows-$arch.db.tar.xz git-for-windows-$arch.db && {
test -z "$sign_option" || {
Expand All @@ -366,7 +417,7 @@ quick_add () { # <file>...
} &&
if test -n "$db2"
then
repo_add $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
$action $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
{ test ! -h git-for-windows-$db2.db || rm git-for-windows-$db2.db; } &&
cp git-for-windows-$db2.db.tar.xz git-for-windows-$db2.db && {
test -z "$sign_option" || {
Expand All @@ -376,20 +427,41 @@ quick_add () { # <file>...
}
fi &&

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

# Now add the files to the Git branch
git add --sparse $msys $mingw \*.sig ':(exclude)*.old.sig' &&
msg="$(printf 'Update %s package(s)\n\n%s\n' \
$(printf '%s\n' $msys $mingw | wc -l) \
"$(printf '%s\n' $msys $mingw |
sed 's/^\(.*\)-\([^-]*-[^-]*\)-[^-]*\.pkg\.tar\.\(xz\|zst\)$/\1 -> \2/')")" &&
case "$label" in
add)
git add --sparse $msys $mingw \*.sig ':(exclude)*.old.sig' &&
msg="$(printf 'Update %s package(s)\n\n%s\n' \
$(printf '%s\n' $msys $mingw | wc -l) \
"$(printf '%s\n' $msys $mingw |
sed 's/^\(.*\)-\([^-]*-[^-]*\)-[^-]*\.pkg\.tar\.\(xz\|zst\)$/\1 -> \2/')")"
;;
remove)
msg="$(printf 'Remove %s package(s)\n\n%s\n' \
$(printf '%s\n' $msys $mingw | wc -l) \
"$(printf '%s\n' $msys $mingw)")"
esac &&
git commit -asm "$msg") ||
die "Could not add $msys $mingw to db in $arch"
die "Could not ${label} $msys $mingw to/from db in $arch"
done

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

eval "msys=\$${arch}_msys" &&
eval "mingw=\$${arch}_mingw" &&
printf '%s\n' $msys $mingw |
sed 's/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/' |
xargs -r git restore --ignore-skip-worktree-bits -- &&

repo_add $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
case "$label" in
add)
printf '%s\n' $msys $mingw |
sed 's/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/' |
xargs -r git restore --ignore-skip-worktree-bits --
;;
esac &&
$action $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
{ test ! -h git-for-windows-$arch.db || rm git-for-windows-$arch.db; } &&
cp git-for-windows-$arch.db.tar.xz git-for-windows-$arch.db && {
test -z "$sign_option" || {
Expand All @@ -441,7 +516,7 @@ quick_add () { # <file>...
} &&
if test -n "$db2"
then
repo_add $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
$action $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
{ test ! -h git-for-windows-$db2.db || rm git-for-windows-$db2.db; } &&
cp git-for-windows-$db2.db.tar.xz git-for-windows-$db2.db && {
test -z "$sign_option" || {
Expand Down Expand Up @@ -483,7 +558,7 @@ quick_add () { # <file>...
echo "Would upload $path to release" >&2
continue
fi
echo "Uploading $path to release $id" >&2
echo "Uploading $path to release $id" >&2
case "$path" in
*.sig) content_type=application/pgp-signature;;
*) content_type=application/x-xz;;
Expand Down Expand Up @@ -551,6 +626,14 @@ quick_add () { # <file>...
die "Could not remove $dir/"
}

quick_add () {
quick_action add "$@"
}

quick_remove () {
quick_action remove "$@"
}

lock () { #
test -z "$PACMANDRYRUN" || {
echo "upload: wingit-snapshot-helper.sh wingit x86-64 <token> lock git-for-windows.db" >&2
Expand Down