| 1 | #!/usr/bin/env bash |
| 2 | # publish-aur.sh PKGNAME — adapted from timfa/legacy-cycles. |
| 3 | # Runs in the tag pipeline after `release`: downloads this tag's .deb release |
| 4 | # asset, sets pkgver/_tag/sha256sums in packaging/aur/PKGNAME/PKGBUILD, |
| 5 | # regenerates .SRCINFO and pushes to aur.archlinux.org (the first push creates |
| 6 | # the AUR package). Uses AUR_GIT_AUTHOR_NAME / AUR_GIT_AUTHOR_EMAIL; the SSH |
| 7 | # key comes from aur-ssh-setup.sh (AUR_SSH_PRIVATE_KEY_B64). |
| 8 | set -euo pipefail |
| 9 | pkg="$1" |
| 10 | ROOT="$(cd "$(dirname "$0")/../.." && pwd)" |
| 11 | SRC="$ROOT/packaging/aur/$pkg" |
| 12 | : "${CI_COMMIT_TAG:?}" "${CI_PROJECT_URL:?}" "${AUR_GIT_AUTHOR_NAME:?}" "${AUR_GIT_AUTHOR_EMAIL:?}" |
| 13 | tag="$CI_COMMIT_TAG" |
| 14 | [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "not a release tag: $tag" >&2; exit 1; } |
| 15 | ver="${tag#v}" |
| 16 | url="$CI_PROJECT_URL/-/releases/$tag/assets/paperdoll-renderer-${tag}-amd64.deb" |
| 17 | |
| 18 | WORKDIR="$(mktemp -d)"; export WORKDIR |
| 19 | trap 'rm -rf "$WORKDIR"' EXIT |
| 20 | curl -fsSL "$url" -o "$WORKDIR/asset.deb" |
| 21 | sha="$(sha256sum "$WORKDIR/asset.deb" | awk '{print $1}')" |
| 22 | echo "$pkg $ver $url $sha" |
| 23 | |
| 24 | dest="$WORKDIR/$pkg" |
| 25 | remote="ssh://aur@aur.archlinux.org/${pkg}.git" |
| 26 | if ! git clone "$remote" "$dest"; then |
| 27 | echo "AUR repo $pkg does not exist yet; the first push creates it" |
| 28 | mkdir -p "$dest"; git -C "$dest" init -q -b master; git -C "$dest" remote add origin "$remote" |
| 29 | fi |
| 30 | git -C "$dest" symbolic-ref HEAD refs/heads/master |
| 31 | find "$dest" -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + |
| 32 | cp -a "$SRC/." "$dest/" |
| 33 | cd "$dest" |
| 34 | sed -i "s/^pkgver=.*/pkgver=${ver}/; s/^pkgrel=.*/pkgrel=1/; s/^_tag=.*/_tag=${tag}/; s/^sha256sums=.*/sha256sums=('${sha}')/" PKGBUILD |
| 35 | |
| 36 | useradd -m aurbuild 2>/dev/null || true |
| 37 | chmod 755 "$WORKDIR"; chown -R aurbuild "$dest" |
| 38 | runuser -u aurbuild -- makepkg --printsrcinfo > "$WORKDIR/srcinfo" |
| 39 | mv "$WORKDIR/srcinfo" .SRCINFO |
| 40 | chown -R root:root "$dest" |
| 41 | git config --global --add safe.directory '*' |
| 42 | git config user.name "$AUR_GIT_AUTHOR_NAME" |
| 43 | git config user.email "$AUR_GIT_AUTHOR_EMAIL" |
| 44 | git add -A |
| 45 | if git diff --cached --quiet; then echo "AUR $pkg already up to date ($ver)"; exit 0; fi |
| 46 | git commit -qm "$ver" |
| 47 | git push -u origin HEAD:master |
| 48 | echo "AUR updated: $pkg $ver" |