Skip to main content

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

OptionDescriptionRequiredDefault
-h, --host HOSTRouter hostname or IP addressYes-
-u, --user USERSSH usernameNoPrompted
-p, --port PORTSSH portNo22
-k, --key KEY_PATHPath to SSH private keyNo-
--helpShow help messageNo-

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:

  1. Validation: Checks required parameters and router connectivity
  2. SSH Setup: Establishes multiplexed SSH connection
  3. HTTP Server: Starts temporary Python HTTP server on port 8000
  4. File Transfer: Downloads scripts to router via HTTP
  5. Configuration: Sets up Supabase configuration
  6. Crontab: Installs crontab for scheduled monitoring
  7. Database Registration: Automatically registers router in router_versions table
  8. Testing: Runs /root/scripts/test_deployment.sh to test all deployed scripts
  9. 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:

  1. Detect Router IMEI: Automatically runs detect_router_identity.sh to get the router's IMEI
  2. Register in Database: Creates an entry in the router_versions table via Supabase API
  3. Set Initial Status: Configures the router with:
    • current_version: unknown
    • update_status: pending
    • target_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_imei on 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:

  1. Check the web interface at /routers to see your router
  2. The router will appear with status "unknown" and is ready for target version to be set by an administrator
  3. 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:

  1. Verify Monitoring: Check the router dashboard for data
  2. Monitor Logs: Watch /var/log/auto-update.log for updates
  3. Re-run Tests: Execute /root/scripts/test_deployment.sh on the router if needed
  4. Update Configuration: Modify supabase_config.env if needed