BlueGit

timfa bluegit

Files

bluegit / scripts / publish-aur.sh

publish-aur.sh

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