Last active
January 8, 2019 19:22
-
-
Save mbierman/9d611af8a124076c0744a04f8f83489e to your computer and use it in GitHub Desktop.
Reboot Arris modem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Configure/Initialize | |
| # Configure/Initialize | |
| # read sensitive data from local files. Example: | |
| # KEY=value | |
| BASEDIR=$(dirname "$0") | |
| APIKEY="$(cat $BASEDIR/arrisdata.txt | grep API | cut -f2 -d "=" )" | |
| USER="$(cat $BASEDIR/arrisdata.txt | grep USER | cut -f2 -d "=" )" | |
| PASS="$(cat $BASEDIR/arrisdata.txt | grep PASS | cut -f2 -d "=" )" | |
| tries=1 | |
| SECONDS=0 | |
| run="null" | |
| begin=`date +%s` | |
| dur=59 | |
| permlog=/tmp/com.arrisreboot.log | |
| nodns="FALSE" | |
| showme="FALSE" | |
| silent="FALSE" | |
| dryrun="FALSE" | |
| skipNPR="FALSE" | |
| for i in "$@" ; do | |
| if [ "$i" = "silent" ]; then | |
| silent="TRUE" | |
| elif [ "$i" = "nodns" ]; then | |
| nodns="TRUE" | |
| elif [ "$i" = "showme" ]; then | |
| showme="TRUE" | |
| elif [ "$i" = "dryrun" ]; then | |
| dryrun="TRUE" | |
| elif [ "$i" = skipNPR ]; then | |
| skipNPR="TRUE" | |
| else | |
| echo -e "\nValid options are: \n * nodns (do not sleep)\n * showme (open web page)\n * dryrun (don't actually reboot modem)\n * silent (don't push notification)\n* skipNPR (don't run getNPR )" | |
| exit | |
| fi | |
| done | |
| echo dryrun is:$dryrun | |
| function convertsecs() { | |
| ((h=${runtime}/3600)) | |
| ((m=(${runtime}%3600)/60)) | |
| ((s=${runtime}%60)) | |
| printf "%02d:%02d:%02d\n" $h $m $s | |
| } | |
| function ready() { | |
| while [ "$test" != "$1" ] | |
| do | |
| if [ "$1" = "DOCTYPE" ]; then | |
| echo "$1" | |
| test=$(curl http://192.168.0.1 | grep -aho 'DOCTYPE') | |
| elif [ "$1" = "HTTP/2" ]; then | |
| test=$(curl --connect-timeout 5000 -I https://cnn.com | grep -ho 'HTTP/2') | |
| else | |
| echo uh oh. | |
| exit | |
| fi | |
| ((tries+=1)) | |
| if [ "$test" != "$1" ]; then | |
| sleep 20 | |
| fi | |
| done | |
| echo "starting Ready" | |
| if [ "$nodns" != "TRUE" ]; then | |
| pmset -a displaysleep 10 disksleep 10 sleep 15 womp 1 | |
| else | |
| echo no sleep | |
| fi | |
| } | |
| # Begin MAIN | |
| ready "DOCTYPE" | |
| if [ "$dryrun" != "TRUE" ]; then | |
| echo "working..." | |
| curl --user $USER:$PASS -d "loginChallenge=o8F9kmPmC75wzc2H3bWCO3Fxi3dYKGFb&loginUsername=michaelb&loginPassword=eAevjIfUq6okHYC7RReq" -H "Content-Type: text/html" -v http://192.168.0.1/goform/login & -v http://192.168.0.1/goform/RgConfiguration.pl -d "GetNonce=R0T5QUiNN1hPNqjHKtqNsHEFnuIoUIi&EEE=0&Rebooting=1" -X POST -H "Content-Type: text/html" -H "content-length: 58" | |
| sleep 30 | |
| else | |
| echo "DryRun..." | |
| fi | |
| if [ "$nodns" = "FALSE" ]; then | |
| sudo ifconfig en0 down | |
| sudo ifconfig en1 down | |
| sleep 10 | |
| dscacheutil -flushcache;sudo killall -HUP mDNSResponder;echo DNS cleared. | |
| sleep 30 | |
| sudo ifconfig en0 up | |
| sudo ifconfig en1 up | |
| else | |
| echo "No sleep for you..." | |
| fi | |
| #Test LAN | |
| echo "LAN up?" | |
| ready "DOCTYPE" | |
| #Test WAN | |
| echo "WAN up?" | |
| ready "HTTP/2" | |
| # we're done! | |
| end=`date +%s` | |
| runtime=$((end-begin)) | |
| runtime=$(convertsecs $runtime) | |
| ts=$(date +"%m/%d @%H:%M") | |
| if [ $tries -eq 1 ]; then | |
| output=">>> Completed in $runtime (${tries} try) <<<" | |
| else | |
| output=">>> Completed in $runtime ($tries tries) <<<" | |
| fi | |
| echo output is: "$output" | |
| sleep 10 | |
| if [ "$silent" = "FALSE" ]; then | |
| curl https://api.pushbullet.com/api/pushes -u $APIKEY -d type=note -d title="Arris restarted $ts, tries: $tries ($runtime)" -d body="restarted at $(date) in $tries tries in $runtime" -X POST > /dev/null | |
| else | |
| echo "Shhh" | |
| fi | |
| echo "$output" | |
| echo "$output" >> $permlog | |
| if [ "skipNPR" = "FALSE" ]; then | |
| /Users/bierman/Documents/Applications/bin/getnpr.sh me f | |
| fi | |
| if [ "$nodns" = "FALSE" ]; then | |
| osascript -e 'tell app "System Events" to sleep' | |
| fi | |
| if [ $tries -eq 1 ];then | |
| output=">>> Completed in $runtime (${tries} try) <<<" | |
| else | |
| output=">>> Completed in $runtime ($tries tries) <<<" | |
| fi | |
| if [ "$nodns" = "FALSE" ]; then | |
| pmset -a displaysleep 10 disksleep 10 sleep 15 womp 1 | |
| # sleep 300 | |
| else | |
| echo "no sleep for you" | |
| fi | |
| echo "$output" | |
| echo "$output" >> $permlog | |
| if [ "$showme" = "TRUE" ]; then | |
| open http://192.160.0.1 | |
| fi | |
| # Check which are running | |
| # sudo launchctl unload /Library/LaunchDaemons/com.arrisreboot.plist; sleep 3; sudo launchctl unload /Library/LaunchDaemons/com.arrisreboot.plist; sudo launchctl load -w /Library/LaunchDaemons/com.arrisreboot.plist; sudo launchctl load -w /Library/LaunchDaemons/com.arrisreboot.plist | |
| # cp /Users/bierman/Documents/Applications/bin/arris.sh /Volumes/michael/bin; cp /Users/bierman/Documents/Applications/bin/arrisdata.txt /Volumes/michael/bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment