Skip to content

Instantly share code, notes, and snippets.

@rchrd2
Last active April 5, 2018 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rchrd2/720337417549dd34546c0ed6d6f821cf to your computer and use it in GitHub Desktop.
Save rchrd2/720337417549dd34546c0ed6d6f821cf to your computer and use it in GitHub Desktop.
BitBar + sshuttle
#!/bin/bash
#
# Easily start/stop sshuttle
#
# <bitbar.title>sshuttle</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>richard@archive.org</bitbar.author>
# <bitbar.author.github>rchrd2</bitbar.author.github>
# <bitbar.desc>Easily start/stop a background shhuttle.</bitbar.desc>
# <bitbar.image></bitbar.image>
#
SSHUTTLE_CMD="/usr/local/bin/sshuttle -r `whoami`@host 0.0.0.0/0"
SHUTTLE_KILL_CMD="/usr/bin/pkill -f '$SSHUTTLE_CMD'"
DEBUG="false"
case "$1" in
connect)
echo "$1"
echo $SSHUTTLE_CMD
if pgrep -qf "$SSHUTTLE_CMD"; then
echo "already connected"
else
/usr/bin/osascript -e "do shell script \"nohup -- $SSHUTTLE_CMD > /dev/null 2>&1 &\" with administrator privileges"
echo "Waiting. "
until pgrep -qf "$SSHUTTLE_CMD"; do echo "." && sleep 1; done
echo "Done!"
sleep 1
fi
;;
disconnect)
echo "$1"
echo $SHUTTLE_KILL_CMD
/usr/bin/osascript -e "do shell script \"$SHUTTLE_KILL_CMD\" with administrator privileges"
until ! pgrep -qf "$SSHUTTLE_CMD"; do sleep 1; done
;;
esac
if pgrep -qf "$SSHUTTLE_CMD"; then
echo "sshuttle :green_apple:"
else
echo "shhuttle :x:"
fi
echo "---"
if pgrep -qf "$SSHUTTLE_CMD"; then
echo "Connected"
echo `pgrep -f "$SSHUTTLE_CMD" | head -1 | xargs ps -o etime -p`
echo "Disconnect | color=indianred bash=$0 param1=disconnect terminal=$DEBUG refresh=true"
else
echo "Not connected"
echo "Connect | bash='$0' param1=connect terminal=$DEBUG refresh=true"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment