From 59c7227587fcc8ac84cddbd991b4f3029d554a58 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Sat, 11 Jun 2016 15:36:43 -0500 Subject: [PATCH] Improve defining VPN variables --- vpnsetup.sh | 17 ++++++++++------- vpnsetup_centos.sh | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/vpnsetup.sh b/vpnsetup.sh index 76f9cf2..e8c973d 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -18,12 +18,13 @@ # =========================================================== # Define your own values for these variables +# - IPsec pre-shared key, VPN username and password # - All values MUST be placed inside 'single quotes' # - DO NOT use these characters within values: \ " ' -VPN_IPSEC_PSK=${VPN_IPSEC_PSK:-'your_ipsec_pre_shared_key'} -VPN_USER=${VPN_USER:-'your_vpn_username'} -VPN_PASSWORD=${VPN_PASSWORD:-'your_vpn_password'} +YOUR_IPSEC_PSK='' +YOUR_USERNAME='' +YOUR_PASSWORD='' # Important Notes: https://git.io/vpnnotes # Setup VPN Clients: https://git.io/vpnclients @@ -64,18 +65,20 @@ EOF exit 1 fi -[ "$VPN_IPSEC_PSK" = "your_ipsec_pre_shared_key" ] && VPN_IPSEC_PSK='' -[ "$VPN_USER" = "your_vpn_username" ] && VPN_USER='' -[ "$VPN_PASSWORD" = "your_vpn_password" ] && VPN_PASSWORD='' +[ -n "$YOUR_IPSEC_PSK" ] && VPN_IPSEC_PSK="$YOUR_IPSEC_PSK" +[ -n "$YOUR_USERNAME" ] && VPN_USER="$YOUR_USERNAME" +[ -n "$YOUR_PASSWORD" ] && VPN_PASSWORD="$YOUR_PASSWORD" if [ -z "$VPN_IPSEC_PSK" ] && [ -z "$VPN_USER" ] && [ -z "$VPN_PASSWORD" ]; then + echo "VPN credentials not set by user. Generating random PSK and password..." + echo VPN_IPSEC_PSK="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" VPN_USER=vpnuser VPN_PASSWORD="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" fi if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then - echoerr "VPN credentials must be specified. Edit the script and re-enter them." + echoerr "All VPN credentials must be specified. Edit the script and re-enter them." exit 1 fi diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index 3704164..b1d2e15 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -18,12 +18,13 @@ # =========================================================== # Define your own values for these variables +# - IPsec pre-shared key, VPN username and password # - All values MUST be placed inside 'single quotes' # - DO NOT use these characters within values: \ " ' -VPN_IPSEC_PSK=${VPN_IPSEC_PSK:-'your_ipsec_pre_shared_key'} -VPN_USER=${VPN_USER:-'your_vpn_username'} -VPN_PASSWORD=${VPN_PASSWORD:-'your_vpn_password'} +YOUR_IPSEC_PSK='' +YOUR_USERNAME='' +YOUR_PASSWORD='' # Important Notes: https://git.io/vpnnotes # Setup VPN Clients: https://git.io/vpnclients @@ -68,18 +69,20 @@ EOF exit 1 fi -[ "$VPN_IPSEC_PSK" = "your_ipsec_pre_shared_key" ] && VPN_IPSEC_PSK='' -[ "$VPN_USER" = "your_vpn_username" ] && VPN_USER='' -[ "$VPN_PASSWORD" = "your_vpn_password" ] && VPN_PASSWORD='' +[ -n "$YOUR_IPSEC_PSK" ] && VPN_IPSEC_PSK="$YOUR_IPSEC_PSK" +[ -n "$YOUR_USERNAME" ] && VPN_USER="$YOUR_USERNAME" +[ -n "$YOUR_PASSWORD" ] && VPN_PASSWORD="$YOUR_PASSWORD" if [ -z "$VPN_IPSEC_PSK" ] && [ -z "$VPN_USER" ] && [ -z "$VPN_PASSWORD" ]; then + echo "VPN credentials not set by user. Generating random PSK and password..." + echo VPN_IPSEC_PSK="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" VPN_USER=vpnuser VPN_PASSWORD="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" fi if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then - echoerr "VPN credentials must be specified. Edit the script and re-enter them." + echoerr "All VPN credentials must be specified. Edit the script and re-enter them." exit 1 fi