#!/bin/bash # Restore NexusOS from Gitea (enderofwings/NexusOS). Clones or pulls the repo, # rebuilds the memory DB from its SQL dump, then rebuilds the regenerable env # (venv, frontend deps) and desktop integration (theme, terminal, panel). # # restore.sh Pull latest + rebuild. # restore.sh -c | --claude Dry-run: fetch + show what a restore WOULD apply. No changes. NEXUS_ROOT="$HOME/nexus-core" REPO="https://git.enderofwings.com/enderofwings/NexusOS.git" mode="${1:-}" DB="$NEXUS_ROOT/synapse/memory/memory.db" DB_SQL="$NEXUS_ROOT/synapse/memory/memory.db.sql" detect_requirements() { if command -v nvidia-smi &>/dev/null || lspci 2>/dev/null | grep -qi nvidia; then echo "requirements-nvidia.txt" else echo "requirements-amd.txt" fi } # Fresh machine: clone. Existing: work in place. if [ ! -d "$NEXUS_ROOT/.git" ]; then echo "No local repo — cloning from Gitea..." git clone "$REPO" "$NEXUS_ROOT" || { echo "Clone failed."; exit 1; } fi cd "$NEXUS_ROOT" || { echo "No $NEXUS_ROOT"; exit 1; } # Check mode: dry-run. Fetch and show what a real restore would pull, no changes. if [ "$mode" = "-c" ] || [ "$mode" = "--claude" ] || [ "$mode" = "check" ]; then echo "Fetching to preview restore (no changes)..." git fetch origin echo "" echo "Commits a restore would apply:" git log --oneline ..origin/main 2>/dev/null || echo "(up to date)" echo "" git diff --stat ..origin/main 2>/dev/null echo "" echo "(dry-run only — nothing changed. Apply with: restore)" exit 0 fi echo "Pulling latest from Gitea..." git pull --ff-only origin main || { echo "Pull failed (diverged? stash/commit local changes)."; exit 1; } # Rebuild the memory DB from its SQL dump — only if there's no live DB, so we # never clobber a machine that has newer conversations than the backup. if [ -f "$DB_SQL" ] && [ ! -f "$DB" ]; then echo "" echo "Rebuilding memory DB from dump..." sqlite3 "$DB" < "$DB_SQL" && echo "Memory DB restored." \ || echo "Warning: memory DB rebuild failed." elif [ -f "$DB" ]; then echo "Live memory DB present — left as-is (dump not applied). Delete it first to restore from backup." fi echo "" echo "Rebuilding Python environment..." if [ ! -x "$NEXUS_ROOT/Promethean/bin/pip" ]; then python3 -m venv "$NEXUS_ROOT/Promethean" fi req=$(detect_requirements) if [ -f "$NEXUS_ROOT/$req" ]; then "$NEXUS_ROOT/Promethean/bin/pip" install --upgrade pip -q "$NEXUS_ROOT/Promethean/bin/pip" install -r "$NEXUS_ROOT/$req" else echo "Warning: $req not found — skipping pip install." fi echo "" echo "Rebuilding frontend dependencies..." cd "$NEXUS_ROOT/interface/web" && npm install cd "$NEXUS_ROOT" 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 echo "" echo "Restore complete. Nexus is ready to start." echo "Note: Ollama models are not in the backup — pull them with \`ollama pull \` as needed."