Setup install

This commit is contained in:
2025-12-02 05:06:08 -05:00
parent eeeae4740b
commit c0f308761b
4 changed files with 57 additions and 1 deletions

53
scripts/install.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail
MIRAGE_USER="${MIRAGE_USER:-mirage}"
MIRAGE_GROUP="${MIRAGE_GROUP:-mirage}"
MIRROR_ROOT="${MIRAGE_MIRROR_ROOT:-/srv/www/mirrors}"
DATA_DIR="${MIRAGE_DATA_DIR:-/var/lib/mirage}"
LOG_DIR="${MIRAGE_LOG_DIR:-/var/log/mirage}"
echo "==> Creating mirage user/group (if needed)"
if ! getent group "$MIRAGE_GROUP" >/dev/null 2>&1; then
groupadd --system "$MIRAGE_GROUP"
fi
if ! id "$MIRAGE_USER" >/dev/null 2>&1; then
useradd --system --no-create-home \
--gid "$MIRAGE_GROUP" \
--home-dir "$DATA_DIR" \
--shell /usr/bin/nologin \
"$MIRAGE_USER"
fi
echo "==> Creating directories"
mkdir -p "$MIRROR_ROOT" "$DATA_DIR" "$LOG_DIR"
chown -R "$MIRAGE_USER:$MIRAGE_GROUP" "$MIRROR_ROOT" "$DATA_DIR" "$LOG_DIR"
echo "==> Installing mirage Python package (pip install .)"
pip install .
MIRAGE_BIN="$(command -v mirage || true)"
if [ -z "$MIRAGE_BIN" ]; then
echo "ERROR: 'mirage' not found in PATH after pip install" >&2
exit 1
fi
echo "==> Installing systemd units"
install -D -m 644 systemd/mirage.service /etc/systemd/system/mirage.service
install -D -m 644 systemd/mirage-update.service /etc/systemd/system/mirage-update.service
install -D -m 644 systemd/mirage-update.timer /etc/systemd/system/mirage-update.timer
echo "==> Reloading systemd"
systemctl daemon-reload
echo "==> Enabling and starting mirage daemon + timer"
systemctl enable --now mirage.service
systemctl enable --now mirage-update.timer
echo "==> Done."
echo "Mirrors root : $MIRROR_ROOT"
echo "Data dir : $DATA_DIR"
echo "Log dir : $LOG_DIR"
echo "Binary : $MIRAGE_BIN"

View File

@@ -3,4 +3,7 @@ Description=Enqueue periodic updates for Mirage mirrors
[Service]
Type=oneshot
User=mirage
Group=mirage
ExecStart=/usr/bin/mirage mirrors update-all
WorkingDirectory=/var/lib/mirage

View File

@@ -1,4 +1,3 @@
# systemd/mirage-update.timer
[Unit]
Description=Run Mirage mirror updates periodically

View File

@@ -10,6 +10,7 @@ Group=mirage
ExecStart=/usr/bin/mirage daemon
Restart=on-failure
RestartSec=5
WorkingDirectory=/var/lib/mirage
[Install]
WantedBy=multi-user.target