Skip to content

Instantly share code, notes, and snippets.

@sergeyhush
Created July 28, 2016 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeyhush/adc9367603689fc9164f2984938b8035 to your computer and use it in GitHub Desktop.
Save sergeyhush/adc9367603689fc9164f2984938b8035 to your computer and use it in GitHub Desktop.
Cromebook OpenVPN connection script
#!/bin/sh -e
CONF_DIR=$1
CONFIG="$CONF_DIR/client.ovpn"
RESOLVE_CONF="$CONF_DIR/resolv.conf"
ORIG_RESOLVE_CONF="$CONF_DIR/resolv.conf.orig"
if [ ! -d "$CONF_DIR" ]; then
echo "Could not find config dir $CONF_DIR" >&2
exit 1
fi
if [ ! -f "$CONFIG" ]; then
echo "Could not find config file $CONFIG" >&2
exit 1
fi
if [ ! -f "$RESOLVE_CONF" ]; then
echo "Could not find config file $RESOLVE_CONF" >&2
exit 1
fi
trap '' 2
# Stop shill and restart it with a nicer attitude towards tun0
sudo stop shill
sudo start shill BLACKLISTED_DEVICES=tun0
# Sleep 10 seconds to allow chromebook to reconnect to the network
sudo sleep 10
sudo openvpn --mktun --dev tun0
sudo sleep 3
# Add DNS on top of current ones, since openvpn command does not do it
sudo cp /var/run/shill/resolv.conf $ORIG_RESOLVE_CONF
sudo mv $RESOLVE_CONF /var/run/shill/resolv.conf
# Lauch openvpn, finally...
sudo openvpn --config $CONFIG --dev tun0 --auth-retry interact
# When ctrl-c is hit remove tun0 and cleanup the DNS
sudo openvpn --rmtun --dev tun0
if [ -f "$ORIG_RESOLVE_CONF" ]; then
sudo mv $ORIG_RESOLVE_CONF /var/run/shill/resolv.conf
fi
trap 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment