fix: make SparkFun removal and launchd bootstrap non-fatal under set -e

networksetup -removenetworkservice fails on the sole PPP-port service and
aborted the whole run at exit 4 (before pmset/backup agent). Both it and the
GUI-domain launchctl bootstrap (flaky over SSH) are now best-effort with a
warn; the LaunchAgent plist auto-loads at next login regardless.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mortdecai
2026-09-15 19:36:56 -04:00
parent 39f61f48ce
commit af51e0cfa3
2 changed files with 14 additions and 3 deletions
+13 -3
View File
@@ -112,9 +112,15 @@ if [[ "$dock_cur" == "${dock_want[*]} " ]]; then log skip "dock apps"; else
log set "dock apps = ${dock_want[*]}"; CHANGED=1
fi
# ---------- stray network service ----------
# ---------- stray network service (best-effort; never fatal) ----------
# macOS refuses -removenetworkservice for the sole service on a PPP port ("parameters were not
# valid"), so this may not remove it. It's a harmless disconnected entry — warn and move on.
if networksetup -listallnetworkservices | grep -qx 'SparkFun Pro Micro'; then
sudo networksetup -removenetworkservice 'SparkFun Pro Micro'; log set "removed SparkFun Pro Micro PPP service"; CHANGED=1
if sudo networksetup -removenetworkservice 'SparkFun Pro Micro' 2>/dev/null; then
log set "removed SparkFun Pro Micro PPP service"; CHANGED=1
else
log warn "could not remove SparkFun PPP service (macOS refuses; harmless — remove via Settings > Network if desired)"
fi
else log skip "no SparkFun service"; fi
# ---------- power (DAW) — AC profile only ----------
@@ -130,7 +136,11 @@ PL="$HOME/Library/LaunchAgents/xyz.sethpc.mac-backup.plist"
if [[ -f $PL ]] && cmp -s "$REPO/config/xyz.sethpc.mac-backup.plist" "$PL"; then log skip "backup launchd agent"; else
mkdir -p "$HOME/Library/LaunchAgents"; cp "$REPO/config/xyz.sethpc.mac-backup.plist" "$PL"
launchctl bootout "gui/$(id -u)/xyz.sethpc.mac-backup" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$PL"; log set "backup launchd agent (03:30 nightly)"; CHANGED=1
# bootstrap into the GUI domain is flaky over SSH (no bound Aqua session); the plist in
# ~/Library/LaunchAgents auto-loads at next login regardless, so never let this abort setup.
if launchctl bootstrap "gui/$(id -u)" "$PL" 2>/dev/null; then log set "backup launchd agent loaded (03:30 nightly)"
else log warn "backup agent copied; bootstrap-over-SSH failed (normal) — loads at next login"; fi
CHANGED=1
fi
# ---------- apply ----------