Newer
Older
copilot / BOOTSTRAP_README.md

๐Ÿš€ COPILOT CLI+ Complete Bootstrap Script

Complete automated setup of the entire Copilot CLI+ environment with DeepSeek integration.

๐Ÿ“‹ Overview

This script will rebuild the entire setup from scratch on any Ubuntu/Debian system.

Includes:

  • โœ… System dependencies
  • โœ… Python packages
  • โœ… API Server (FastAPI)
  • โœ… DeepSeek integration
  • โœ… MCP Server bridge
  • โœ… Systemd services
  • โœ… SSH configuration
  • โœ… Sudo safety rules
  • โœ… Full automated tests

๐Ÿš€ Quick Start

On Target System:

# Download bootstrap script
wget https://your-host.com/bootstrap.sh -O bootstrap.sh
chmod +x bootstrap.sh

# Run with DeepSeek API key
./bootstrap.sh "sk-your-deepseek-api-key-here"

# Optional flags
./bootstrap.sh "sk-..." --verbose        # Detailed output
./bootstrap.sh "sk-..." --skip-tests     # Skip integration tests

๐Ÿ“ฅ Restore from Backup

If you need to restore on a new system:

# 1. Copy bootstrap script
scp bootstrap.sh user@newhost:/tmp/

# 2. Run on new host
ssh user@newhost "cd /tmp && bash bootstrap.sh 'sk-your-key'"

# 3. Verify
ssh user@newhost "curl http://localhost:8888/health"

๐Ÿ”ง What Gets Installed

System-level:

  • python3, pip, curl, wget, git
  • ansible, sudo
  • openssh-server, openssh-client
  • systemd

Python packages:

  • fastapi, uvicorn, pydantic, requests

Local components:

  • /opt/local-agent/bin/api-server.py - REST API
  • /opt/local-agent/bin/deepseek-api.py - DeepSeek wrapper
  • /opt/local-agent/bin/mcp-server.py - Copilot CLI bridge
  • /opt/local-agent/config/ - Configuration files
  • Systemd services for automation

Services started:

  • local-agent-api (port 8888)
  • ollama (port 11434)
  • local-agent (daemon)
  • ssh (port 22)

โœ… Features

Safety:

  • โœ… Dangerous command blocking
  • โœ… Sudo restrictions
  • โœ… Command timeouts
  • โœ… Comprehensive logging

Integration:

  • โœ… DeepSeek API (Polish/English)
  • โœ… Shell command execution
  • โœ… Ansible automation
  • โœ… Service monitoring

Automation:

  • โœ… Automatic service restart
  • โœ… Health checks
  • โœ… Audit logging
  • โœ… Recovery scripts

๐Ÿ“Š API Endpoints (After Setup)

# Health check
curl http://localhost:8888/health

# Execute shell
curl -X POST http://localhost:8888/execute \
  -H "Content-Type: application/json" \
  -d '{"command":"whoami"}'

# Query DeepSeek
curl -X POST http://localhost:8888/deepseek \
  -H "Content-Type: application/json" \
  -d '{"query":"Czeล›ฤ‡!"}'

# Service status
curl http://localhost:8888/services

# API docs
curl http://localhost:8888/docs

๐Ÿ” API Key Management

The bootstrap script:

  1. Takes DeepSeek API key as argument
  2. Stores it securely in systemd service
  3. Never logs the key value
  4. Makes it available to API server

To rotate the key:

# Edit systemd service
sudo nano /etc/systemd/system/local-agent-api.service

# Update DEEPSEEK_API_KEY variable
# Then reload and restart
sudo systemctl daemon-reload
sudo systemctl restart local-agent-api

๐Ÿ“ Logs

After setup, check logs in:

tail -f /opt/local-agent/logs/api.log      # API activity
tail -f /opt/local-agent/logs/agent.log    # Command execution

๐Ÿงช Testing

Bootstrap automatically runs tests:

โœ“ API health check
โœ“ Services endpoint
โœ“ DeepSeek integration

To skip tests during bootstrap:

./bootstrap.sh "sk-..." --skip-tests

๐Ÿ†˜ Troubleshooting

Script fails with "Command not found"

  • Ensure running on Ubuntu/Debian
  • Check internet connection
  • May need root/sudo access

API not responding after setup

# Check service status
systemctl status local-agent-api

# Check logs
journalctl -u local-agent-api -f

# Restart
systemctl restart local-agent-api

DeepSeek queries fail

# Verify API key
echo $DEEPSEEK_API_KEY

# Check service environment
systemctl show local-agent-api -p Environment

# Test directly
python3 /opt/local-agent/bin/deepseek-api.py "Test"

MCP not connecting in Copilot CLI

# Verify MCP config exists
cat ~/.copilot/mcp-config.json

# Test MCP server manually
python3 /opt/local-agent/bin/mcp-server.py < /dev/null

# Restart Copilot CLI
copilot --restart

๐Ÿ”„ Disaster Recovery

If you lose the host, to fully restore:

  1. Get the bootstrap script

    # From backup/git
    git clone <your-backup> && cd repo
  2. Run on new system

    chmod +x bootstrap.sh
    ./bootstrap.sh "sk-your-api-key"
  3. Verify

    curl http://localhost:8888/health
    copilot
    /mcp
  4. (Optional) Copy custom playbooks

    scp user@oldhost:/opt/local-agent/config/playbook.yml \
        /opt/local-agent/config/

๐Ÿ“ฆ Backup Recommendations

To prepare for disaster recovery:

# 1. Backup bootstrap script
cp /opt/local-agent/bootstrap.sh ~/bootstrap-backup.sh

# 2. Backup custom configs
tar -czf ~/agent-config-backup.tar.gz /opt/local-agent/config/

# 3. Backup documentation
cp /opt/local-agent/*.md ~/agent-docs/

# 4. Store API key securely (NOT in repo)
echo "DEEPSEEK_API_KEY=sk-..." > ~/.deepseek-key-backup

# 5. Upload to secure location (git, S3, etc)

To restore from backup:

# 1. Extract bootstrap
cp bootstrap-backup.sh /tmp/ && chmod +x /tmp/bootstrap-backup.sh

# 2. Run bootstrap (API key from secure storage)
/tmp/bootstrap-backup.sh "$(cat ~/.deepseek-key-backup | grep -oP 'sk-.*')"

# 3. Restore custom configs
tar -xzf agent-config-backup.tar.gz -C /

# 4. Restart services
systemctl restart local-agent-api

๐ŸŽฏ Next Steps After Bootstrap

  1. Start Copilot CLI

    copilot
  2. Enable MCP integration

    /mcp

    Select: local-agent

  3. Test integration

    "Tell me what services are running"
    "Execute: whoami"
    "Ask DeepSeek: Czeล›ฤ‡!"
  4. Deploy custom automation

    # Edit playbook
    nano /opt/local-agent/config/playbook.yml
    
    # Use in Copilot
    "Deploy using Ansible"

๐Ÿ“ž Support

All configuration and logs in:

  • /opt/local-agent/ - Main agent directory
  • /opt/local-agent/logs/ - All activity logs
  • ~/.copilot/mcp-config.json - MCP configuration
  • /etc/systemd/system/local-agent*.service - Service configs

Check logs for detailed diagnostics:

journalctl -u local-agent-api -n 50
journalctl -u ollama -n 50
tail -50 /opt/local-agent/logs/*.log

Script Version: 1.0
Last Updated: 2026-03-25
Compatible: Ubuntu 20.04 LTS+, Debian 11+