71 lines
2.7 KiB
Bash
71 lines
2.7 KiB
Bash
#!/bin/sh
|
|
# XBPS INSTALL script — post-install and post-upgrade paths.
|
|
#
|
|
# Arguments: $1=ACTION $2=PKGNAME $3=VERSION $4=UPDATE $5=CONF_FILE $6=ARCH
|
|
#
|
|
# Actions: pre (before files extracted), post (after files extracted)
|
|
# UPDATE: "yes" on upgrade, "no" on fresh install
|
|
set -eu
|
|
|
|
STORE_DIR="/var/lib/fenris"
|
|
STORE_DB="${STORE_DIR}/observations.db"
|
|
STORE_BAK="${STORE_DIR}/observations.db.bak"
|
|
RUNTIME_PYTHON="/usr/bin/python3"
|
|
VENDOR_DIR="/opt/fenris/vendor"
|
|
|
|
ACTION="$1"
|
|
UPDATE="$4"
|
|
|
|
case "${ACTION}" in
|
|
pre)
|
|
# Migration guard — abort if make-install remnants detected
|
|
MARKER="/var/lib/fenris/manifest.txt"
|
|
if [ -f "${MARKER}" ]; then
|
|
echo >&2
|
|
echo >&2 "Fenris make-install remnants detected — refusing to install."
|
|
echo >&2
|
|
echo >&2 "Migrate to the package with:"
|
|
echo >&2 " sudo make uninstall # removes make-install files, preserves store + config"
|
|
echo >&2 " sudo xbps-install fenris"
|
|
echo >&2
|
|
echo >&2 "See: https://git.bongbetic.com/xavierk/Fenris/blob/main/docs/spec/release-packaging.md#9-migration-from-make-install-systems"
|
|
echo >&2
|
|
exit 1
|
|
fi
|
|
;;
|
|
post)
|
|
# Keep observation-store access consistent across fresh installs and upgrades.
|
|
groupadd -f fenris
|
|
install -d -o root -g fenris -m 2770 "${STORE_DIR}"
|
|
chmod 02770 "${STORE_DIR}"
|
|
if [ "${UPDATE}" = "yes" ]; then
|
|
# Upgrade — snapshot, migration, runit-aware reload
|
|
if [ -f "${STORE_DB}" ]; then
|
|
cp "${STORE_DB}" "${STORE_BAK}" 2>/dev/null || true
|
|
fi
|
|
if [ -d "${VENDOR_DIR}" ] && [ -f "${STORE_DB}" ]; then
|
|
PYTHONPATH="${VENDOR_DIR}" "${RUNTIME_PYTHON}" -c "
|
|
from fenris.store import migrate_to_latest
|
|
from pathlib import Path
|
|
n = migrate_to_latest(Path('${STORE_DB}'))
|
|
print(f'Fenris migration: {n} step(s) applied') if n else None
|
|
" 2>&1 || echo "Fenris: migration skipped (store not yet initialized)"
|
|
fi
|
|
# Ensure log directory exists on upgrade
|
|
groupadd -f fenris
|
|
install -d -o root -g fenris -m 2770 /var/log/fenris-collect 2>/dev/null || true
|
|
else
|
|
# Fresh install — runit service setup
|
|
groupadd -f fenris
|
|
# Mark runit service as dormant (down) for fresh install
|
|
if [ -d /etc/sv/fenris-collect ] && [ ! -e /var/service/fenris-collect ]; then
|
|
touch /etc/sv/fenris-collect/down
|
|
fi
|
|
# Ensure log directory exists
|
|
install -d -o root -g fenris -m 2770 /var/log/fenris-collect 2>/dev/null || true
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
exit 0
|