BlueGit

timfa bluegit

Files

bluegit / scripts / aur-publish-local.sh

aur-publish-local.sh

feat: publiceer de AUR lokaal en start de service bij installatie
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
Failed f02dd066 History
aur-publish-local.sh 5.2 KiB Download Raw
1#!/usr/bin/env bash
2# Publiceer bluegit naar de AUR vanuit een lokale checkout.
3# Gebruikt de sleutel in ~/.ssh of ssh-agent. Geen CI-variabelen.
4#
5# De checkout moet op master staan, schoon zijn en gelijk aan origin/master.
6# De gepubliceerde sha is die van origin/master. Staat die al als _commit
7# in de AUR-PKGBUILD, dan stopt het script zonder push.
8#
9# Werkmap: ~/.cache/bluegit-aur, of BLUEGIT_AUR_CACHE.
10# --check-only [repo] controleert de checkout en print de sha. Geen clone, geen push.
11set -euo pipefail
12
13ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
14# shellcheck source=aur-common.sh
15source "$(dirname "${BASH_SOURCE[0]}")/aur-common.sh"
16
17require_publishable_checkout() {
18 local repo="$1"
19 local branch head origin
20 branch="$(git -C "$repo" symbolic-ref --short HEAD 2>/dev/null || true)"
21 if [[ "$branch" != "master" ]]; then
22 echo "De checkout staat niet op master." >&2
23 exit 1
24 fi
25 if [[ -n "$(git -C "$repo" status --porcelain)" ]]; then
26 echo "De checkout is niet schoon." >&2
27 exit 1
28 fi
29 git -C "$repo" fetch origin master
30 head="$(git -C "$repo" rev-parse HEAD)"
31 origin="$(git -C "$repo" rev-parse origin/master)"
32 if [[ "$head" != "$origin" ]]; then
33 echo "De checkout wijkt af van origin/master." >&2
34 exit 1
35 fi
36 [[ "$origin" =~ ^[0-9a-f]{40}$ ]] || { echo "origin/master is geen volledige sha." >&2; exit 1; }
37 printf '%s\n' "$origin"
38}
39
40have_local_ssh() {
41 if command -v ssh-add >/dev/null 2>&1 && ssh-add -l >/dev/null 2>&1; then
42 return 0
43 fi
44 local f base
45 [[ -d "$HOME/.ssh" ]] || return 1
46 shopt -s nullglob
47 for f in "$HOME"/.ssh/*; do
48 [[ -f "$f" ]] || continue
49 base="$(basename "$f")"
50 case "$base" in
51 *.pub|known_hosts|known_hosts.old|config|authorized_keys|authorized_keys2) continue ;;
52 esac
53 if grep -q 'PRIVATE KEY' "$f" 2>/dev/null; then
54 shopt -u nullglob
55 return 0
56 fi
57 done
58 shopt -u nullglob
59 return 1
60}
61
62copy_packaging_aur() {
63 local src="$1" dest="$2"
64 local dotglob=0 nullglob=0
65 if shopt -q dotglob; then
66 dotglob=1
67 fi
68 if shopt -q nullglob; then
69 nullglob=1
70 fi
71 shopt -s dotglob nullglob
72 local files=("$src"/*)
73 if [[ "$nullglob" -eq 0 ]]; then
74 shopt -u nullglob
75 fi
76 if [[ "$dotglob" -eq 0 ]]; then
77 shopt -u dotglob
78 fi
79 if [[ ${#files[@]} -eq 0 ]]; then
80 echo "Geen bestanden in $src" >&2
81 exit 1
82 fi
83 local f
84 for f in "${files[@]}"; do
85 cp -a "$f" "$dest/"
86 done
87}
88
89sync_aur_workdir() {
90 local dest="$1"
91 local remote="ssh://aur@aur.archlinux.org/bluegit.git"
92 if [[ -d "$dest/.git" ]]; then
93 echo "Werk AUR-checkout bij: $dest"
94 git -C "$dest" remote set-url origin "$remote"
95 git -C "$dest" fetch origin master
96 git -C "$dest" checkout -f -B master origin/master
97 return 0
98 fi
99 if [[ -d "$dest" ]] && [[ -n "$(ls -A "$dest" 2>/dev/null || true)" ]]; then
100 echo "Werkmap $dest bestaat al en is geen git-checkout." >&2
101 exit 1
102 fi
103 mkdir -p "$(dirname "$dest")"
104 clone_or_init_aur_repo bluegit "$dest"
105}
106
107main() {
108 local CHECK_ONLY=0
109 local REPO="$ROOT"
110 if [[ "${1:-}" == "--check-only" ]]; then
111 CHECK_ONLY=1
112 shift
113 fi
114 if [[ $# -gt 0 ]]; then
115 if [[ "$CHECK_ONLY" -ne 1 || $# -ne 1 ]]; then
116 echo "Gebruik: $0 [--check-only [repo]]" >&2
117 exit 1
118 fi
119 REPO="$(cd "$1" && pwd)"
120 fi
121
122 local COMMIT
123 COMMIT="$(require_publishable_checkout "$REPO")"
124 echo "Publiceren: $COMMIT"
125 if [[ "$CHECK_ONLY" -eq 1 ]]; then
126 exit 0
127 fi
128
129 if [[ "$(id -u)" -eq 0 ]]; then
130 echo "Draai dit script als de gebruiker met de AUR-sleutel, niet als root." >&2
131 exit 1
132 fi
133 : "${HOME:?HOME is niet gezet}"
134 if ! have_local_ssh; then
135 echo "Geen AUR-sleutel: start ssh-agent en doe ssh-add, of zet een private sleutel in ~/.ssh." >&2
136 exit 1
137 fi
138
139 local cmd
140 for cmd in git sed updpkgsums makepkg; do
141 command -v "$cmd" >/dev/null || {
142 echo "Ontbrekend commando: $cmd. updpkgsums zit in pacman-contrib (pacman -S pacman-contrib)." >&2
143 exit 1
144 }
145 done
146
147 local CACHE="${BLUEGIT_AUR_CACHE:-$HOME/.cache/bluegit-aur}"
148 sync_aur_workdir "$CACHE"
149 if aur_commit_published "$CACHE/PKGBUILD" "$COMMIT"; then
150 echo "Deze sha staat al op de AUR ($COMMIT). Niets te doen."
151 exit 0
152 fi
153
154 copy_packaging_aur "$ROOT/packaging/aur" "$CACHE"
155 local VERSION
156 VERSION="$(TZ=UTC git -C "$REPO" show -s --date=format-local:%Y%m%d%H%M%S --format=%cd "$COMMIT")"
157 [[ "$VERSION" =~ ^[0-9]{14}$ ]] || { echo "pkgver uit de commit is geen tijdstempel: $VERSION" >&2; exit 1; }
158 set_pkgver_commit "$CACHE/PKGBUILD" "$VERSION" "$COMMIT"
159
160 mkdir -p "$CACHE/.makepkg/src" "$CACHE/.makepkg/build"
161 (
162 cd "$CACHE"
163 export SRCDEST="$CACHE/.makepkg/src"
164 export BUILDDIR="$CACHE/.makepkg/build"
165 export WORKDIR="$CACHE"
166 updpkgsums PKGBUILD
167 generate_srcinfo
168 )
169
170 cd "$CACHE"
171 git add PKGBUILD .SRCINFO bluegit.install
172 if git diff --cached --quiet; then
173 echo "AUR-checkout is al gelijk. Niets te doen."
174 exit 0
175 fi
176 if git rev-parse --verify HEAD >/dev/null 2>&1; then
177 git commit -m "upstream ${VERSION}"
178 else
179 git commit -m "initial import ${VERSION}"
180 fi
181 git push -u origin master
182 echo "AUR bijgewerkt: bluegit ${VERSION} (${COMMIT})"
183}
184
185if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
186 main "$@"
187fi