#!/bin/bash NEXUS_ROOT="$HOME/nexus-core" ROUTER_BACKUP="router:/tmp/mnt/Wingdrive2/nexus-backup/" # ─── Helpers ────────────────────────────────────────────────────────────────── is_wsl() { grep -qi microsoft /proc/version 2>/dev/null } detect_requirements() { if command -v nvidia-smi &>/dev/null && nvidia-smi &>/dev/null 2>&1; then echo "nvidia_requirements.txt" elif lspci 2>/dev/null | grep -qi nvidia; then echo "nvidia_requirements.txt" else echo "amd_requirements.txt" fi } get_windows_user() { powershell.exe -command '$env:USERNAME' 2>/dev/null | tr -d '\r\n' } setup_windows() { local win_user distro icon_src icon_win_dir icon_win_path wt_settings win_user=$(get_windows_user) distro="${WSL_DISTRO_NAME:-$(uname -n)}" if [ -z "$win_user" ] || [ ! -d "/mnt/c/Users/$win_user" ]; then echo "Could not locate Windows user directory — skipping Windows setup." return 1 fi # Copy icon to Windows filesystem icon_src="$NEXUS_ROOT/assets/nexus-terminal.png" icon_win_dir="/mnt/c/Users/$win_user/AppData/Local/Nexus" mkdir -p "$icon_win_dir" cp "$icon_src" "$icon_win_dir/nexus-terminal.png" icon_win_path="C:\\Users\\$win_user\\AppData\\Local\\Nexus\\nexus-terminal.png" # Create combined init file so WT session has ncp, nvm, and Promethean prompt cat > "$HOME/.promethean_init" << 'EOF' [[ -f ~/.bashrc ]] && source ~/.bashrc [[ -f ~/.promethean_bashrc ]] && source ~/.promethean_bashrc EOF # Patch Windows Terminal settings.json python3 - "$win_user" "$distro" "$icon_win_path" << 'PYEOF' import json, uuid, sys from pathlib import Path win_user, distro, icon_path = sys.argv[1], sys.argv[2], sys.argv[3] wt_candidates = [ f"/mnt/c/Users/{win_user}/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json", f"/mnt/c/Users/{win_user}/AppData/Local/Packages/Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe/LocalState/settings.json", ] settings_path = next((Path(p) for p in wt_candidates if Path(p).exists()), None) if not settings_path: print("Windows Terminal settings.json not found — skipping.") sys.exit(0) with open(settings_path) as f: settings = json.load(f) profiles = settings.setdefault("profiles", {}).setdefault("list", []) if any(p.get("name") == "Promethean" for p in profiles): print("Promethean profile already exists — skipping.") sys.exit(0) profiles.insert(0, { "guid": "{" + str(uuid.uuid4()) + "}", "name": "Promethean", "commandline": f"wsl.exe -d {distro} bash --init-file ~/.promethean_init", "startingDirectory": "~", "icon": icon_path, }) with open(settings_path, "w") as f: json.dump(settings, f, indent=4) print(f"Promethean profile added to Windows Terminal ({settings_path.parent.parent.name}).") PYEOF # Create desktop shortcut powershell.exe -command " \$ws = New-Object -ComObject WScript.Shell \$s = \$ws.CreateShortcut(\"\$env:USERPROFILE\Desktop\Promethean.lnk\") \$s.TargetPath = 'wt.exe' \$s.Arguments = '--profile Promethean' \$s.IconLocation = 'wt.exe,0' \$s.Save() " 2>/dev/null && echo "Desktop shortcut created." || echo "Could not create desktop shortcut — open Windows Terminal manually." } # ─── Step 1: Sync from router ───────────────────────────────────────────────── echo "Pulling Nexus from router..." mkdir -p "$NEXUS_ROOT" rsync -avz --delete \ --exclude='Promethean/' \ --exclude='models/blobs/' \ --exclude='ollama/' \ --exclude='interface/web/node_modules/' \ --exclude='interface/web/dist/' \ --exclude='runtime/' \ --exclude='__pycache__/' \ --exclude='*.pyc' \ -e ssh \ "$ROUTER_BACKUP" "$NEXUS_ROOT/" # ─── Step 2: Python venv ────────────────────────────────────────────────────── echo "" echo "Creating Python environment..." python3 -m venv "$NEXUS_ROOT/Promethean" # ─── Step 3: pip install ────────────────────────────────────────────────────── echo "" echo "Installing Python dependencies..." req=$(detect_requirements) echo "Detected: $req" 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 # ─── Step 4: npm install ────────────────────────────────────────────────────── echo "" echo "Installing frontend dependencies..." export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" if command -v npm &>/dev/null; then cd "$NEXUS_ROOT/interface/web" && npm install else echo "npm not found — install nvm/node then run 'cd $NEXUS_ROOT/interface/web && npm install'." fi # ─── Step 5: Register ncp in ~/.bashrc ─────────────────────────────────────── echo "" echo "Registering ncp..." if ! grep -q "nexus-core/management/nexus-cli.sh" "$HOME/.bashrc"; then cat >> "$HOME/.bashrc" << 'EOF' # Nexus ncp() { ~/nexus-core/management/nexus-cli.sh "$@" } alias promethean='source ~/.promethean_bashrc' EOF echo "ncp registered in ~/.bashrc." else echo "ncp already in ~/.bashrc — skipping." fi # ─── Step 6: Windows Terminal + desktop shortcut ────────────────────────────── if is_wsl; then echo "" echo "Configuring Windows environment..." setup_windows || true echo "" echo "Reload your shell or open a new terminal for ncp to take effect." fi # ─── Done ───────────────────────────────────────────────────────────────────── echo "" echo "Installation complete. Nexus is ready." if is_wsl; then echo "Open Windows Terminal → Promethean profile, or use the desktop shortcut." else echo "Run 'ncp start' to launch Nexus." fi