Skip to main content

Mac Deploy Script

The mac-deploy.sh script is a comprehensive deployment tool for setting up router monitoring on OpenWrt routers from macOS/Linux systems. It automatically detects router type and deploys the appropriate monitoring scripts.

Overview

The Mac Deploy script provides:

  • Automatic router type detection (single SIM vs dual SIM)
  • 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

System Requirements

  • macOS or Linux system
  • Python 3 (for HTTP server)
  • SSH client
  • Network access to the router

Router Requirements

  • OpenWrt-based router
  • SSH access enabled
  • wget installed on router
  • at-cmd utility available (for SIM detection)

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

# Specify router type explicitly
./mac-deploy.sh -h 192.168.1.1 -t single

# 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 -t dual -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 ROUTER_TYPE="single"
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-
-t, --type TYPERouter type: auto, single, dualNoauto
--helpShow help messageNo-

Router Type Detection

The script can automatically detect router type or you can specify it manually:

Automatic Detection (-t auto)

  • Tests multiple AT ports (/dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2)
  • Counts working SIM ports
  • Dual SIM: More than 1 working port
  • Single SIM: 1 or fewer working ports

Manual Specification

  • -t single: Force single SIM router deployment
  • -t dual: Force dual SIM router deployment

Deployment Process

The script follows these steps:

  1. Validation: Checks required parameters and router connectivity
  2. Router Detection: Determines router type (single/dual SIM)
  3. SSH Setup: Establishes multiplexed SSH connection
  4. HTTP Server: Starts temporary Python HTTP server on port 8000
  5. File Transfer: Downloads scripts to router via HTTP
  6. Configuration: Sets up Supabase configuration
  7. Crontab: Installs appropriate crontab for scheduled monitoring
  8. Testing: Tests all deployed scripts
  9. Cleanup: Stops HTTP server and cleans up connections

Deployed Scripts

The following scripts are deployed to /root/scripts/ on the router:

Core Scripts

  • detect_router_identity.sh - Router identification and caching
  • auto-update.sh - Automatic script updates

Monitoring Scripts

  • push_devices.sh - Device list monitoring (dual SIM)
  • push_devices_single_sim.sh - Device list monitoring (single SIM)
  • push_dhcp.sh - DHCP lease monitoring
  • push_signal_strength.sh - Signal strength monitoring
  • push_sim_slot.sh - SIM slot information

Configuration Files

  • supabase_config.env - Supabase connection configuration
  • crontab or crontab-single-sim - Scheduled task configuration

Crontab Schedule

Dual SIM Routers (crontab)

# Run DHCP list push every 15 minutes
*/15 * * * * /root/scripts/push_dhcp.sh

# Run signal strength push every 15 minutes
*/15 * * * * /root/scripts/push_signal_strength.sh

# Run connected devices every 5 minutes
*/5 * * * * /root/scripts/push_devices.sh

# Run SIM slot info push every 15 minutes
*/15 * * * * /root/scripts/push_sim_slot.sh

# Check for updates every 2 hours
0 */2 * * * /root/scripts/auto-update.sh >> /var/log/auto-update.log 2>&1

Single SIM Routers (crontab-single-sim)

# Run DHCP list push every 15 minutes
*/15 * * * * /root/scripts/push_dhcp.sh

# Run signal strength push every 15 minutes
*/15 * * * * /root/scripts/push_signal_strength.sh

# Run connected devices every 5 minutes (single SIM version)
*/5 * * * * /root/scripts/push_devices_single_sim.sh

# Run SIM slot info push every 15 minutes
*/15 * * * * /root/scripts/push_sim_slot.sh

# Check for updates every 2 hours
0 */2 * * * /root/scripts/auto-update.sh >> /var/log/auto-update.log 2>&1

Troubleshooting

Common Issues

SSH Connection Failed

# Check SSH connectivity
ssh -p 22 admin@192.168.1.1

# 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>

Router Type Detection Failed

# Force specific router type
./mac-deploy.sh -h 192.168.1.1 -t single

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 GitHub - verify URLs

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 -t dual

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. Test Scripts: Run individual scripts manually if needed
  4. Update Configuration: Modify supabase_config.env if needed