Setup install
This commit is contained in:
53
scripts/install.sh
Executable file
53
scripts/install.sh
Executable 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"
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# systemd/mirage-update.timer
|
||||
[Unit]
|
||||
Description=Run Mirage mirror updates periodically
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user