Skip to main content

Auto-Update System

The router auto-update system provides secure, automated firmware updates for routers in the field. It supports individual router targeting with comprehensive monitoring and rollback capabilities.

How It Works

Centralized Version Management

The system uses a centralized approach where:

  • update_config table stores all available versions with download URLs and checksums
  • router_versions table tracks each router's current and target versions
  • Individual targeting allows setting different versions for different routers

Update Flow

graph TD
A[Create Version] --> B[Upload to VPS]
B --> C[Create Supabase Entry]
C --> D[Manual Router Targeting]
D --> E[Router Checks Every 2h]
E --> F{Update Needed?}
F -->|Yes| G[Download & Install]
F -->|No| H[Wait 2h]
G --> I[Test & Report]
I --> J[Success/Failure]
H --> E
J --> E

Version Sources

The system downloads updates from:

  1. Your VPS server (https://updates.comlink.co.za) - Primary and only source

Local Version Management

Version Manager Script

The version-manager.sh script is executed locally on your development machine to create new router script versions:

Prerequisites

Before using the version-manager script, ensure you have:

  1. Environment Configuration: Create a version-manager.env file:
# Copy the example file
cp version-manager.env.example version-manager.env

# Edit with your actual values
nano version-manager.env
  1. Scripts Directory: The script looks for scripts in files/scripts/ directory (which is the correct structure)

  2. Make Script Executable:

chmod +x version-manager.sh

Available Commands

Show Usage:

./version-manager.sh [invalid-command]
# Shows help and available commands

List All Versions:

./version-manager.sh list
# Lists all versions from Supabase

Create New Version:

./version-manager.sh create VERSION [DESCRIPTION]
# Example: ./version-manager.sh create v2.1.0 "Fixed DHCP parsing bug"

Create New Version Process

When you run the create command, the script will:

  1. Build Update Package: Creates router-scripts-VERSION.tar.gz
  2. Generate Checksum: Creates SHA256 checksum file
  3. Upload to VPS: Uploads files to your update server (if configured)
  4. Update Supabase: Creates entry in update_config table
# Create version v2.1.0
./version-manager.sh create v2.1.0 "Fixed DHCP parsing bug"

# This will:
# - Build router-scripts-v2.1.0.tar.gz
# - Upload to your VPS server
# - Create Supabase entry in update_config table

Testing the Script

Basic Test (without full configuration):

# Test if script is executable and shows usage
./version-manager.sh list
# Should show: [INFO] Listing all versions

Full Test (with configuration):

# Test creating a version
./version-manager.sh create v1.0.0 "Test version"
# Should create releases/v1.0.0/ directory with package files

Troubleshooting

"Scripts directory not found" Error:

  • Ensure you're running the script from the router-files/ directory
  • Verify that files/scripts/ directory exists with all the router scripts

"Permission denied" Error:

# Solution: Make script executable
chmod +x version-manager.sh

Empty Supabase Response:

  • Check your SUPABASE_URL and SUPABASE_API_KEY in version-manager.env
  • Ensure your Supabase project has the update_config table created

Router Targeting

Version targeting is managed through the web interface by administrators. Routers automatically check for updates and install them based on target versions set in the system.

Environment Configuration

Create a version-manager.env file:

# Supabase Configuration
SUPABASE_URL="https://your-project.supabase.co"
SUPABASE_API_KEY="your-supabase-anon-key"

# Update Server Configuration
UPDATE_SERVER_URL="https://updates.comlink.co.za"

# VPS Configuration
VPS_HOST="138.68.81.211"
VPS_USER="root"
VPS_UPLOAD_PATH="/var/www/router-updates"

Router-Side Auto-Update

Automatic Updates

Routers automatically check for updates every 2 hours via the auto-update.sh script:

Update Process

  1. Check for updates - Query Supabase for target_version
  2. Download package - Get update from update server
  3. Verify integrity - Check SHA256 checksum
  4. Install update - Extract and install new scripts (no backup is created)
  5. Test installation - Run critical scripts to verify they work
  6. Report status - Update Supabase with success/failure and current_version

Safety Features

  • Checksum verification for download integrity
  • Script testing after installation (detects failures)
  • Status tracking in Supabase (updating/success/failed)
  • Comprehensive logging to /var/log/auto-update.log and stderr

Manual Updates

For immediate updates or troubleshooting, the auto-update script can be run manually:

# On router: Check for updates and apply if available
/root/scripts/auto-update.sh

# View update logs
tail -f /var/log/auto-update.log

Update Status

The system tracks router update status automatically:

  • pending → Ready to update (target version set by administrator)
  • updating → Update in progress (download/install/test)
  • success → Update completed successfully
  • failed → Update failed (check logs for details)

Security Features

API Key Authentication

  • Uses Supabase anon key from /root/supabase_config.env
  • Key is public but safe due to RLS policies
  • Secure communication with Supabase

Integrity Verification

  • SHA256 checksums for all downloads
  • Downloaded from https://updates.comlink.co.za/<version>/
  • Verification happens before installation

Update Safety

  • Test scripts after installation
  • Status tracking in Supabase
  • No automatic rollback - manual intervention required if failed

Monitoring and Troubleshooting

Check Update Logs

# On router: View update logs
tail -f /var/log/auto-update.log

# Check recent activity
grep "SUCCESS\|ERROR" /var/log/auto-update.log

# View router version
cat /root/scripts/version.txt

Common Issues

Router Not Updating

  1. Check update logs: tail -f /var/log/auto-update.log
  2. Verify network connectivity: ping 8.8.8.8
  3. Check current version: cat /root/scripts/version.txt
  4. Test Supabase connection: curl -s "$SUPABASE_BASE_URL/rest/v1/update_config?limit=1" -H "apikey: $SUPABASE_API_KEY"
  5. Check if router needs to be registered (contact administrator)

Update Fails

  1. Check update logs for specific error: grep ERROR /var/log/auto-update.log
  2. Verify download URL is accessible
  3. Check router has enough disk space: df -h
  4. Review script permissions: ls -la /root/scripts/

How Auto-Update Works

From Router's Perspective

  1. Administrator sets target version via web interface
  2. Router checks every 2 hours for updates
  3. Router downloads and installs new version if available
  4. Router reports status back to the system

Monitoring Your Router

You can monitor your router's update status:

# Check if update is needed
cat /var/log/auto-update.log | grep "target_version"

# View current version
cat /root/scripts/version.txt

# Check update activity
grep "SUCCESS\|ERROR" /var/log/auto-update.log

# Force immediate check
/root/scripts/auto-update.sh

What Happens During Update

  1. Router connects to Supabase and checks for target version
  2. If update needed, downloads package from update server
  3. Verifies SHA256 checksum of downloaded file
  4. Extracts and installs new scripts
  5. Tests critical scripts (detect_router_identity, push_devices)
  6. Reports success or failure back to database