#!/bin/bash
cd /root/firefrost-work/firefrost-operations-manual

# Add automation system section to migration plan
cat >> docs/dedis-to-vps-migration-plan.md << 'AUTOPLAN'

---

## CRITICAL: Automation System Migration

**OVERSIGHT IDENTIFIED:** The Firefrost Automation System currently runs on TX1!

### Current Automation Setup
- **Location:** `/root/firefrost-work/firefrost-operations-manual/automation/`
- **Daemon:** Running on TX1 (PID management)
- **Function:** Polls Git repo, executes tasks, commits results
- **Usage:** 95% reduction in manual operations

### Migration Decision Required

**Option 1: Keep Automation on TX1**
- Pros: Already working, no changes needed
- Cons: Requires TX1 SSH access for management work
- Use case: If TX1 remains partially management server

**Option 2: Move Automation to Command Center VPS**
- Pros: All management tools in one place
- Cons: Need to set up SSH keys, test thoroughly
- Use case: If going full VPS for management

**Option 3: Run Automation on BOTH**
- Pros: Redundancy, can manage either server
- Cons: Complexity, two daemons to monitor
- Use case: Hybrid approach

**Option 4: Eliminate Need for Automation on Dedis**
- Pros: VPS deployments are simpler (no dedi complexity)
- Cons: Lose automation benefits
- Reality check: VPS might not need automation as much

### Recommendation: Option 2 (Move to Command Center)

**Reasoning:**
- All management work happens on VPS tier
- Automation system designed for management services
- Keep TX1/NC1 as "appliances" (game servers only)
- Single management hub = cleaner architecture

### Automation Migration Steps

1. **Clone repo to Command Center VPS:**
```bash
cd /root
git clone https://git.firefrostgaming.com/firefrost-gaming/firefrost-operations-manual.git firefrost-work/firefrost-operations-manual
```

2. **Set up Git authentication:**
```bash
# SSH key or HTTPS token
git config --global user.name "Firefrost Automation"
git config --global user.email "automation@firefrostgaming.com"
```

3. **Start daemon on Command Center:**
```bash
cd ~/firefrost-work/firefrost-operations-manual
nohup bash automation/automation-daemon.sh > /dev/null 2>&1 &
echo "Daemon PID: $!"
```

4. **Test task execution:**
- Queue test task
- Verify execution
- Check Git commit

5. **Stop TX1 daemon:**
```bash
# On TX1
ps aux | grep automation-daemon
kill [PID]
```

6. **Update documentation:**
- USAGE.md updated with new location
- Session handoff updated

### Timeline

**When to migrate automation:**
- **After** Gitea migration (needs working Git repo)
- **Before** other services (to use automation for migrations)
- **Estimated time:** 30 minutes

### Automation in Migration Workflow

**Use automation for:**
- ✅ Backing up services
- ✅ Deploying to VPS
- ✅ Testing configurations
- ✅ Committing migration logs

**Don't use automation for:**
- ❌ Initial Git clone (chicken-egg problem)
- ❌ DNS changes (manual in Cloudflare)
- ❌ Critical rollbacks (need manual control)

---

## Updated Migration Phase Order

### Phase M0: Automation System Migration (NEW - FIRST!)
**Target:** Command Center VPS
**Duration:** 30 minutes
**Prerequisite:** Gitea migrated first

**Steps:**
1. Migrate Gitea to Command Center (Service 1)
2. Clone repo on Command Center
3. Configure Git authentication
4. Start automation daemon
5. Test with simple task
6. Stop TX1 daemon
7. Update documentation

**Why first:** Enables automation for remaining migrations!

### Phase M1-M6: Continue as planned
(All other services use automation system on Command Center)

---

**CRITICAL NOTE:** This is why good planning matters! Almost missed a key component.

**Fire + Frost = Where Passion Meets Precision** 🔥❄️
AUTOPLAN

# Commit update
git add docs/dedis-to-vps-migration-plan.md
git commit -m "Migration Plan: Added automation system migration (Phase M0)"
git push

echo "Automation migration section added!"
