501 lines
15 KiB
Bash
501 lines
15 KiB
Bash
#!/bin/bash
|
|
# OpenClaw DevMatrix Environment Setup
|
|
# Run this INSIDE the Ubuntu VM (ID: 300) after OS installation
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m'
|
|
|
|
log() { echo -e "${GREEN}[DevMatrix]${NC} $1"; }
|
|
warn() { echo -e "${YELLOW}[Warning]${NC} $1"; }
|
|
error() { echo -e "${RED}[Error]${NC} $1"; exit 1; }
|
|
info() { echo -e "${CYAN}[Info]${NC} $1"; }
|
|
|
|
log "🚀 Starting DevMatrix Environment Setup..."
|
|
|
|
# ============================================
|
|
# SYSTEM UPDATE (Skip if recent)
|
|
# ============================================
|
|
log "📦 Checking system update..."
|
|
if [ -f /var/lib/apt/periodic/update-success-stamp ] && [ $(($(date +%s) - $(stat -c %Y /var/lib/apt/periodic/update-success-stamp))) -lt 86400 ]; then
|
|
log "✓ System recently updated, skipping"
|
|
else
|
|
sudo apt update && sudo apt upgrade -y
|
|
log "✓ System updated"
|
|
fi
|
|
|
|
# ============================================
|
|
# BASE PACKAGES (Skip if installed)
|
|
# ============================================
|
|
log "📦 Checking base packages..."
|
|
|
|
PACKAGES="curl wget git git-lfs build-essential software-properties-common apt-transport-https ca-certificates gnupg lsb-release unzip zip jq htop tree vim nano tmux sshpass"
|
|
|
|
missing_packages=""
|
|
for pkg in $PACKAGES; do
|
|
if ! dpkg -l | grep -q "^ii $pkg "; then
|
|
missing_packages="$missing_packages $pkg"
|
|
fi
|
|
done
|
|
|
|
if [ -n "$missing_packages" ]; then
|
|
sudo apt install -y $missing_packages
|
|
log "✓ Installed missing packages"
|
|
else
|
|
log "✓ All base packages already installed"
|
|
fi
|
|
|
|
# ============================================
|
|
# INSTALL OPENCLAW (Skip if installed)
|
|
# ============================================
|
|
log "🦞 Checking OpenClaw..."
|
|
if command -v openclaw &> /dev/null; then
|
|
log "✓ OpenClaw already installed"
|
|
else
|
|
curl -fsSL https://openclaw.dev/install.sh | bash
|
|
log "✓ OpenClaw installed"
|
|
fi
|
|
|
|
# Add to PATH if not already
|
|
if ! grep -q ".openclaw/bin" ~/.bashrc; then
|
|
echo 'export PATH="$HOME/.openclaw/bin:$PATH"' >> ~/.bashrc
|
|
fi
|
|
export PATH="$HOME/.openclaw/bin:$PATH"
|
|
|
|
# ============================================
|
|
# NODE.JS
|
|
# ============================================
|
|
log "📦 Installing Node.js 20..."
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
|
sudo apt install -y nodejs
|
|
|
|
# ============================================
|
|
# PYTHON
|
|
# ============================================
|
|
log "📦 Installing Python development tools..."
|
|
sudo apt install -y python3 python3-pip python3-venv python3-dev python-is-python3
|
|
|
|
pip3 install --user \
|
|
pipenv poetry pytest black flake8 mypy bandit pylint \
|
|
jupyter notebook requests
|
|
|
|
# ============================================
|
|
# DOCKER
|
|
# ============================================
|
|
log "🐳 Installing Docker..."
|
|
sudo apt install -y docker.io docker-compose-plugin
|
|
sudo usermod -aG docker $USER
|
|
sudo systemctl enable --now docker
|
|
|
|
# ============================================
|
|
# FLUTTER (Mobile Development)
|
|
# ============================================
|
|
log "📱 Installing Flutter..."
|
|
sudo snap install flutter --classic
|
|
flutter config --enable-linux-desktop
|
|
flutter config --enable-web
|
|
|
|
# ============================================
|
|
# .NET (Cross-Platform)
|
|
# ============================================
|
|
log "🔷 Installing .NET 8..."
|
|
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
|
|
sudo dpkg -i packages-microsoft-prod.deb
|
|
sudo apt update
|
|
sudo apt install -y dotnet-sdk-8.0 aspnetcore-runtime-8.0
|
|
rm packages-microsoft-prod.deb
|
|
|
|
# ============================================
|
|
# RUST
|
|
# ============================================
|
|
log "🦀 Installing Rust..."
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
source $HOME/.cargo/env
|
|
|
|
# ============================================
|
|
# GO
|
|
# ============================================
|
|
log "🐹 Installing Go..."
|
|
sudo apt install -y golang-go
|
|
|
|
# ============================================
|
|
# WINE (Windows App Testing)
|
|
# ============================================
|
|
log "🍷 Installing Wine..."
|
|
sudo dpkg --add-architecture i386
|
|
sudo mkdir -pm755 /etc/apt/keyrings
|
|
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
|
|
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
|
|
sudo apt update
|
|
sudo apt install -y --install-recommends winehq-stable
|
|
|
|
# ============================================
|
|
# PLAYWRIGHT (UI Testing)
|
|
# ============================================
|
|
log "🎭 Installing Playwright..."
|
|
npm install -g @playwright/test
|
|
npx playwright install-deps chromium
|
|
npx playwright install chromium
|
|
|
|
# ============================================
|
|
# POSTGRESQL & REDIS
|
|
# ============================================
|
|
log "🗄️ Installing databases..."
|
|
sudo apt install -y postgresql postgresql-contrib redis-server
|
|
sudo systemctl enable --now postgresql
|
|
sudo systemctl enable --now redis-server
|
|
|
|
# ============================================
|
|
# CLOUD TOOLS
|
|
# ============================================
|
|
log "☁️ Installing cloud tools..."
|
|
|
|
# AWS CLI
|
|
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
|
unzip -q awscliv2.zip
|
|
sudo ./aws/install
|
|
rm -rf aws awscliv2.zip
|
|
|
|
# Google Cloud SDK
|
|
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
|
|
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
|
|
sudo apt update && sudo apt install -y google-cloud-cli
|
|
|
|
# ============================================
|
|
# KUBERNETES TOOLS
|
|
# ============================================
|
|
log "☸️ Installing Kubernetes tools..."
|
|
sudo snap install kubectl --classic
|
|
sudo snap install helm --classic
|
|
|
|
# ============================================
|
|
# TERRAFORM
|
|
# ============================================
|
|
log "🏗️ Installing Terraform..."
|
|
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null
|
|
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
|
|
sudo apt update && sudo apt install -y terraform
|
|
|
|
# ============================================
|
|
# VS CODE SERVER
|
|
# ============================================
|
|
log "📝 Installing VS Code Server..."
|
|
curl -fsSL https://code-server.dev/install.sh | sh
|
|
|
|
# Configure code-server
|
|
mkdir -p ~/.config/code-server
|
|
cat > ~/.config/code-server/config.yaml << 'EOF'
|
|
bind-addr: 0.0.0.0:8080
|
|
auth: password
|
|
password: devmatrix-setup-2024
|
|
cert: false
|
|
EOF
|
|
|
|
sudo systemctl enable --now code-server@$USER
|
|
|
|
# ============================================
|
|
# WORKSPACE STRUCTURE
|
|
# ============================================
|
|
log "📁 Creating workspace structure..."
|
|
mkdir -p ~/{projects,scripts,docs,backups,logs}
|
|
cd ~/projects
|
|
mkdir -p {mobile,web,desktop,backend,infrastructure,experiments}
|
|
|
|
# ============================================
|
|
# VM CONTROL SCRIPTS
|
|
# ============================================
|
|
log "🤖 Creating VM control scripts..."
|
|
|
|
mkdir -p ~/scripts
|
|
|
|
# VM Control Script
|
|
cat > ~/scripts/vm_control.sh << 'EOF'
|
|
#!/bin/bash
|
|
PROXMOX_HOST="192.168.5.200"
|
|
WIN_VMID=301
|
|
ANDROID_VMID=302
|
|
|
|
case "$1" in
|
|
win-start)
|
|
ssh root@$PROXMOX_HOST "qm start $WIN_VMID"
|
|
echo "Windows VM starting..."
|
|
;;
|
|
win-stop)
|
|
ssh root@$PROXMOX_HOST "qm stop $WIN_VMID"
|
|
echo "Windows VM stopping..."
|
|
;;
|
|
win-status)
|
|
ssh root@$PROXMOX_HOST "qm status $WIN_VMID"
|
|
;;
|
|
android-start)
|
|
ssh root@$PROXMOX_HOST "qm start $ANDROID_VMID"
|
|
echo "Android VM starting..."
|
|
;;
|
|
android-stop)
|
|
ssh root@$PROXMOX_HOST "qm stop $ANDROID_VMID"
|
|
echo "Android VM stopping..."
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {win-start|win-stop|win-status|android-start|android-stop}"
|
|
;;
|
|
esac
|
|
EOF
|
|
chmod +x ~/scripts/vm_control.sh
|
|
|
|
# Windows Test Script
|
|
cat > ~/scripts/test_on_windows.sh << 'EOF'
|
|
#!/bin/bash
|
|
# Build and test .NET app on Windows VM
|
|
|
|
PROJECT_PATH="$1"
|
|
WIN_IP="192.168.5.201" # Adjust based on your DHCP
|
|
WIN_USER="testuser"
|
|
|
|
if [ -z "$PROJECT_PATH" ]; then
|
|
echo "Usage: $0 <project-path>"
|
|
exit 1
|
|
fi
|
|
|
|
echo "🪟 Starting Windows test sequence..."
|
|
|
|
# 1. Start Windows VM
|
|
~/scripts/vm_control.sh win-start
|
|
sleep 60
|
|
|
|
# 2. Build for Windows
|
|
echo "🔨 Building for Windows..."
|
|
dotnet publish "$PROJECT_PATH" -c Release -r win-x64 --self-contained
|
|
|
|
# 3. Copy to Windows
|
|
echo "📤 Deploying to Windows VM..."
|
|
scp -r "$PROJECT_PATH/bin/Release/net8.0/win-x64/publish/" "$WIN_USER@$WIN_IP:/C:/Apps/TestApp/"
|
|
|
|
# 4. Run test
|
|
ssh "$WIN_USER@$WIN_IP" "C:\\Apps\\TestApp\\TestApp.exe --version"
|
|
|
|
# 5. Stop VM
|
|
~/scripts/vm_control.sh win-stop
|
|
|
|
echo "✅ Windows test complete!"
|
|
EOF
|
|
chmod +x ~/scripts/test_on_windows.sh
|
|
|
|
# ============================================
|
|
# OPENCLAW CONFIGURATION FRAMEWORK
|
|
# ============================================
|
|
log "⚙️ Creating OpenClaw configuration framework..."
|
|
|
|
mkdir -p ~/.openclaw/workspaces/devmatrix
|
|
|
|
# Routing configuration
|
|
cat > ~/.openclaw/workspaces/devmatrix/routing.yaml << 'EOF'
|
|
routing:
|
|
strategy: "smart_fallback"
|
|
|
|
rules:
|
|
- name: "complex_tasks"
|
|
pattern: ".*(architecture|design|refactor|implement|create).*"
|
|
model: "kimi/k2p5"
|
|
priority: 1
|
|
|
|
- name: "quick_fixes"
|
|
pattern: ".*(fix|bug|error|typo|simple).*"
|
|
model: "antigravity/mixtral-8x7b"
|
|
priority: 2
|
|
|
|
- name: "documentation"
|
|
pattern: ".*(doc|comment|readme|explain).*"
|
|
model: "antigravity/qwen2.5-coder"
|
|
priority: 2
|
|
|
|
- name: "default"
|
|
pattern: ".*"
|
|
model: "kimi/k2p5"
|
|
priority: 99
|
|
|
|
cost_optimization:
|
|
monthly_budget: 100
|
|
alert_threshold: 80
|
|
EOF
|
|
|
|
# Swarm configuration
|
|
cat > ~/.openclaw/workspaces/devmatrix/swarm.yaml << 'EOF'
|
|
swarm:
|
|
name: "DevMatrix Swarm"
|
|
max_concurrent: 8
|
|
default_timeout: 300
|
|
|
|
agents:
|
|
- id: "architect"
|
|
name: "System Architect"
|
|
model: "kimi/k2p5"
|
|
|
|
- id: "frontend"
|
|
name: "Frontend Lead"
|
|
model: "kimi/k2p5"
|
|
|
|
- id: "backend"
|
|
name: "Backend Lead"
|
|
model: "kimi/k2p5"
|
|
|
|
- id: "devops"
|
|
name: "DevOps Engineer"
|
|
model: "antigravity/mixtral-8x7b"
|
|
|
|
- id: "qa"
|
|
name: "QA Engineer"
|
|
model: "antigravity/qwen2.5-coder"
|
|
|
|
- id: "windows_tester"
|
|
name: "Windows Test Agent"
|
|
model: "antigravity/mixtral-8x7b"
|
|
EOF
|
|
|
|
# ============================================
|
|
# API KEY CONFIGURATION SCRIPT
|
|
# ============================================
|
|
log "🔑 Creating API key configuration script..."
|
|
|
|
cat > ~/scripts/configure_api_keys.sh << 'EOFSCRIPT'
|
|
#!/bin/bash
|
|
# Configure API Keys for OpenClaw
|
|
# Run this after setup to add your API keys
|
|
|
|
echo "🔐 DevMatrix API Key Configuration"
|
|
echo "==================================="
|
|
echo ""
|
|
echo "You will need:"
|
|
echo " 1. Kimi API Key (from https://kimi.moonshot.cn/)"
|
|
echo " 2. Antigravity API Key (from your provider)"
|
|
echo ""
|
|
|
|
# Kimi API Key
|
|
read -sp "Enter your Kimi API Key: " KIMI_KEY
|
|
echo ""
|
|
|
|
# Antigravity API Key
|
|
read -sp "Enter your Antigravity API Key: " ANTIGRAVITY_KEY
|
|
echo ""
|
|
|
|
# Create config directory
|
|
mkdir -p ~/.openclaw/config
|
|
|
|
# Save Kimi config
|
|
cat > ~/.openclaw/config/kimi.yaml << EOF
|
|
provider: kimi
|
|
name: "Kimi K2.5"
|
|
auth:
|
|
type: api_key
|
|
key: "$KIMI_KEY"
|
|
models:
|
|
primary:
|
|
id: "k2p5"
|
|
max_tokens: 128000
|
|
fallback:
|
|
id: "k1.5"
|
|
max_tokens: 64000
|
|
routing:
|
|
priority: 1
|
|
EOF
|
|
|
|
# Save Antigravity config
|
|
cat > ~/.openclaw/config/antigravity.yaml << EOF
|
|
provider: antigravity
|
|
name: "Antigravity"
|
|
auth:
|
|
type: api_key
|
|
key: "$ANTIGRAVITY_KEY"
|
|
models:
|
|
primary:
|
|
id: "mixtral-8x7b"
|
|
max_tokens: 32000
|
|
secondary:
|
|
id: "qwen2.5-coder"
|
|
max_tokens: 32000
|
|
routing:
|
|
priority: 2
|
|
EOF
|
|
|
|
# Set permissions
|
|
chmod 600 ~/.openclaw/config/*.yaml
|
|
|
|
echo ""
|
|
echo "✅ API Keys configured!"
|
|
echo ""
|
|
echo "Test with: openclaw models list"
|
|
echo ""
|
|
EOFSCRIPT
|
|
chmod +x ~/scripts/configure_api_keys.sh
|
|
|
|
# ============================================
|
|
# BASH ALIASES
|
|
# ============================================
|
|
log "📝 Creating bash aliases..."
|
|
|
|
cat >> ~/.bashrc << 'EOF'
|
|
|
|
# DevMatrix Aliases
|
|
alias devmatrix-status='~/scripts/vm_control.sh win-status'
|
|
alias devmatrix-win-start='~/scripts/vm_control.sh win-start'
|
|
alias devmatrix-win-stop='~/scripts/vm_control.sh win-stop'
|
|
alias devmatrix-config='~/scripts/configure_api_keys.sh'
|
|
alias oc='openclaw'
|
|
alias ocs='openclaw sessions'
|
|
alias ocm='openclaw models'
|
|
|
|
# Development aliases
|
|
alias serve='python3 -m http.server'
|
|
alias myip='curl -s ipinfo.io/ip'
|
|
alias ports='sudo netstat -tulanp'
|
|
|
|
# Add paths
|
|
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.openclaw/bin:$PATH"
|
|
export OPENCLAW_WORKSPACE="$HOME/.openclaw/workspaces/devmatrix"
|
|
|
|
# Welcome message
|
|
if command -v figlet &> /dev/null; then
|
|
echo ""
|
|
figlet -f slant "DevMatrix" 2>/dev/null || echo "DevMatrix"
|
|
fi
|
|
echo ""
|
|
echo "🦞 OpenClaw DevMatrix Environment"
|
|
echo "================================"
|
|
echo "📂 Projects: ~/projects"
|
|
echo "📝 VS Code: http://$(hostname -I | awk '{print $1}'):8080"
|
|
echo "🐳 Docker: $(docker --version 2>/dev/null | cut -d' ' -f3 | tr -d ',')"
|
|
echo "🎯 Flutter: $(flutter --version 2>/dev/null | head -1)"
|
|
echo "🔷 .NET: $(dotnet --version 2>/dev/null)"
|
|
echo ""
|
|
echo "Next: Run '~/scripts/configure_api_keys.sh' to add your API keys"
|
|
echo ""
|
|
EOF
|
|
|
|
# ============================================
|
|
# SUMMARY
|
|
# ============================================
|
|
log "🎉 DevMatrix Environment Setup Complete!"
|
|
echo ""
|
|
echo "╔════════════════════════════════════════════════════════════╗"
|
|
echo "║ SETUP COMPLETE ║"
|
|
echo "╠════════════════════════════════════════════════════════════╣"
|
|
echo "║ ║"
|
|
echo "║ 🦞 OpenClaw: Installed at ~/.openclaw ║"
|
|
echo "║ 📱 Flutter: Installed (snap) ║"
|
|
echo "║ 🔷 .NET 8: Installed ║"
|
|
echo "║ 🐳 Docker: Installed and running ║"
|
|
echo "║ 🗄️ PostgreSQL: Installed and running ║"
|
|
echo "║ 📊 Redis: Installed and running ║"
|
|
echo "║ 📝 VS Code: http://$(hostname -I | awk '{print $1}'):8080 ║"
|
|
echo "║ ║"
|
|
echo "╠════════════════════════════════════════════════════════════╣"
|
|
echo "║ NEXT STEP: Run '~/scripts/configure_api_keys.sh' ║"
|
|
echo "║ to add your Kimi and Antigravity API keys ║"
|
|
echo "╚════════════════════════════════════════════════════════════╝"
|
|
echo ""
|