Last active
August 29, 2015 14:13
-
-
Save freyes/6f8234718faa359fa8f2 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# | |
# Simple wrapper for sshuttle :) | |
# | |
# Felipe Reyes <freyes@tty.cl> | |
# | |
PIDFILE=$HOME/.fake-vpn.pid | |
if [ ! -n "$FAKEVPN_HOST" ]; then | |
echo "Please define FAKEVPN_HOST environment variable" | |
exit 1 | |
fi | |
if [ ! -n "$FAKEVPN_NETS" ]; then | |
echo "Please define FAKEVPN_NETS environment variable" | |
exit 1 | |
fi | |
function log_msg { | |
echo "$1" | |
} | |
if [ "x$1" == "xstop" ]; then | |
kill $(cat $PIDFILE) 2>/dev/null | |
sleep 1 | |
kill -0 $(cat $PIDFILE) 2>/dev/null | |
if [ $? -ne 0 ]; then | |
log_msg "stopped" | |
exit 0 | |
fi | |
exit 1 | |
fi | |
if [ -e $PIDFILE ]; then | |
kill -0 $(cat $PIDFILE) 2>/dev/null | |
if [ $? -eq 0 ]; then | |
log_msg "fakevpn is already running" | |
exit 0 | |
else | |
rm $PIDFILE | |
fi | |
fi | |
sshuttle -r $FAKEVPN_HOST $FAKEVPN_NETS & | |
echo $! > $PIDFILE | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment