refactor(management): replace curses TUIs with API-backed ncp subcommands; panel/autostart/install integration
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+76
-94
@@ -1,109 +1,87 @@
|
||||
#!/bin/bash
|
||||
# NexusOS installer — Linux side.
|
||||
# Syncs the repo, builds the Python venv, installs frontend deps, registers ncp,
|
||||
# and installs the Promethean Terminal + panel.
|
||||
#
|
||||
# ./install.sh Linux install (default)
|
||||
# ./install.sh -w | --windows Hand off to the Windows installer (install-windows.ps1)
|
||||
|
||||
NEXUS_ROOT="$HOME/nexus-core"
|
||||
ROUTER_BACKUP="router:/tmp/mnt/Wingdrive2/nexus-backup/"
|
||||
ROUTER_BACKUP="router:/tmp/mnt/Wingdrive2/nexus-core/"
|
||||
|
||||
# ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
is_wsl() {
|
||||
grep -qi microsoft /proc/version 2>/dev/null
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: install.sh [-w|--windows] [-h|--help]
|
||||
|
||||
(no flags) Run the Linux install.
|
||||
-w, --windows Run the Windows installer (install-windows.ps1), which sets up
|
||||
WSL2 and bootstraps NexusOS inside it.
|
||||
-h, --help Show this help.
|
||||
EOF
|
||||
}
|
||||
|
||||
detect_requirements() {
|
||||
if command -v nvidia-smi &>/dev/null && nvidia-smi &>/dev/null 2>&1; then
|
||||
echo "nvidia_requirements.txt"
|
||||
echo "requirements-nvidia.txt"
|
||||
elif lspci 2>/dev/null | grep -qi nvidia; then
|
||||
echo "nvidia_requirements.txt"
|
||||
echo "requirements-nvidia.txt"
|
||||
elif grep -qi microsoft /proc/version 2>/dev/null; then
|
||||
echo "requirements-wsl.txt"
|
||||
elif lspci 2>/dev/null | grep -qi amd; then
|
||||
echo "requirements-amd.txt"
|
||||
else
|
||||
echo "amd_requirements.txt"
|
||||
echo "requirements-wsl.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
|
||||
run_windows() {
|
||||
local ps1="$NEXUS_ROOT/install-windows.ps1"
|
||||
if [ ! -f "$ps1" ]; then
|
||||
echo "Error: $ps1 not found." >&2
|
||||
exit 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"
|
||||
# install-windows.ps1 must run from Windows: it self-elevates to Administrator
|
||||
# and provisions WSL2 from the outside, then runs wsl-bootstrap.sh inside WSL.
|
||||
# Running it from within a WSL shell would be circular, so just point the way.
|
||||
cat <<EOF
|
||||
The Windows installer must be run from Windows, not from this shell.
|
||||
|
||||
# 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
|
||||
1. Open the nexus-core folder in Windows Explorer.
|
||||
2. Right-click install-windows.ps1 → "Run with PowerShell".
|
||||
|
||||
It will self-elevate, set up WSL2, copy the repo in, and run the bootstrap.
|
||||
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."
|
||||
}
|
||||
|
||||
# ─── Arg parsing ──────────────────────────────────────────────────────────────
|
||||
|
||||
case "${1:-}" in
|
||||
-w|--windows)
|
||||
run_windows
|
||||
exit $?
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1" >&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# ─── Step 1: Sync from router ─────────────────────────────────────────────────
|
||||
|
||||
echo "Pulling Nexus from router..."
|
||||
mkdir -p "$NEXUS_ROOT"
|
||||
rsync -avz --delete \
|
||||
--exclude='.git/' \
|
||||
--exclude='Promethean/' \
|
||||
--exclude='models/blobs/' \
|
||||
--exclude='ollama/' \
|
||||
@@ -157,29 +135,33 @@ if ! grep -q "nexus-core/management/nexus-cli.sh" "$HOME/.bashrc"; then
|
||||
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."
|
||||
if ! grep -qF "alias promethean='source ~/nexus-core/.promethean_bashrc'" "$HOME/.bashrc"; then
|
||||
printf '\n# Promethean\nalias promethean='"'"'source ~/nexus-core/.promethean_bashrc'"'"'\n' >> "$HOME/.bashrc"
|
||||
echo "promethean registered in ~/.bashrc."
|
||||
else
|
||||
echo "promethean already in ~/.bashrc — skipping."
|
||||
fi
|
||||
|
||||
# ─── Step 6: Promethean Terminal + panel ─────────────────────────────────────
|
||||
|
||||
echo ""
|
||||
echo "Installing Promethean Terminal..."
|
||||
bash "$NEXUS_ROOT/bin/promethean/install.sh" || \
|
||||
echo "Warning: Promethean Terminal install failed — run bin/promethean/install.sh manually."
|
||||
|
||||
echo ""
|
||||
echo "Installing NexusOS panel applet..."
|
||||
bash "$NEXUS_ROOT/bin/panel/install.sh" || \
|
||||
echo "Warning: panel install failed — run bin/panel/install.sh manually."
|
||||
|
||||
# ─── 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
|
||||
echo "Run 'ncp start' to launch Nexus."
|
||||
|
||||
Reference in New Issue
Block a user