diff --git a/Documents/train-wifi.sh b/Documents/train-wifi.sh index b19bf6a15aa883fe9c241db4529dde6c5c285abb..a9a328728cce1e125fc711671b67b6a51e99d748 100755 --- a/Documents/train-wifi.sh +++ b/Documents/train-wifi.sh @@ -1,8 +1,7 @@ #!/bin/sh -set -eu # The MIT License (MIT) # -# Copyright (c) 2016 Adar Nimrod <nimrod@shore.co.il> +# Copyright (c) 2017 Adar Nimrod <nimrod@shore.co.il> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -27,15 +26,13 @@ set -eu # To install run: # sudo cp --preserve=mode train-wifi.sh /etc/NetworkManager/dispatcher.d/90trainwifi +set -eu + die () { - echo $@ | logger + logger -p user.err $@ exit 1 } -debug () { - [ -n ${DEBUG:+x} ] && echo $@ | logger -} - if [ $# -ne 2 ] then echo "Usage: $0 interface action" @@ -52,13 +49,13 @@ which logger > /dev/null || dir "Can't login to the train wifi, logger is not in if [ "$interface" = "ISRAEL-RAILWAYS" ] && [ "$action" = "up" ] then redirect_url="$(curl --output /dev/null --silent --write-out '%{redirect_url}' http://google.com/)" - debug "Train wifi redirect url: $redirect_url" + logger -p user.debug "Train wifi redirect url: $redirect_url" login_ip="$(echo "$redirect_url" | grep --only-matching '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')" - debug "Train wifi login IP: $ip" + logger -p user.debug "Train wifi login IP: $ip" login_url="http://$ip/loginHandler.php?allowAccess=true" - debug "Train wifi login URL: $login_url" + logger -p user.debug "Train wifi login URL: $login_url" http_code="$(curl --output /dev/null --silent --write-out '%{http_code}' "$login_url")" - debug "Train wifi login HTTP code: $http_code" + logger -p user.debug "Train wifi login HTTP code: $http_code" else - debug "Interface isn't ISRAEL-RAILWAYS or action isn't up, not signing in to the train wifi." + logger -p user.debug "Interface isn't ISRAEL-RAILWAYS or action isn't up, not signing in to the train wifi." fi