| 1 | #!/usr/bin/env bash |
| 2 | # Update the AUR package bluegit from the GitLab source archive of this commit. |
| 3 | # Pushes ssh://aur@aur.archlinux.org/bluegit.git master. AUR only accepts master. |
| 4 | set -euo pipefail |
| 5 | |
| 6 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 7 | # shellcheck source=aur-common.sh |
| 8 | source "$(dirname "$0")/aur-common.sh" |
| 9 | |
| 10 | # pkgver_of_commit is YYYYMMDDHHMMSS in UTC, from the committer time. |
| 11 | # CI_COMMIT_TIMESTAMP is ISO 8601. Without it, git show -s --format=%cI |
| 12 | # is the same instant the self-updater uses. The job clock is not a version. |
| 13 | # BusyBox date does not parse the Z or an offset, so the offset is applied here. |
| 14 | pkgver_of_commit() { |
| 15 | local root="$1" |
| 16 | local commit="${2:-}" |
| 17 | if [[ -z "$commit" ]]; then |
| 18 | commit="$(git_safe "$root" rev-parse HEAD)" || return 1 |
| 19 | fi |
| 20 | [[ "$commit" =~ ^[0-9a-f]{40}$ ]] || { echo "CI_COMMIT_SHA or HEAD is not a full sha" >&2; return 1; } |
| 21 | local stamp version |
| 22 | if [[ -n "${CI_COMMIT_TIMESTAMP:-}" ]]; then |
| 23 | stamp="$CI_COMMIT_TIMESTAMP" |
| 24 | else |
| 25 | # Zonder || blijft stamp leeg: set -e stopt niet op een falende |
| 26 | # command substitution, en utc_digits meldt dan een lege stempel. |
| 27 | stamp="$(git_safe "$root" show -s --format=%cI "$commit")" || return 1 |
| 28 | fi |
| 29 | version="$(utc_digits "$stamp")" || return 1 |
| 30 | [[ "$version" =~ ^[0-9]{14}$ ]] || { echo "pkgver is not a timestamp: ${version:-empty} from ${stamp:-empty}" >&2; return 1; } |
| 31 | printf '%s\n' "$version" |
| 32 | } |
| 33 | |
| 34 | # utc_digits turns ISO 8601 into YYYYMMDDHHMMSS in UTC. |
| 35 | # Accepted forms: 2026-10-22T23:32:33Z, 2026-10-22T23:32:33+01:00, 2026-10-22T23:32:33+0100. |
| 36 | utc_digits() { |
| 37 | local stamp="$1" core off sign hh mm epoch adj |
| 38 | if [[ "$stamp" == *Z ]]; then |
| 39 | core="${stamp%Z}" |
| 40 | off="+00:00" |
| 41 | elif [[ "$stamp" =~ ^(.+)([+-][0-9]{2}:[0-9]{2})$ ]]; then |
| 42 | core="${BASH_REMATCH[1]}" |
| 43 | off="${BASH_REMATCH[2]}" |
| 44 | elif [[ "$stamp" =~ ^(.+)([+-][0-9]{4})$ ]]; then |
| 45 | core="${BASH_REMATCH[1]}" |
| 46 | off="${BASH_REMATCH[2]:0:3}:${BASH_REMATCH[2]:3:2}" |
| 47 | else |
| 48 | core="$stamp" |
| 49 | off="+00:00" |
| 50 | fi |
| 51 | core="${core%%.*}" |
| 52 | core="${core/T/ }" |
| 53 | [[ "$core" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}$ ]] || { |
| 54 | echo "pkgver stamp is not ISO 8601: $stamp" >&2 |
| 55 | return 1 |
| 56 | } |
| 57 | sign="${off:0:1}" |
| 58 | hh="${off:1:2}" |
| 59 | mm="${off:4:2}" |
| 60 | epoch="$(TZ=UTC date -u -d "$core" +%s)" || return 1 |
| 61 | adj=$((10#$hh * 3600 + 10#$mm * 60)) |
| 62 | if [[ "$sign" == "+" ]]; then |
| 63 | epoch=$((epoch - adj)) |
| 64 | else |
| 65 | epoch=$((epoch + adj)) |
| 66 | fi |
| 67 | TZ=UTC date -u -d "@$epoch" +%Y%m%d%H%M%S |
| 68 | } |
| 69 | |
| 70 | if [[ "${1:-}" == "--rewrite-only" ]]; then |
| 71 | rewrite_pkgbuild "$2" "$3" "$4" "$5" |
| 72 | exit 0 |
| 73 | fi |
| 74 | |
| 75 | if [[ "${1:-}" == "--print-pkgver" ]]; then |
| 76 | pkgver_of_commit "$ROOT" "${CI_COMMIT_SHA:-}" |
| 77 | exit |
| 78 | fi |
| 79 | |
| 80 | for cmd in git sed sha256sum curl; do |
| 81 | command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; } |
| 82 | done |
| 83 | |
| 84 | if [[ -n "${CI_COMMIT_SHA:-}" ]]; then |
| 85 | COMMIT="$CI_COMMIT_SHA" |
| 86 | else |
| 87 | COMMIT="$(git_safe "$ROOT" rev-parse HEAD)" || exit 1 |
| 88 | fi |
| 89 | VERSION="$(pkgver_of_commit "$ROOT" "$COMMIT")" |
| 90 | |
| 91 | TMPDIR="${TMPDIR:-/tmp}" |
| 92 | WORKDIR="$(mktemp -d "$TMPDIR/bluegit-aur-XXXXXX")" |
| 93 | cleanup() { rm -rf "$WORKDIR"; } |
| 94 | trap cleanup EXIT |
| 95 | |
| 96 | SOURCE_URL="https://gitlab.com/Timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz" |
| 97 | TMP_SOURCE="$WORKDIR/source.tar.gz" |
| 98 | echo "Checking source tarball: $SOURCE_URL" |
| 99 | if ! curl -fsSL "$SOURCE_URL" -o "$TMP_SOURCE"; then |
| 100 | echo "Could not download $SOURCE_URL" >&2 |
| 101 | exit 1 |
| 102 | fi |
| 103 | SOURCE_SHA="$(sha256sum "$TMP_SOURCE" | awk '{print $1}')" |
| 104 | |
| 105 | dest="$WORKDIR/bluegit" |
| 106 | clone_or_init_aur_repo "bluegit" "$dest" |
| 107 | cd "$dest" |
| 108 | git config user.name "${AUR_GIT_AUTHOR_NAME:-BlueGit release bot}" |
| 109 | git config user.email "${AUR_GIT_AUTHOR_EMAIL:-noreply@example.invalid}" |
| 110 | cp "$ROOT/packaging/aur/PKGBUILD" PKGBUILD |
| 111 | cp "$ROOT/packaging/aur/bluegit.install" bluegit.install |
| 112 | rewrite_pkgbuild "$VERSION" "$COMMIT" "$SOURCE_SHA" PKGBUILD |
| 113 | generate_srcinfo |
| 114 | |
| 115 | if git diff --quiet -- PKGBUILD .SRCINFO bluegit.install 2>/dev/null && git rev-parse --verify HEAD >/dev/null 2>&1; then |
| 116 | echo "AUR repo already up to date: bluegit ${VERSION}" |
| 117 | exit 0 |
| 118 | fi |
| 119 | |
| 120 | git add PKGBUILD .SRCINFO bluegit.install |
| 121 | if git rev-parse --verify HEAD >/dev/null 2>&1; then |
| 122 | git commit -m "upstream ${VERSION}" |
| 123 | else |
| 124 | git commit -m "initial import ${VERSION}" |
| 125 | fi |
| 126 | git push -u origin master |
| 127 | echo "AUR updated: bluegit ${VERSION}" |