Author: magespawn Language: text
Description: Auto Connect script for Ubuntu 12.04 Timestamp: 2012-10-20 02:55:37 -0400
View raw paste Reply
  1. #!/bin/sh
  2. # Mobile Broadband Autoconnect Service script v2.0 alpha by The Fan Club - May 2012
  3. # acts as startup service script for nmcli to autoconnect Mobile Broadband Connections
  4. # NOTE: use the name of the Mobile Connection in the Network Manager as the 'id'
  5. # USAGE: start|stop|status
  6. #
  7. ### BEGIN INIT INFO
  8. # Provides: mobile-broadband-connect
  9. # Required-Start: $remote_fs $syslog
  10. # Required-Stop: $remote_fs $syslog
  11. # Should-Start: $network
  12. # Should-Stop: $network
  13. # Default-Start: 3 4 5
  14. # Default-Stop: 0 1 6
  15. # Short-Description: Autoconnect 3G GSM
  16. ### END INIT INFO
  17.  
  18. NAME="mobile-broadband-connect"
  19. DESC="Autoconnect 3G/4G GSM USB modem at startup"
  20.  
  21. test -x $DAEMON || exit 0
  22.  
  23. case "$1" in
  24.         start)
  25.            echo "[MBC] *** Starting Mobile Broadband Connection."  
  26.            while true; do
  27.               # Waiting for GSM modem adaptor...
  28.           LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
  29.           if [ $? -eq 0 ]; then          
  30.                  # now gsm detected, run the script
  31.              echo "[MBC] GSM Modem Detected - attempting auto connect"
  32.                      nmcli -t con up id YourMobileBroadbandConnectionNameHere
  33.                  echo "[MBC] GSM Modem connecting ....."
  34.              # we want the script to loop forever and
  35.              # check if the connection is down
  36.              # but we need to give it a chance to connect or
  37.              # the modem will attempt to connect in an endless loop so we
  38.              # give a 30 second break to make sure it is not connected 
  39.                  echo "[MBC] Hopefully connected now... sleeping for 30sec"            
  40.                  sleep 30
  41.               else
  42.                  # GSM device not detected yet or GMS device already connected - sleep
  43.                  echo "[MBC] MBC still running - sleeping for 10....."
  44.                  sleep 10
  45.               fi
  46.        done
  47.         ;;
  48.         stop)
  49.        echo "[MBC] Stopping Mobile Broadband Connection."  
  50.        nmcli -t con down id YourMobileBroadbandConnectionNameHere
  51.        #nmcli -t nm wwan off
  52.         ;;
  53.         status)
  54.        # Check network status with nmcli
  55.        nmcli -p dev
  56.         ;;
  57.        
  58.         *)
  59.            echo "[MBC] Mobile Broadband Startup Service"
  60.        echo $"Usage: $0 {start|stop|status}"
  61.        exit 1
  62. esac
  63. exit 0
View raw paste Reply