Skip to content

Instantly share code, notes, and snippets.

@hernandazevedo
Last active April 18, 2019 01:54
Show Gist options
  • Save hernandazevedo/08b77a0c5826fffa3a3a0717314ecccf to your computer and use it in GitHub Desktop.
Save hernandazevedo/08b77a0c5826fffa3a3a0717314ecccf to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
set -x
# write your script here
#!/bin/bash
set -eu
case "$OSTYPE" in
linux*)
echo "Configuring for Ubuntu"
echo "Configuring variables"
CLIENT_KEY=${ENV_CLIENT_KEY}
CA_CRT=${ENV_CA_CRT}
CLIENT_CRT=${ENV_CLIENT_CRT}
ROUTE_IPS=${ENV_ROUTE_IPS}
HOST=${ENV_VPN_HOST}
PORT=${ENV_VPN_PORT}
sudo apt-get update
sudo apt-get install -y openvpn net-tools
cat <<EOF > /tmp/client.conf
remote ${HOST}
port ${PORT}
proto tcp
dev tap
client
ca ca.crt
cert client.crt
key client.key
comp-lzo
persist-key
persist-tun
verb 3
route ${ROUTE_IPS}
EOF
echo ${CA_CRT} | base64 -d > /tmp/ca.crt
echo ${CLIENT_CRT} | base64 -d > /tmp/client.crt
echo ${CLIENT_KEY} | base64 -d > /tmp/client.key
cd /tmp
sudo openvpn client.conf > /dev/null 2>&1 &
sleep 15
if ifconfig | grep tap0 > /dev/null
then
echo "VPN connection succeeded"
else
echo "VPN connection failed!"
exit 1
fi
;;
*)
echo "Unknown operative system: $OSTYPE, exiting"
exit 1
;;
esac
# or run a script from your repository, like:
# bash ./path/to/script.sh
# not just bash, e.g.:
# ruby ./path/to/script.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment