Last active
September 3, 2015 13:44
-
-
Save chew-z/e1799b20ef6d70a3520d to your computer and use it in GitHub Desktop.
Script starting/stoping/restaring tor service
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 zsh | |
| # idea came from here: | |
| # http://blog.felipe-alfaro.com/2015/03/05/tor-with-brew-in-mac-os-x/ | |
| # and some ideas from here: | |
| # https://kremalicious.com/simple-tor-setup-on-mac-os-x/ | |
| # setting up Sleepwatcher best described here: | |
| # https://www.kodiakskorner.com/log/258 | |
| function usage() { | |
| echo "usage: $0 start|stop|restart|check"; | |
| exit 1; | |
| } | |
| function tor_service() { | |
| launchctl $1 /usr/local/opt/tor/homebrew.mxcl.tor.plist | |
| } | |
| function start() { | |
| echo "$0: starting tor service..."; | |
| # it keeps asking for password. Could be launched as Daemon (with root privileges) | |
| sudo networksetup -setsocksfirewallproxy $INTERFACE 127.0.0.1 9048 off | |
| sudo networksetup -setsocksfirewallproxystate $INTERFACE on | |
| tor_service load | |
| # merge tor restart action with Sleepwatcher wakeup script | |
| cat ~/.config/sleepwatcher/*.wakeup > ~/.config/sleepwatcher/wakeup | |
| } | |
| function stop() { | |
| echo "$0: stopping tor service..."; | |
| sudo networksetup -setsocksfirewallproxystate $INTERFACE off | |
| tor_service unload | |
| # null restarting tor from Sleepwatcher wakeup script | |
| cat ~/.config/sleepwatcher/one.wakeup > ~/.config/sleepwatcher/wakeup | |
| } | |
| function check() { | |
| echo "$0: checking if tor works..."; | |
| if torsocks curl -s https://check.torproject.org | grep -q 'Congratulations. This browser is configured to use Tor.'; then | |
| echo 'The tor service works'; | |
| else | |
| echo 'The tor service does NOT work'; | |
| fi | |
| } | |
| function restart() { | |
| echo "$0: restarting tor service..."; | |
| tor_service unload | |
| tor_service load | |
| } | |
| # 'Wi-Fi' or 'Ethernet' or 'Display Ethernet' | |
| INTERFACE=Wi-Fi | |
| case "$1" in | |
| help|--help|-h) | |
| usage;; | |
| start) | |
| start;; | |
| stop) | |
| stop;; | |
| check) | |
| check;; | |
| restart) | |
| restart;; | |
| *) | |
| echo "torservice: error: missing or unrecognized command-line argument"; | |
| usage;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment