Mac / Linux Script
The mac-deploy.sh script is a comprehensive deployment tool for setting up router monitoring on OpenWrt routers from macOS/Linux systems. It deploys monitoring scripts and automatically registers the router in the database.
Overview
The Mac Deploy script provides:
- SSH-based deployment with connection multiplexing
- HTTP server for file transfer (temporary Python server)
- Comprehensive testing of all deployed scripts
- Crontab installation for automated monitoring
- Error handling and cleanup
Prerequisites
See Prerequisites for complete setup requirements.
Usage
Basic Usage
# Deploy to router with IP address
./mac-deploy.sh -h 192.168.1.1
# Deploy with custom username
./mac-deploy.sh -h 192.168.1.1 -u admin
# Deploy with SSH key
./mac-deploy.sh -h 192.168.1.1 -u admin -k ~/.ssh/id_rsa
Advanced Usage
# Use custom SSH port
./mac-deploy.sh -h 192.168.1.1 -p 2222
# Combine multiple options
./mac-deploy.sh -h router.example.com -u admin -k ~/.ssh/id_rsa -p 22
Environment Variables
You can also use environment variables instead of command-line options:
export ROUTER_HOST="192.168.1.1"
export ROUTER_USER="admin"
export SSH_KEY="~/.ssh/id_rsa"
./mac-deploy.sh
Command Line Options
| Option | Description | Required | Default |
|---|---|---|---|
-h, --host HOST | Router hostname or IP address | Yes | - |
-u, --user USER | SSH username | No | Prompted |
-p, --port PORT | SSH port | No | 22 |
-k, --key KEY_PATH | Path to SSH private key | No | - |
--help | Show help message | No | - |
Router Detection
The script automatically detects the router's IMEI and configures it for monitoring. All routers use the same standard monitoring scripts regardless of SIM slot configuration.
Deployment Process
The script follows these steps:
- Validation: Checks required parameters and router connectivity
- SSH Setup: Establishes multiplexed SSH connection
- HTTP Server: Starts temporary Python HTTP server on port 8000
- File Transfer: Downloads scripts to router via HTTP
- Configuration: Sets up Supabase configuration
- Crontab: Installs crontab for scheduled monitoring
- Database Registration: Automatically registers router in router_versions table
- Testing: Runs
/root/scripts/test_deployment.shto test all deployed scripts - Cleanup: Stops HTTP server and cleans up connections
Deployed Scripts
The Mac Deploy script installs comprehensive monitoring scripts to /root/scripts/ on the router.
View Complete Scripts Reference →
Automatic Router Registration
NEW: The deployment script automatically registers your router in the router_versions database table.
What Happens During Registration
When you run the deployment script, it will:
- Detect Router IMEI: Automatically runs
detect_router_identity.shto get the router's IMEI - Register in Database: Creates an entry in the
router_versionstable via Supabase API - Set Initial Status: Configures the router with:
current_version: unknownupdate_status: pendingtarget_version: null(set later via web interface)
Benefits
- No Manual Steps Required: Router is immediately visible in the web interface
- Ready for Updates: Set target version via web UI to start update process
- Automatic Detection: IMEI is automatically detected and registered
Registration Details
The registration process:
- Uses IMEI from
/etc/router_imeion the router - Loads Supabase credentials from local
files/supabase_config.env - Creates database entry if IMEI doesn't exist
- Updates existing entry if IMEI already registered (re-deployment scenario)
Verify Registration
After deployment, the router is automatically registered in the database. You can:
- Check the web interface at
/routersto see your router - The router will appear with status "unknown" and is ready for target version to be set by an administrator
- Monitor router activity through the web dashboard
Crontab Schedule
The script automatically installs crontab for scheduled monitoring tasks:
View Complete Crontab Schedules →
Troubleshooting
Common Issues
SSH Connection Failed
# Check SSH connectivity
ssh -p 22 [email protected]
# Verify SSH key permissions
chmod 600 ~/.ssh/id_rsa
Port 8000 Already in Use
# Find process using port 8000
lsof -i :8000
# Kill the process
kill -9 <PID>
Script Testing Failed
- Check Supabase configuration in
supabase_config.env - Verify router has internet connectivity
- Check router logs:
logread | grep scripts
Debug Mode
For verbose output, you can modify the script to add debug logging:
# Add to the beginning of mac-deploy.sh
set -x # Enable debug mode
Security Considerations
- SSH Keys: Use SSH key authentication instead of passwords
- Network: Deploy over secure networks only
- Firewall: Ensure router firewall allows SSH access
- Updates: The auto-update script downloads from secure update servers
Examples
Deploy to Local Router
./mac-deploy.sh -h 192.168.1.1 -u root
Deploy to Remote Router
./mac-deploy.sh -h router.company.com -u admin -k ~/.ssh/company_key
Deploy with Custom Port
./mac-deploy.sh -h 10.0.0.1 -u admin -p 2222 -k ~/.ssh/id_rsa
Batch Deployment
# Deploy to multiple routers
for router in 192.168.1.1 192.168.1.2 192.168.1.3; do
echo "Deploying to $router..."
./mac-deploy.sh -h $router -u admin -k ~/.ssh/id_rsa
done
Output
The script provides colored output for easy monitoring:
- 🔵 [INFO]: General information
- 🟢 [SUCCESS]: Successful operations
- 🟡 [WARNING]: Warnings (non-critical issues)
- 🔴 [ERROR]: Errors (critical failures)
Next Steps
After successful deployment:
- Verify Monitoring: Check the router dashboard for data
- Monitor Logs: Watch
/var/log/auto-update.logfor updates - Re-run Tests: Execute
/root/scripts/test_deployment.shon the router if needed - Update Configuration: Modify
supabase_config.envif needed