BlueGit

timfa bluegit

Files

bluegit / scripts / aur-publish-local.sh

aur-publish-local.sh

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