← back to Nas Setup
scripts/install-root-daemon-dwdump.sh
68 lines
#!/bin/bash
# install-root-daemon-dwdump.sh — one-paste, run as root:
# sudo bash /Users/macstudio3/Projects/nas-setup/scripts/install-root-daemon-dwdump.sh
#
# Same fix as install-root-daemon.sh, applied to the dw_unified mirror job
# (com.steve.nas-dwdump-mirror). The realestate installer already proved root can write
# to /Volumes/Henry and set up /var/root/.ssh, so this one runs the dw_unified pull once
# to verify, installs the root LaunchDaemon, and retires the old user agent.
set -uo pipefail
USER_HOME=/Users/macstudio3
NAS=$USER_HOME/Projects/nas-setup
HENRY=/Volumes/Henry/dw-backups/dw_unified
KEY=id_ed25519_wallco_20260530
LABEL=com.steve.nas-dwdump-mirror
ROOT_LABEL=$LABEL-root
DAEMON_SRC=$NAS/launchd/$ROOT_LABEL.plist
DAEMON_DST=/Library/LaunchDaemons/$ROOT_LABEL.plist
say(){ printf '\n=== %s ===\n' "$1"; }
if [ "$(id -u)" -ne 0 ]; then echo "must run as root: sudo bash $0"; exit 1; fi
# ── 1. ensure root ssh key (idempotent; realestate installer already did this) ──
say "1. ensure root ssh (/var/root/.ssh)"
install -d -m 700 /var/root/.ssh
install -m 600 "$USER_HOME/.ssh/$KEY" /var/root/.ssh/$KEY
if [ ! -f /var/root/.ssh/config ]; then
cat > /var/root/.ssh/config <<CFG
Host 45.61.58.125
HostName 45.61.58.125
User root
IdentityFile /var/root/.ssh/$KEY
IdentitiesOnly yes
StrictHostKeyChecking accept-new
UserKnownHostsFile /var/root/.ssh/known_hosts
CFG
chmod 600 /var/root/.ssh/config
fi
HOME=/var/root ssh -o BatchMode=yes -o ConnectTimeout=15 root@45.61.58.125 "echo ok" >/dev/null 2>&1 \
&& echo "OK — root authenticates to Kamatera." || echo "WARN — ssh test failed; the pull below will surface it."
# ── 2. run the dw_unified pull once as root (default GLOB + 100MB/100-TOC floors) ──
say "2. run the dw_unified pull once as root"
HOME=/var/root \
HENRY_BACKUP_DIR="$HENRY" \
NAS_BACKUP_DIR=/Volumes/DW-Backups/dw_unified \
PATH=/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin \
/opt/homebrew/bin/bash "$NAS/scripts/pull-dw-dump.sh"
echo "pull exit rc=$? (0 = a destination verified)"
# ── 3. install + bootstrap the root LaunchDaemon ──
say "3. install + bootstrap the root LaunchDaemon"
install -m 644 -o root -g wheel "$DAEMON_SRC" "$DAEMON_DST"
launchctl bootout system/$ROOT_LABEL 2>/dev/null
launchctl bootstrap system "$DAEMON_DST" && echo "bootstrapped $ROOT_LABEL into system/"
launchctl print system/$ROOT_LABEL >/dev/null 2>&1 && echo "loaded OK (runs daily 03:45 as root)"
# ── 4. retire the old user LaunchAgent ──
say "4. retire the old user LaunchAgent"
launchctl bootout gui/501/$LABEL 2>/dev/null && echo "booted out user agent gui/501/$LABEL"
launchctl disable gui/501/$LABEL 2>/dev/null || true
echo "user agent disabled"
say "DONE"
echo "Latest dw_unified on Henry:"; ls -la "$HENRY" 2>&1
echo
echo "If step 2 showed PASS + rc=0, the dw_unified nightly is now fixed too (the 41-day-stale gap is closed)."