Files

168 lines
6.0 KiB
Bash
Executable File

#!/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-core/"
# ─── Helpers ──────────────────────────────────────────────────────────────────
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 "requirements-nvidia.txt"
elif lspci 2>/dev/null | grep -qi nvidia; then
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 "requirements-wsl.txt"
fi
}
run_windows() {
local ps1="$NEXUS_ROOT/install-windows.ps1"
if [ ! -f "$ps1" ]; then
echo "Error: $ps1 not found." >&2
exit 1
fi
# 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.
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
}
# ─── 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/' \
--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 "$@"
}
EOF
echo "ncp registered in ~/.bashrc."
else
echo "ncp already in ~/.bashrc — skipping."
fi
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."
echo "Run 'ncp start' to launch Nexus."