#!/bin/bash # ╔══════════════════════════════════════╗ # ║ 👻 PHANTOM IDE — Auto Installer ║ # ╚══════════════════════════════════════╝ set -e INSTALL_DIR="$HOME" echo "" echo "👻 Phantom IDE Installer" echo "========================" echo "" # ── Detect install mode ────────────────────────────────── # If running from USB stick (script is ON the USB), copy files from USB # If running via curl|sh, download files from the server USB_DIR="$(cd "$(dirname "$0")" && pwd)" IS_USB_INSTALL=false if [ -f "$USB_DIR/phantom-server.js" ] && [ -f "$USB_DIR/phantom-ide.html" ]; then IS_USB_INSTALL=true echo "📦 USB install detected" else echo "📦 Remote install detected" fi # 1. Install Node.js if missing if ! command -v node &>/dev/null; then echo "📦 Installing Node.js..." curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - 2>/dev/null || true sudo apt-get install -y nodejs 2>/dev/null || true else echo "✅ Node.js $(node -v) already installed" fi # 2. Get Phantom files if [ "$IS_USB_INSTALL" = true ]; then echo "📂 Copying Phantom IDE files from USB..." cp "$USB_DIR/phantom-ide.html" "$INSTALL_DIR/phantom-ide.html" cp "$USB_DIR/phantom-server.js" "$INSTALL_DIR/phantom-server.js" cp "$USB_DIR/phantom-cli.js" "$INSTALL_DIR/phantom-cli.js" 2>/dev/null || true cp "$USB_DIR/phantom-knowledge.md" "$INSTALL_DIR/phantom-knowledge.md" 2>/dev/null || true cp "$USB_DIR/.phantom-ai-config.json" "$INSTALL_DIR/.phantom-ai-config.json" 2>/dev/null || true cp "$USB_DIR/.phantom-stripe-config.json" "$INSTALL_DIR/.phantom-stripe-config.json" 2>/dev/null || true # Copy public dir for install/payment pages mkdir -p "$INSTALL_DIR/public" "$INSTALL_DIR/buy-tokens" cp -r "$USB_DIR/public/"* "$INSTALL_DIR/public/" 2>/dev/null || true cp -r "$USB_DIR/buy-tokens/"* "$INSTALL_DIR/buy-tokens/" 2>/dev/null || true else echo "📂 Downloading Phantom IDE from phantomide.com..." # Download core files from the server SERVER="https://phantomide.com" mkdir -p "$INSTALL_DIR/public" "$INSTALL_DIR/buy-tokens" curl -fsSL "$SERVER/phantom-server.js" -o "$INSTALL_DIR/phantom-server.js" 2>/dev/null || echo "⚠️ phantom-server.js download failed" curl -fsSL "$SERVER/phantom-ide.html" -o "$INSTALL_DIR/phantom-ide.html" 2>/dev/null || echo "⚠️ phantom-ide.html download failed" curl -fsSL "$SERVER/phantom-cli.js" -o "$INSTALL_DIR/phantom-cli.js" 2>/dev/null || echo "⚠️ phantom-cli.js download failed" curl -fsSL "$SERVER/install" -o "$INSTALL_DIR/public/install.html" 2>/dev/null || true curl -fsSL "$SERVER/buy-tokens" -o "$INSTALL_DIR/buy-tokens/index.html" 2>/dev/null || true fi # 3. Install npm dependencies echo "📦 Installing dependencies..." cd "$INSTALL_DIR" npm install --save express ws cors pg 2>/dev/null || true npm install --save monaco-editor@0.44.0 2>/dev/null || echo "⚠️ monaco-editor install failed" npm install --save node-pty 2>/dev/null || echo "⚠️ node-pty skipped (optional)" # 4. Create phantom CLI command echo "🔧 Setting up phantom CLI..." chmod +x "$INSTALL_DIR/phantom-cli.js" 2>/dev/null || true sudo ln -sf "$INSTALL_DIR/phantom-cli.js" /usr/local/bin/phantom 2>/dev/null || { # If no sudo, use local bin mkdir -p "$HOME/.local/bin" ln -sf "$INSTALL_DIR/phantom-cli.js" "$HOME/.local/bin/phantom" echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc" export PATH="$HOME/.local/bin:$PATH" } # 5. Create server launcher script cat > "$INSTALL_DIR/phantom.sh" << 'EOF' #!/bin/bash cd "$HOME" echo "👻 Starting Phantom IDE on http://localhost:4000" node phantom-server.js & sleep 2 xdg-open http://localhost:4000 2>/dev/null || echo "Open your browser → http://localhost:4000" EOF chmod +x "$INSTALL_DIR/phantom.sh" # 6. Create systemd service for auto-start if command -v systemctl &>/dev/null; then echo "🔧 Setting up systemd service..." sudo tee /etc/systemd/system/phantom-server.service > /dev/null << SERVICE [Unit] Description=Phantom IDE Server After=network.target [Service] Type=simple User=$USER WorkingDirectory=$INSTALL_DIR Environment=NODE_ENV=production Environment=PORT=4000 ExecStart=/usr/bin/node $INSTALL_DIR/phantom-server.js Restart=always RestartSec=5 [Install] WantedBy=multi-user.target SERVICE sudo systemctl daemon-reload 2>/dev/null || true sudo systemctl enable phantom-server 2>/dev/null || true sudo systemctl start phantom-server 2>/dev/null || true fi # 7. Create desktop shortcut DESKTOP="$HOME/Desktop" mkdir -p "$DESKTOP" cat > "$DESKTOP/PhantomIDE.desktop" << EOF [Desktop Entry] Version=1.0 Type=Application Name=Phantom IDE Comment=Launch Phantom IDE Exec=bash $HOME/phantom.sh Icon=utilities-terminal Terminal=true Categories=Development; EOF chmod +x "$DESKTOP/PhantomIDE.desktop" gio set "$DESKTOP/PhantomIDE.desktop" metadata::trusted true 2>/dev/null || true # 8. Check if user_id was passed (from payment success page) PHANTOM_UID="${1:-}" if [ -n "$PHANTOM_UID" ]; then echo "🔑 Linking your account: $PHANTOM_UID" mkdir -p "$INSTALL_DIR/.phantom" echo "$PHANTOM_UID" > "$INSTALL_DIR/.phantom/user_id" export PHANTOM_UID="$PHANTOM_UID" # Also set in CLI config if [ -f "$INSTALL_DIR/.phantom-ai-config.json" ]; then node -e " const fs=require('fs'), f='$INSTALL_DIR/.phantom-ai-config.json'; try { const c=JSON.parse(fs.readFileSync(f,'utf8')); c.user_id='$PHANTOM_UID'; fs.writeFileSync(f,JSON.stringify(c,null,2)); } catch{} " 2>/dev/null || true fi fi echo "" echo "✅ Phantom IDE installed!" echo "" echo " Start the server: bash ~/phantom.sh" echo " Or double-click PhantomIDE on your Desktop" echo " Then open: http://localhost:4000" echo "" echo " CLI chat: phantom" if [ -n "$PHANTOM_UID" ]; then echo " Account linked: $PHANTOM_UID" fi echo "" echo " Buy tokens: phantom /buy" echo " Check balance: phantom /balance" echo " View plans: phantom /plan" echo ""