BlueGit

timfa bluegit

Files

bluegit / packaging / aur / bluegit.install

bluegit.install

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
bluegit.install 3.2 KiB Download Raw
1# System-unit met User=bluegit, config in /etc/bluegit/config.yml en
2# state in /var/lib/bluegit. Dit is geen systemd --user-unit.
3# backup= in de PKGBUILD laat een bestaande config.yml staan.
4# Zonder draaiende systemd (chroot of container) faalt de transactie niet.
5
6_bluegit_have_systemd() {
7 if [[ "${_BLUEGIT_SYSTEMD_CHECKED:-}" == 1 ]]; then
8 [[ "${_BLUEGIT_SYSTEMD_OK}" == 1 ]]
9 return
10 fi
11 _BLUEGIT_SYSTEMD_CHECKED=1
12 if ! command -v systemctl >/dev/null 2>&1 || [[ ! -d /run/systemd/system ]]; then
13 _BLUEGIT_SYSTEMD_OK=0
14 echo "bluegit: systemd draait niet (chroot of container). De service is niet aangepast."
15 return 1
16 fi
17 _BLUEGIT_SYSTEMD_OK=1
18 return 0
19}
20
21_bluegit_run() {
22 _bluegit_have_systemd || return 0
23 local out rc
24 out="$(systemctl "$@" 2>&1)" && return 0
25 rc=$?
26 if printf '%s\n' "$out" | grep -Eq 'not been booted with systemd|Failed to connect to bus|Host is down'; then
27 echo "bluegit: systemd is niet bereikbaar. De service is niet aangepast."
28 return 0
29 fi
30 printf '%s\n' "$out" >&2
31 return "$rc"
32}
33
34_bluegit_unquote() {
35 local val="$1" n first last
36 val="${val#"${val%%[![:space:]]*}"}"
37 val="${val%"${val##*[![:space:]]}"}"
38 n=${#val}
39 if (( n >= 2 )); then
40 first="${val:0:1}"
41 last="${val:n-1:1}"
42 if [[ "$first" == "$last" && ( "$first" == '"' || "$first" == "'" ) ]]; then
43 val="${val:1:n-2}"
44 val="${val#"${val%%[![:space:]]*}"}"
45 val="${val%"${val##*[![:space:]]}"}"
46 fi
47 fi
48 printf '%s' "$val"
49}
50
51# Config én een niet-leeg clientgeheim. Een lege client_secret: "" telt niet.
52_bluegit_secret_ready() {
53 [[ -f /etc/bluegit/config.yml ]] || return 1
54 if [[ -f /etc/bluegit/client_secret ]]; then
55 local body
56 body="$(tr -d '[:space:]' < /etc/bluegit/client_secret || true)"
57 [[ -n "$body" ]] && return 0
58 fi
59 [[ -f /etc/bluegit/secret.env ]] || return 1
60 local line val
61 line="$(grep -E '^[[:space:]]*BLUEGIT_AUTH_CLIENT_SECRET=' /etc/bluegit/secret.env | tail -n 1 || true)"
62 [[ -n "$line" ]] || return 1
63 val="$(_bluegit_unquote "${line#*=}")"
64 [[ -n "$val" ]]
65}
66
67_bluegit_print_next_steps() {
68 cat <<'EOF'
69bluegit: de service is niet gestart. /etc/bluegit/config.yml en het clientgeheim moeten er allebei zijn.
70
71Vervolg:
721. Zorg dat /etc/bluegit/config.yml bestaat. Het package levert een voorbeeld.
732. Schrijf het clientgeheim naar /etc/bluegit/client_secret (mode 0600),
74 of zet BLUEGIT_AUTH_CLIENT_SECRET in /etc/bluegit/secret.env.
75 Een lege client_secret: "" in de config telt niet.
763. Kopieer /usr/share/bluegit/storage.conf.example naar
77 /etc/systemd/system/bluegit.service.d/storage.conf en zet ReadWritePaths.
784. systemctl daemon-reload && systemctl enable --now bluegit.service
79EOF
80}
81
82post_install() {
83 systemd-sysusers bluegit.conf || true
84 systemd-tmpfiles --create bluegit.conf || true
85 _bluegit_run daemon-reload || return
86 if _bluegit_secret_ready; then
87 _bluegit_run enable --now bluegit.service || return
88 else
89 _bluegit_print_next_steps
90 fi
91}
92
93post_upgrade() {
94 systemd-sysusers bluegit.conf || true
95 systemd-tmpfiles --create bluegit.conf || true
96 _bluegit_run daemon-reload || return
97 _bluegit_run try-restart bluegit.service
98}
99
100pre_remove() {
101 _bluegit_run disable --now bluegit.service
102}
103
104post_remove() {
105 _bluegit_run daemon-reload
106}