Files
NexusOS/bin/restore-linux.sh
T
jonandClaude Opus 4.8 ee6e5bead7 Replace stale bin/install.sh with a wrapper over sync.py restore
bin/install.sh still rsynced --delete from a backup path retired in July, so
the documented Linux install both failed and could erase a working tree. Every
step it claimed to do already lives in bin/sync.py, shared with Windows.

Root ./install.sh is now a thin wrapper over `sync.py restore`, so deployment
stays one bash command. It also registers ncp/promethean in ~/.bashrc, which
was the only thing the old script uniquely did.

Split restore-linux.sh into runtime (Ollama binary, shell aliases) and desktop
(XFCE panel, theme, os-release). Only desktop writes outside the repo, it now
auto-skips off XFCE, and `--no-desktop` skips it explicitly. Two tests keep the
stage names in sync and the $HOME writes confined to the desktop stage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 08:46:46 -05:00

166 lines
7.2 KiB
Bash

#!/bin/bash
# The Linux-only half of a restore: system packages, the bundled Ollama binary,
# and the XFCE desktop wiring (panel, wallpaper, theme, terminal, branding).
# None of it means anything on Windows, which is why it lives here instead of in
# bin/sync.py — sync.py owns the portable half and calls this in three stages:
#
# restore-linux.sh prep Before the rebuild: system packages the build needs.
# restore-linux.sh runtime After: Ollama binary + shell wiring. Any Linux box
# needs these to actually run NexusOS.
# restore-linux.sh desktop After: the XFCE look (panel, wallpaper, theme,
# branding). Cosmetic, this box's setup, and the only
# stage that rewrites files outside the repo and $HOME.
# Skippable with `--no-desktop`; auto-skipped off XFCE.
#
# Not meant to be run by hand — use `ncp restore` (python bin/sync.py restore).
# Set by bin/sync.py to the repo it was invoked from, so a clone in a scratch dir
# operates on itself instead of reaching into the real ~/nexus-core.
NEXUS_ROOT="${NEXUS_ROOT:-$HOME/nexus-core}"
stage="${1:?usage: restore-linux.sh prep|runtime|desktop}"
# sync.py calls these by name with check=False, so a stage renamed on one side
# and not the other would silently do nothing. Fail loudly instead; a test keeps
# this list and sync.py's call sites in agreement.
case "$stage" in
prep|runtime|desktop) ;;
*) echo "unknown stage: $stage (expected prep|runtime|desktop)" >&2; exit 2 ;;
esac
cd "$NEXUS_ROOT" || { echo "No $NEXUS_ROOT"; exit 1; }
if [ "$stage" = "prep" ]; then
# Fresh machine: the system packages the desktop + build steps need. No-op once
# installed, so it's cheap on an in-place restore. Skipped without apt (non-Debian).
if command -v apt-get >/dev/null; then
echo "Installing system packages..."
sudo apt-get install -y --no-install-recommends \
git sqlite3 curl python3-venv python3-gi gir1.2-gtk-3.0 \
nodejs npm xfce4-genmon-plugin plank blueman \
|| echo "Warning: some system packages failed — install them manually."
fi
exit 0
fi
if [ "$stage" = "runtime" ]; then
echo ""
echo "Ensuring Ollama binary..."
# ollama/ is gitignored, so a fresh clone has no binary — fetch it. No-op if the
# machine already has one (e.g. an in-place restore).
if [ -x "$NEXUS_ROOT/bin/fetch-ollama.sh" ]; then
"$NEXUS_ROOT/bin/fetch-ollama.sh" "$NEXUS_ROOT" || echo "Warning: Ollama fetch failed — install it manually."
else
echo "Warning: bin/fetch-ollama.sh not found — skipping Ollama fetch."
fi
# Shell wiring: the `ncp` function and the Promethean venv alias. This is the
# only place they get registered now that bin/install.sh is gone. Guarded by a
# grep so an in-place restore is a no-op and a scratch clone can't re-point an
# already-wired ~/.bashrc at itself.
if ! grep -q "management/nexus-cli.sh" "$HOME/.bashrc" 2>/dev/null; then
cat >> "$HOME/.bashrc" <<EOF
# Nexus
ncp() {
$NEXUS_ROOT/management/nexus-cli.sh "\$@"
}
EOF
echo "Registered ncp in ~/.bashrc."
fi
if ! grep -qF "alias promethean=" "$HOME/.bashrc" 2>/dev/null; then
printf "\n# Promethean\nalias promethean='source %s/.promethean_bashrc'\n" \
"$NEXUS_ROOT" >> "$HOME/.bashrc"
echo "Registered promethean in ~/.bashrc."
fi
# The AMD box runs CPU-only (Vega 20, 4GB VRAM thrashes). An NVIDIA box should not.
if command -v nvidia-smi >/dev/null && command -v sqlite3 >/dev/null && \
[ "$(sqlite3 "$NEXUS_ROOT/synapse/memory/memory.db" \
"select value from settings where key='memory_gpu_offload'" 2>/dev/null)" = "0" ]; then
echo "Note: memory_gpu_offload=0 came from the AMD box (4GB VRAM). This machine has an"
echo " NVIDIA GPU — raise it in Settings to actually use the card."
fi
exit 0
fi
# --- desktop stage: XFCE only, and it writes outside the repo -----------------
# Everything below reconfigures the logged-in user's desktop. On any other DE it
# would be actively wrong (copying XFCE channel XMLs onto a GNOME box does
# nothing good), so bail rather than make a mess of someone else's machine.
if ! command -v xfconf-query >/dev/null; then
echo "Not an XFCE session (no xfconf-query) — skipping desktop wiring."
exit 0
fi
# Panel layout, wallpaper, compositing, keybindings and terminal profile all live
# in the xfconf channel XMLs — restore them by copying the files back. xfconfd
# caches channels in memory and rewrites them on exit, so it has to die first or
# it clobbers what we just copied; the next xfconf-query respawns it.
xml_snap="$NEXUS_ROOT/assets/themes/restore-snapshot/xfconf-xml"
xml_dst="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml"
if [ -d "$xml_snap" ]; then
echo ""
echo "Restoring XFCE desktop settings (panel, wallpaper, effects)..."
mkdir -p "$xml_dst"
pkill -x xfconfd 2>/dev/null && sleep 1
cp -f "$xml_snap"/*.xml "$xml_dst/" 2>/dev/null
# Wallpaper props are keyed by monitor name, which differs per machine — point
# every backdrop this box actually has at the Nexus background.
bg="$NEXUS_ROOT/assets/background.png"
if [ -f "$bg" ] && [ -n "${DISPLAY:-}" ]; then
xfconf-query -c xfce4-desktop -l 2>/dev/null | grep 'last-image$' | while read -r p; do
xfconf-query -c xfce4-desktop -p "$p" -s "$bg" 2>/dev/null || true
done
fi
fi
# Multi-monitor primary-follow watcher (panel + Plank track the xrandr primary).
if [ -f "$NEXUS_ROOT/bin/panel/plank-primary-watch.sh" ]; then
mkdir -p "$HOME/.local/bin"
chmod +x "$NEXUS_ROOT/bin/panel/plank-primary-watch.sh"
ln -sf "$NEXUS_ROOT/bin/panel/plank-primary-watch.sh" "$HOME/.local/bin/plank-primary-watch.sh"
fi
plank_snap="$NEXUS_ROOT/assets/themes/restore-snapshot/plank"
if [ -d "$plank_snap" ]; then
mkdir -p "$HOME/.config/plank"
cp -rf "$plank_snap/." "$HOME/.config/plank/" # /. = contents, else it nests
fi
echo ""
echo "Restoring NexusOS desktop theme..."
theme_installer="$NEXUS_ROOT/assets/themes/install-theme.sh"
if [ -x "$theme_installer" ]; then
"$theme_installer"
elif [ -f "$theme_installer" ]; then
bash "$theme_installer"
else
echo "Warning: $theme_installer not found — skipping theme restore."
fi
echo ""
echo "Installing Promethean Terminal launcher..."
term_installer="$NEXUS_ROOT/bin/promethean/install.sh"
if [ -x "$term_installer" ]; then
"$term_installer"
else
echo "Warning: $term_installer not found — skipping."
fi
echo ""
echo "Installing panel applet..."
panel_installer="$NEXUS_ROOT/bin/panel/install.sh"
if [ -x "$panel_installer" ]; then
"$panel_installer"
else
echo "Warning: $panel_installer not found — skipping panel install."
fi
# Distro branding — the About dialog / neofetch read /etc/os-release.
if grep -q '^ID=linuxmint' /etc/os-release 2>/dev/null && ! grep -q 'NexusOS' /etc/os-release; then
echo ""
echo "Branding /etc/os-release as NexusOS..."
sudo sed -i -e 's/^NAME=.*/NAME="NexusOS"/' -e 's/^PRETTY_NAME=.*/PRETTY_NAME="NexusOS 1.0"/' \
/etc/os-release || echo "Warning: os-release branding skipped."
fi