From 031afd587e594f4dc7966c11c73ed0dd90bf6022 Mon Sep 17 00:00:00 2001 From: patlol Date: Sat, 22 Jul 2017 19:30:36 +0200 Subject: [PATCH 1/4] fix #8 Client files not beeing created in the right folder when using sudo --- openvpn-install.sh | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) mode change 100755 => 100644 openvpn-install.sh diff --git a/openvpn-install.sh b/openvpn-install.sh old mode 100755 new mode 100644 index 3bcd725..e9e5373 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -56,21 +56,29 @@ else fi newclient () { + # Where to write the custom client.ovpn? + if [ -e /home/$1 ]; then # if $1 is a user ID + homeDir="/home/$1" + elif [ -e /home/${SUDO_USER} ]; then # if not, use SUDO_USER + homeDir="/home/${SUDO_USER}" + else # if not, use /root + homeDir="~" + fi # Generates the custom client.ovpn - cp /etc/openvpn/client-template.txt ~/$1.ovpn - echo "" >> ~/$1.ovpn - cat /etc/openvpn/easy-rsa/pki/ca.crt >> ~/$1.ovpn - echo "" >> ~/$1.ovpn - echo "" >> ~/$1.ovpn - cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >> ~/$1.ovpn - echo "" >> ~/$1.ovpn - echo "" >> ~/$1.ovpn - cat /etc/openvpn/easy-rsa/pki/private/$1.key >> ~/$1.ovpn - echo "" >> ~/$1.ovpn - echo "key-direction 1" >> ~/$1.ovpn - echo "" >> ~/$1.ovpn - cat /etc/openvpn/tls-auth.key >> ~/$1.ovpn - echo "" >> ~/$1.ovpn + cp /etc/openvpn/client-template.txt $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn + cat /etc/openvpn/easy-rsa/pki/ca.crt >> $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn + cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >> $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn + cat /etc/openvpn/easy-rsa/pki/private/$1.key >> $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn + echo "key-direction 1" >> $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn + cat /etc/openvpn/tls-auth.key >> $homeDir/$1.ovpn + echo "" >> $homeDir/$1.ovpn } # Try to get our IP from the system and fallback to the Internet. @@ -108,7 +116,7 @@ if [[ -e /etc/openvpn/server.conf ]]; then # Generates the custom client.ovpn newclient "$CLIENT" echo "" - echo "Client $CLIENT added, certs available at ~/$CLIENT.ovpn" + echo "Client $CLIENT added, certs available at $homeDir/$CLIENT.ovpn" exit ;; 2) @@ -356,7 +364,7 @@ else echo "Ok, bye !" exit 4 fi - + if [[ "$OS" = 'arch' ]]; then # Install rc.local echo "[Unit] @@ -375,7 +383,7 @@ WantedBy=multi-user.target" > /etc/systemd/system/rc-local.service echo "#!/bin/bash" > $RCLOCAL fi fi - + # Install dependencies pacman -Syu openvpn iptables openssl wget ca-certificates curl --needed --noconfirm if [[ "$OS" = 'arch' ]]; then @@ -417,7 +425,7 @@ WantedBy=multi-user.target" > /etc/systemd/system/rc-local.service cp pki/ca.crt pki/private/ca.key dh.pem pki/issued/server.crt pki/private/server.key /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn # Make cert revocation list readable for non-root chmod 644 /etc/openvpn/crl.pem - + # Generate server.conf echo "port $PORT" > /etc/openvpn/server.conf if [[ "$PROTOCOL" = 'UDP' ]]; then @@ -625,7 +633,7 @@ verb 3" >> /etc/openvpn/client-template.txt echo "" echo "Finished!" echo "" - echo "Your client config is available at ~/$CLIENT.ovpn" + echo "Your client config is available at $homeDir/$CLIENT.ovpn" echo "If you want to add more clients, you simply need to run this script another time!" fi exit 0; From 5787c45a032a204dd4f3b14e91355fd7263c9ec8 Mon Sep 17 00:00:00 2001 From: patlol Date: Sat, 22 Jul 2017 19:40:29 +0200 Subject: [PATCH 2/4] Update openvpn-install.sh --- openvpn-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index e9e5373..603d0a1 100644 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -57,7 +57,7 @@ fi newclient () { # Where to write the custom client.ovpn? - if [ -e /home/$1 ]; then # if $1 is a user ID + if [ -e /home/$1 ]; then # if $1 is a user name homeDir="/home/$1" elif [ -e /home/${SUDO_USER} ]; then # if not, use SUDO_USER homeDir="/home/${SUDO_USER}" From 3c5c87b031d49335f3ccbe941343c1451f8b7f55 Mon Sep 17 00:00:00 2001 From: patlol Date: Sat, 22 Jul 2017 20:18:46 +0200 Subject: [PATCH 3/4] Update openvpn-install.sh --- openvpn-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 603d0a1..3e19335 100644 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -59,10 +59,10 @@ newclient () { # Where to write the custom client.ovpn? if [ -e /home/$1 ]; then # if $1 is a user name homeDir="/home/$1" - elif [ -e /home/${SUDO_USER} ]; then # if not, use SUDO_USER + elif [ ${SUDO_USER} ]; then # if not, use SUDO_USER homeDir="/home/${SUDO_USER}" - else # if not, use /root - homeDir="~" + else # if not SUDO_USER, use /root + homeDir="/root" fi # Generates the custom client.ovpn cp /etc/openvpn/client-template.txt $homeDir/$1.ovpn From 58a5282e17b7556fe0513fd897bddd1830902cd3 Mon Sep 17 00:00:00 2001 From: patlol Date: Sat, 22 Jul 2017 21:08:06 +0200 Subject: [PATCH 4/4] Update openvpn-install.sh --- openvpn-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 3e19335..c5c0f77 100644 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -59,7 +59,7 @@ newclient () { # Where to write the custom client.ovpn? if [ -e /home/$1 ]; then # if $1 is a user name homeDir="/home/$1" - elif [ ${SUDO_USER} ]; then # if not, use SUDO_USER + elif [ ${SUDO_USER} ]; then # if not, use SUDO_USER homeDir="/home/${SUDO_USER}" else # if not SUDO_USER, use /root homeDir="/root"