refactor(hosts): organize repository by server profiles (hosts/raspberrypi5, hosts/llm-node) and add host-aware installer
This commit is contained in:
1 parent
c53fc0a939
commit
c2740c9542
44 files changed
+528
-40
No files matched your search
+110
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bash
|
||||
# Host-aware installer for Backup-Orchestrator v0.4
|
||||
# Usage: sudo ./install.sh [--host <raspberrypi5|llm-node>] [--force-jobs] [--install-systemd]
|
||||
set -Eeuo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
HOST_NAME="$(hostname -s 2>/dev/null || hostname)"
|
||||
FORCE_JOBS=0
|
||||
INSTALL_SYSTEMD=0
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--host)
|
||||
HOST_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--force-jobs)
|
||||
FORCE_JOBS=1
|
||||
shift
|
||||
;;
|
||||
--install-systemd)
|
||||
INSTALL_SYSTEMD=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
echo "Usage: sudo $0 [--host <hostname>] [--force-jobs] [--install-systemd]"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: Unknown argument: $1" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
HOST_DIR="${REPO_ROOT}/hosts/${HOST_NAME}"
|
||||
if [[ ! -d "${HOST_DIR}" ]]; then
|
||||
echo "ERROR: Unknown host configuration '${HOST_NAME}'. Expected directory: ${HOST_DIR}" >&2
|
||||
echo "Available hosts:" >&2
|
||||
ls -1 "${REPO_ROOT}/hosts" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "=== Installing Backup-Orchestrator v0.4 for host '${HOST_NAME}' ==="
|
||||
|
||||
# 1. Backup existing binary if present
|
||||
if [[ -f /usr/local/sbin/backup-orchestrator ]]; then
|
||||
cp -a /usr/local/sbin/backup-orchestrator "/usr/local/sbin/backup-orchestrator.bak.$(date +%Y%m%d%H%M%S)"
|
||||
fi
|
||||
install -m 0755 "${REPO_ROOT}/orchestrator.py" /usr/local/sbin/backup-orchestrator
|
||||
|
||||
# 2. Prepare /etc/backup-orchestrator directories
|
||||
install -d -m 0750 /etc/backup-orchestrator
|
||||
install -d -m 0750 /etc/backup-orchestrator/scripts
|
||||
install -d -m 0750 /etc/backup-orchestrator/scripts/shinkan
|
||||
install -d -m 0700 /etc/backup-orchestrator/credentials
|
||||
install -d -m 0750 /var/log/backup-orchestrator
|
||||
|
||||
# 3. Install host-specific metadata & target registry
|
||||
install -m 0640 "${HOST_DIR}/host.json" /etc/backup-orchestrator/host.json
|
||||
install -m 0640 "${HOST_DIR}/targets.json" /etc/backup-orchestrator/targets.json
|
||||
|
||||
if [[ ! -f /etc/backup-orchestrator/jobs.csv || "${FORCE_JOBS}" -eq 1 ]]; then
|
||||
install -m 0640 "${HOST_DIR}/jobs.csv" /etc/backup-orchestrator/jobs.csv
|
||||
echo "Installed /etc/backup-orchestrator/jobs.csv from hosts/${HOST_NAME}/jobs.csv"
|
||||
else
|
||||
echo "Keeping existing /etc/backup-orchestrator/jobs.csv (use --force-jobs to overwrite)"
|
||||
fi
|
||||
|
||||
if [[ ! -f /etc/backup-orchestrator/notifications.json ]]; then
|
||||
install -m 0600 "${HOST_DIR}/notifications.json.example" /etc/backup-orchestrator/notifications.json
|
||||
echo "Created initial /etc/backup-orchestrator/notifications.json (mode 0600)"
|
||||
fi
|
||||
|
||||
# 4. Install shared common scripts + host-specific scripts + Shinkan adapters
|
||||
for s in "${REPO_ROOT}/scripts/common/"*.sh; do
|
||||
[[ -f "$s" ]] && install -m 0750 "$s" "/etc/backup-orchestrator/scripts/$(basename "$s")"
|
||||
done
|
||||
|
||||
for s in "${HOST_DIR}/scripts/"*.sh; do
|
||||
[[ -f "$s" ]] && install -m 0750 "$s" "/etc/backup-orchestrator/scripts/$(basename "$s")"
|
||||
done
|
||||
|
||||
for s in "${REPO_ROOT}/scripts/shinkan/"*; do
|
||||
if [[ -f "$s" ]]; then
|
||||
case "$s" in
|
||||
*.yml|*.yaml|*.json)
|
||||
install -m 0644 "$s" "/etc/backup-orchestrator/scripts/shinkan/$(basename "$s")"
|
||||
;;
|
||||
*)
|
||||
install -m 0755 "$s" "/etc/backup-orchestrator/scripts/shinkan/$(basename "$s")"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
# 5. Install daily wrapper & optional systemd units
|
||||
if [[ -f "${HOST_DIR}/systemd/backup-orchestrator-daily" ]]; then
|
||||
install -m 0755 "${HOST_DIR}/systemd/backup-orchestrator-daily" /usr/local/sbin/backup-orchestrator-daily
|
||||
fi
|
||||
|
||||
if [[ "${INSTALL_SYSTEMD}" -eq 1 ]]; then
|
||||
install -m 0644 "${HOST_DIR}/systemd/backup-orchestrator-daily.service" /etc/systemd/system/backup-orchestrator-daily.service
|
||||
install -m 0644 "${HOST_DIR}/systemd/backup-orchestrator-daily.timer" /etc/systemd/system/backup-orchestrator-daily.timer
|
||||
systemctl daemon-reload
|
||||
echo "Installed systemd service and timer for ${HOST_NAME}."
|
||||
fi
|
||||
|
||||
echo "=== Verification (--check) ==="
|
||||
/usr/local/sbin/backup-orchestrator --check
|
||||
Reference in new issue
Block a user