SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2. # fail if any commands fails
  3. set -e
  4. # debug log
  5. set -x
  6.  
  7. # write your script here
  8. #!/bin/bash
  9. set -eu
  10.  
  11. case "$OSTYPE" in
  12. linux*)
  13.   echo "Configuring for Ubuntu"
  14.   echo "Configuring variables"
  15.   CLIENT_KEY=${ENV_CLIENT_KEY}
  16.   CA_CRT=${ENV_CA_CRT}
  17.   CLIENT_CRT=${ENV_CLIENT_CRT}
  18.   ROUTE_IPS=${ENV_ROUTE_IPS}
  19.   HOST=${ENV_VPN_HOST}
  20.   PORT=${ENV_VPN_PORT}
  21.  
  22.   sudo apt-get update
  23.   sudo apt-get install -y openvpn net-tools
  24.   cat <<EOF > /tmp/client.conf
  25. remote ${HOST}
  26. port ${PORT}
  27. proto tcp
  28. dev tap
  29. client
  30. ca ca.crt
  31. cert client.crt
  32. key client.key
  33. comp-lzo
  34. persist-key
  35. persist-tun
  36. verb 3
  37.  
  38. route ${ROUTE_IPS}
  39. EOF
  40.  
  41.   echo ${CA_CRT} | base64 -d > /tmp/ca.crt
  42.   echo ${CLIENT_CRT} | base64 -d > /tmp/client.crt
  43.   echo ${CLIENT_KEY} | base64 -d > /tmp/client.key
  44.  
  45.   cd /tmp
  46.   sudo openvpn client.conf > /dev/null 2>&1 &
  47.  
  48.     sleep 15
  49.  
  50.     if ifconfig | grep tap0 > /dev/null
  51.     then
  52.       echo "VPN connection succeeded"
  53.     else
  54.       echo "VPN connection failed!"
  55.       exit 1
  56.     fi
  57.     ;;
  58.   *)
  59.     echo "Unknown operative system: $OSTYPE, exiting"
  60.     exit 1
  61.     ;;
  62. esac
  63.  
  64. # or run a script from your repository, like:
  65. # bash ./path/to/script.sh
  66. # not just bash, e.g.:
  67. # ruby ./path/to/script.rb
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top