124 lines
3.4 KiB
Bash
Executable File
124 lines
3.4 KiB
Bash
Executable File
#!/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}"
|
|
VENV_DIR="${MIRAGE_VENV_DIR:-/opt/mirage/venv}"
|
|
|
|
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
|
|
|
CONFIG_DIR="/etc/mirage"
|
|
CONFIG_FILE="$CONFIG_DIR/config.toml"
|
|
|
|
echo "==> Using python: $PYTHON_BIN"
|
|
echo "==> Mirage user: $MIRAGE_USER"
|
|
echo "==> Mirage group: $MIRAGE_GROUP"
|
|
echo "==> Mirror root: $MIRROR_ROOT"
|
|
echo "==> Data dir: $DATA_DIR"
|
|
echo "==> Log dir: $LOG_DIR"
|
|
echo "==> Venv dir: $VENV_DIR"
|
|
echo "==> Config file: $CONFIG_FILE"
|
|
echo
|
|
|
|
if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then
|
|
echo "ERROR: $PYTHON_BIN not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
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 data/log/mirror directories"
|
|
mkdir -p "$MIRROR_ROOT" "$DATA_DIR" "$LOG_DIR"
|
|
chown -R "$MIRAGE_USER:$MIRAGE_GROUP" "$MIRROR_ROOT" "$DATA_DIR" "$LOG_DIR"
|
|
|
|
echo "==> Installing default config in /etc/mirage (if missing)"
|
|
mkdir -p "$CONFIG_DIR"
|
|
|
|
if [ -f "$CONFIG_FILE" ]; then
|
|
echo " Config already exists at $CONFIG_FILE (leaving it untouched)"
|
|
else
|
|
if [ -f "./etc/mirage/config.toml" ]; then
|
|
echo " Using repo template ./etc/mirage/config.toml"
|
|
install -D -m 644 ./etc/mirage/config.toml "$CONFIG_FILE"
|
|
else
|
|
echo " No template found, generating a basic config at $CONFIG_FILE"
|
|
cat >"$CONFIG_FILE" <<EOF
|
|
# Mirage configuration
|
|
# This file was generated by scripts/install.sh
|
|
# Paths must be writable by the 'mirage' user.
|
|
|
|
# Root directory where mirror content is stored.
|
|
mirror_root = "${MIRROR_ROOT}"
|
|
|
|
# Directory for mirage internal state (queue DB, etc.)
|
|
data_dir = "${DATA_DIR}"
|
|
|
|
# Directory for log files (per-mirror logs, daemon logs, etc.)
|
|
log_dir = "${LOG_DIR}"
|
|
|
|
# Path to wget binary
|
|
wget_bin = "/usr/bin/wget"
|
|
|
|
# Maximum number of concurrent mirror updates
|
|
max_concurrent_updates = 4
|
|
EOF
|
|
chmod 644 "$CONFIG_FILE"
|
|
fi
|
|
fi
|
|
|
|
# Typical /etc ownership: root:root
|
|
chown root:root "$CONFIG_FILE"
|
|
|
|
echo "==> Creating virtualenv at $VENV_DIR"
|
|
mkdir -p "$(dirname "$VENV_DIR")"
|
|
"$PYTHON_BIN" -m venv "$VENV_DIR"
|
|
|
|
echo "==> Installing mirage into virtualenv"
|
|
"$VENV_DIR/bin/pip" install --upgrade pip setuptools wheel
|
|
"$VENV_DIR/bin/pip" install .
|
|
|
|
MIRAGE_BIN="$VENV_DIR/bin/mirage"
|
|
|
|
if [ ! -x "$MIRAGE_BIN" ]; then
|
|
echo "ERROR: $MIRAGE_BIN not found or not executable" >&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
|
|
|
|
cat <<EOF
|
|
|
|
==> Install complete.
|
|
|
|
Mirrors root : $MIRROR_ROOT
|
|
Data dir : $DATA_DIR
|
|
Log dir : $LOG_DIR
|
|
Config : $CONFIG_FILE
|
|
Venv : $VENV_DIR
|
|
Binary : $MIRAGE_BIN
|