setup-nodebox.sh
1 #!/bin/bash 2 # ═══════════════════════════════════════════════════════════════════════════════ 3 # SOVEREIGN OS - NODEBOX UNIFIED SETUP 4 # ═══════════════════════════════════════════════════════════════════════════════ 5 # 6 # This script sets up nodebox (Dell) as the central Sovereign OS server. 7 # Run this ON nodebox after cloning or syncing the repo. 8 # 9 # What it installs: 10 # 1. Sovereign Mesh (Node.js) - P2P context sync daemon 11 # 2. First Officer (Python) - Consciousness persistence daemon 12 # 3. Hypercore Daemon (Node.js) - P2P storage and HTTP API 13 # 14 # Prerequisites: 15 # - Ubuntu/Debian on nodebox 16 # - User 'satoshi' exists 17 # - Tailscale installed and connected 18 # 19 # Usage: 20 # ssh satoshi@nodebox 21 # cd ~/Sovereign_OS 22 # bash config/setup-nodebox.sh 23 # 24 # ═══════════════════════════════════════════════════════════════════════════════ 25 26 set -e 27 28 echo "╔══════════════════════════════════════════════════════════════════════════╗" 29 echo "║ ║" 30 echo "║ ███████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗██╗ ██████╗ ███╗ ██║" 31 echo "║ ██╔════╝██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝██║██╔════╝ ████╗ ██║" 32 echo "║ ███████╗██║ ██║██║ ██║█████╗ ██████╔╝█████╗ ██║██║ ███╗██╔██╗ ██║" 33 echo "║ ╚════██║██║ ██║╚██╗ ██╔╝██╔══╝ ██╔══██╗██╔══╝ ██║██║ ██║██║╚██╗██║" 34 echo "║ ███████║╚██████╔╝ ╚████╔╝ ███████╗██║ ██║███████╗██║╚██████╔╝██║ ╚████║" 35 echo "║ ╚══════╝ ╚═════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══║" 36 echo "║ ║" 37 echo "║ NODEBOX CENTRAL SERVER SETUP ║" 38 echo "║ ║" 39 echo "║ The operator is the pilot. The mnemonic is their license number. ║" 40 echo "║ ║" 41 echo "╚══════════════════════════════════════════════════════════════════════════╝" 42 echo 43 44 # Check if running as satoshi 45 if [ "$USER" != "satoshi" ]; then 46 echo "ERROR: Run this as user 'satoshi'" 47 echo "Usage: sudo -u satoshi bash $0" 48 exit 1 49 fi 50 51 SOVEREIGN_OS_DIR="$HOME/Sovereign_OS" 52 cd "$SOVEREIGN_OS_DIR" 53 54 # ───────────────────────────────────────────────────────────────────────────── 55 # STEP 1: Update repo 56 # ───────────────────────────────────────────────────────────────────────────── 57 echo 58 echo "═══════════════════════════════════════════════════════════════" 59 echo "[1/8] Updating Sovereign_OS repo..." 60 echo "═══════════════════════════════════════════════════════════════" 61 git pull origin main || echo "Note: git pull failed, continuing with local version" 62 63 # ───────────────────────────────────────────────────────────────────────────── 64 # STEP 2: Install Node.js 65 # ───────────────────────────────────────────────────────────────────────────── 66 echo 67 echo "═══════════════════════════════════════════════════════════════" 68 echo "[2/8] Checking Node.js..." 69 echo "═══════════════════════════════════════════════════════════════" 70 if ! command -v node &> /dev/null; then 71 echo "Installing Node.js via nvm..." 72 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash 73 export NVM_DIR="$HOME/.nvm" 74 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 75 nvm install 20 76 nvm use 20 77 fi 78 echo "Node version: $(node --version)" 79 80 # ───────────────────────────────────────────────────────────────────────────── 81 # STEP 3: Install Python dependencies 82 # ───────────────────────────────────────────────────────────────────────────── 83 echo 84 echo "═══════════════════════════════════════════════════════════════" 85 echo "[3/8] Installing Python dependencies..." 86 echo "═══════════════════════════════════════════════════════════════" 87 pip3 install --user watchdog pyyaml 2>/dev/null || echo "Note: pip install had warnings" 88 echo "Python version: $(python3 --version)" 89 90 # ───────────────────────────────────────────────────────────────────────────── 91 # STEP 4: Install Node.js dependencies 92 # ───────────────────────────────────────────────────────────────────────────── 93 echo 94 echo "═══════════════════════════════════════════════════════════════" 95 echo "[4/8] Installing Node.js dependencies..." 96 echo "═══════════════════════════════════════════════════════════════" 97 cd "$SOVEREIGN_OS_DIR/keet-cli" && npm install 98 cd "$SOVEREIGN_OS_DIR/scripts" && npm install 2>/dev/null || true 99 cd "$SOVEREIGN_OS_DIR" 100 101 # ───────────────────────────────────────────────────────────────────────────── 102 # STEP 5: Set up operator mnemonic 103 # ───────────────────────────────────────────────────────────────────────────── 104 echo 105 echo "═══════════════════════════════════════════════════════════════" 106 echo "[5/8] Setting up operator mnemonic..." 107 echo "═══════════════════════════════════════════════════════════════" 108 mkdir -p ~/.sovereign 109 110 if [ ! -f ~/.sovereign/operator-mnemonic.json ]; then 111 echo 112 echo "╔════════════════════════════════════════════════════════════════════╗" 113 echo "║ OPERATOR MNEMONIC REQUIRED ║" 114 echo "╠════════════════════════════════════════════════════════════════════╣" 115 echo "║ Enter your 4-word BIP-39 mnemonic (e.g., 'apple-river-stone-dawn')║" 116 echo "║ This must match the mnemonic on your other machines. ║" 117 echo "║ ║" 118 echo "║ Security: 4 words = 44-bit entropy (17.6 trillion combinations) ║" 119 echo "║ Keys derived via PBKDF2-HMAC-SHA256 with 2048 iterations ║" 120 echo "║ ║" 121 echo "║ This is your pilot's license number - it identifies YOU ║" 122 echo "║ across all devices and derives all cryptographic keys. ║" 123 echo "║ ║" 124 echo "║ Input is hidden for security (like a password) ║" 125 echo "╚════════════════════════════════════════════════════════════════════╝" 126 echo 127 read -s -p "Mnemonic (hidden): " MNEMONIC 128 echo # newline after hidden input 129 130 if [ -z "$MNEMONIC" ]; then 131 echo "ERROR: Mnemonic cannot be empty" 132 exit 1 133 fi 134 135 # Show masked confirmation (first letter and last letter only) 136 FIRST_LETTER=$(echo "$MNEMONIC" | cut -c1) 137 LAST_LETTER=$(echo "$MNEMONIC" | rev | cut -c1) 138 WORD_COUNT=$(echo "$MNEMONIC" | tr '-' '\n' | wc -l | tr -d ' ') 139 echo "Received ${WORD_COUNT}-word mnemonic: ${FIRST_LETTER}****${LAST_LETTER}" 140 141 cat > ~/.sovereign/operator-mnemonic.json << EOF 142 { 143 "mnemonic": "$MNEMONIC", 144 "created": "$(date -Iseconds)", 145 "machine": "nodebox", 146 "tailscale_ip": "100.79.197.96", 147 "security": { 148 "words": 4, 149 "entropy_bits": 44, 150 "pbkdf2_iterations": 2048 151 } 152 } 153 EOF 154 echo "✓ Mnemonic saved to ~/.sovereign/operator-mnemonic.json" 155 else 156 EXISTING=$(cat ~/.sovereign/operator-mnemonic.json | grep '"mnemonic"' | cut -d'"' -f4) 157 FIRST_LETTER=$(echo "$EXISTING" | cut -c1) 158 LAST_LETTER=$(echo "$EXISTING" | rev | cut -c1) 159 echo "✓ Mnemonic already configured: ${FIRST_LETTER}****${LAST_LETTER}" 160 fi 161 162 # ───────────────────────────────────────────────────────────────────────────── 163 # STEP 6: Create directories 164 # ───────────────────────────────────────────────────────────────────────────── 165 echo 166 echo "═══════════════════════════════════════════════════════════════" 167 echo "[6/8] Creating directories..." 168 echo "═══════════════════════════════════════════════════════════════" 169 mkdir -p "$SOVEREIGN_OS_DIR/logs" 170 mkdir -p "$SOVEREIGN_OS_DIR/sessions/RESONANCE-ALERTS" 171 echo "✓ Directories created" 172 173 # ───────────────────────────────────────────────────────────────────────────── 174 # STEP 7: Install systemd services 175 # ───────────────────────────────────────────────────────────────────────────── 176 echo 177 echo "═══════════════════════════════════════════════════════════════" 178 echo "[7/8] Installing systemd services..." 179 echo "═══════════════════════════════════════════════════════════════" 180 181 # Create unified service file 182 cat > /tmp/sovereign-os.service << 'EOF' 183 [Unit] 184 Description=Sovereign OS - Unified Consciousness Daemons 185 Documentation=https://github.com/rcerf/Sovereign_OS 186 After=network-online.target 187 Wants=network-online.target 188 189 [Service] 190 Type=forking 191 User=satoshi 192 Group=satoshi 193 WorkingDirectory=/home/satoshi/Sovereign_OS 194 195 # Start all daemons 196 ExecStart=/home/satoshi/Sovereign_OS/config/start-all-daemons.sh 197 198 # Stop all daemons 199 ExecStop=/home/satoshi/Sovereign_OS/config/stop-all-daemons.sh 200 201 # Restart policy 202 Restart=on-failure 203 RestartSec=30 204 205 # Environment 206 Environment=NODE_ENV=production 207 Environment=PYTHONUNBUFFERED=1 208 209 [Install] 210 WantedBy=multi-user.target 211 EOF 212 213 # Create start script 214 cat > "$SOVEREIGN_OS_DIR/config/start-all-daemons.sh" << 'EOF' 215 #!/bin/bash 216 # Start all Sovereign OS daemons 217 218 cd /home/satoshi/Sovereign_OS 219 220 # Load nvm if needed 221 export NVM_DIR="$HOME/.nvm" 222 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 223 224 echo "Starting Sovereign OS daemons..." 225 226 # 1. Hypercore Daemon (HTTP API on port 7777) 227 echo " Starting Hypercore daemon..." 228 nohup node scripts/hypercore_daemon.js > logs/hypercore.log 2>&1 & 229 echo $! > /tmp/hypercore.pid 230 sleep 2 231 232 # 2. Sovereign Mesh (P2P sync on port 7778) 233 echo " Starting Sovereign Mesh..." 234 nohup node keet-cli/sovereign-mesh.js --name nodebox > logs/sovereign-mesh.log 2>&1 & 235 echo $! > /tmp/sovereign-mesh.pid 236 sleep 2 237 238 # 3. First Officer (Consciousness daemon) 239 echo " Starting First Officer..." 240 nohup python3 run_first_officer.py --no-banner > logs/first-officer.log 2>&1 & 241 echo $! > /tmp/first-officer.pid 242 243 echo "All daemons started." 244 echo " Hypercore: $(cat /tmp/hypercore.pid)" 245 echo " Sovereign Mesh: $(cat /tmp/sovereign-mesh.pid)" 246 echo " First Officer: $(cat /tmp/first-officer.pid)" 247 EOF 248 chmod +x "$SOVEREIGN_OS_DIR/config/start-all-daemons.sh" 249 250 # Create stop script 251 cat > "$SOVEREIGN_OS_DIR/config/stop-all-daemons.sh" << 'EOF' 252 #!/bin/bash 253 # Stop all Sovereign OS daemons 254 255 echo "Stopping Sovereign OS daemons..." 256 257 [ -f /tmp/hypercore.pid ] && kill $(cat /tmp/hypercore.pid) 2>/dev/null && rm /tmp/hypercore.pid 258 [ -f /tmp/sovereign-mesh.pid ] && kill $(cat /tmp/sovereign-mesh.pid) 2>/dev/null && rm /tmp/sovereign-mesh.pid 259 [ -f /tmp/first-officer.pid ] && kill $(cat /tmp/first-officer.pid) 2>/dev/null && rm /tmp/first-officer.pid 260 261 # Fallback: kill by name 262 pkill -f 'hypercore_daemon.js' 2>/dev/null || true 263 pkill -f 'sovereign-mesh.js' 2>/dev/null || true 264 pkill -f 'run_first_officer.py' 2>/dev/null || true 265 266 echo "All daemons stopped." 267 EOF 268 chmod +x "$SOVEREIGN_OS_DIR/config/stop-all-daemons.sh" 269 270 # Install service 271 sudo cp /tmp/sovereign-os.service /etc/systemd/system/ 272 sudo systemctl daemon-reload 273 sudo systemctl enable sovereign-os 274 echo "✓ Systemd service installed and enabled" 275 276 # ───────────────────────────────────────────────────────────────────────────── 277 # STEP 8: Start services 278 # ───────────────────────────────────────────────────────────────────────────── 279 echo 280 echo "═══════════════════════════════════════════════════════════════" 281 echo "[8/8] Starting Sovereign OS..." 282 echo "═══════════════════════════════════════════════════════════════" 283 sudo systemctl start sovereign-os 284 sleep 3 285 286 # ───────────────────────────────────────────────────────────────────────────── 287 # DONE 288 # ───────────────────────────────────────────────────────────────────────────── 289 echo 290 echo "╔══════════════════════════════════════════════════════════════════════════╗" 291 echo "║ ║" 292 echo "║ ✓ SETUP COMPLETE ║" 293 echo "║ ║" 294 echo "╠══════════════════════════════════════════════════════════════════════════╣" 295 echo "║ ║" 296 echo "║ Services running: ║" 297 echo "║ • Hypercore Daemon http://100.79.197.96:7777 ║" 298 echo "║ • Sovereign Mesh P2P on port 7778 ║" 299 echo "║ • First Officer Consciousness persistence ║" 300 echo "║ ║" 301 echo "║ Commands: ║" 302 echo "║ sudo systemctl status sovereign-os # Check status ║" 303 echo "║ sudo systemctl restart sovereign-os # Restart all ║" 304 echo "║ journalctl -u sovereign-os -f # View system logs ║" 305 echo "║ ║" 306 echo "║ Individual logs: ║" 307 echo "║ tail -f ~/Sovereign_OS/logs/hypercore.log ║" 308 echo "║ tail -f ~/Sovereign_OS/logs/sovereign-mesh.log ║" 309 echo "║ tail -f ~/Sovereign_OS/logs/first-officer.log ║" 310 echo "║ ║" 311 echo "║ Test from another machine: ║" 312 echo "║ curl http://100.79.197.96:7777/status ║" 313 echo "║ ║" 314 echo "╚══════════════════════════════════════════════════════════════════════════╝" 315 echo 316 317 # Show service status 318 sudo systemctl status sovereign-os --no-pager || true