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_configtable stores all available versions with download URLs and checksumsrouter_versionstable 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:
- 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:
- Environment Configuration: Create a
version-manager.envfile:
# Copy the example file
cp version-manager.env.example version-manager.env
# Edit with your actual values
nano version-manager.env
-
Scripts Directory: The script looks for scripts in
files/scripts/directory (which is the correct structure) -
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:
- Build Update Package: Creates
router-scripts-VERSION.tar.gz - Generate Checksum: Creates SHA256 checksum file
- Upload to VPS: Uploads files to your update server (if configured)
- Update Supabase: Creates entry in
update_configtable
# 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_URLandSUPABASE_API_KEYinversion-manager.env - Ensure your Supabase project has the
update_configtable 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
- Check for updates - Query Supabase for
target_version - Download package - Get update from update server
- Verify integrity - Check SHA256 checksum
- Install update - Extract and install new scripts (no backup is created)
- Test installation - Run critical scripts to verify they work
- 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.logand 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
- Check update logs:
tail -f /var/log/auto-update.log - Verify network connectivity:
ping 8.8.8.8 - Check current version:
cat /root/scripts/version.txt - Test Supabase connection:
curl -s "$SUPABASE_BASE_URL/rest/v1/update_config?limit=1" -H "apikey: $SUPABASE_API_KEY" - Check if router needs to be registered (contact administrator)
Update Fails
- Check update logs for specific error:
grep ERROR /var/log/auto-update.log - Verify download URL is accessible
- Check router has enough disk space:
df -h - Review script permissions:
ls -la /root/scripts/
How Auto-Update Works
From Router's Perspective
- Administrator sets target version via web interface
- Router checks every 2 hours for updates
- Router downloads and installs new version if available
- 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
- Router connects to Supabase and checks for target version
- If update needed, downloads package from update server
- Verifies SHA256 checksum of downloaded file
- Extracts and installs new scripts
- Tests critical scripts (detect_router_identity, push_devices)
- Reports success or failure back to database