#!/bin/sh
# Installeert BlueGit op Arch zonder makepkg.
# Gebruik: sudo packaging/install.sh
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
cd "$root"
export CGO_ENABLED=0
go build -trimpath -ldflags='-s -w' -o bluegit ./cmd/bluegit
install -Dm755 bluegit /usr/bin/bluegit
install -Dm644 packaging/bluegit.service /usr/lib/systemd/system/bluegit.service
install -Dm644 packaging/sysusers.conf /usr/lib/sysusers.d/bluegit.conf
install -Dm644 packaging/tmpfiles.conf /usr/lib/tmpfiles.d/bluegit.conf
install -Dm755 packaging/bluegit-update.sh /usr/lib/bluegit/update
install -Dm644 packaging/bluegit-update.service /usr/lib/systemd/system/bluegit-update.service
install -Dm644 packaging/bluegit-update.rules /usr/share/polkit-1/rules.d/49-bluegit-update.rules
install -Dm644 packaging/storage.conf /usr/share/bluegit/storage.conf.example
if [ ! -f /etc/bluegit/config.yml ]; then
  install -Dm640 packaging/bluegit.yml /etc/bluegit/config.yml
fi
systemd-sysusers bluegit.conf || true
systemd-tmpfiles --create bluegit.conf || true
systemctl daemon-reload
echo "Klaar. Vul /etc/bluegit/client_secret."
echo "De database komt in /var/lib/bluegit. Kies de datadisk zelf: kopieer /usr/share/bluegit/storage.conf.example naar /etc/systemd/system/bluegit.service.d/storage.conf en zet ReadWritePaths op die map."
echo "Daarna: systemctl daemon-reload && systemctl enable --now bluegit"
echo "De eerste aanmelding kiest hetzelfde pad in het setup-scherm. Git en CI doen niets tot dat gebeurd is."
