Added variable CERTIFICATE_DIR to change the output destination certificate path

This commit is contained in:
Angelo Cassano 2020-12-27 18:05:50 +01:00
parent ea236de3e3
commit 833167d520
2 changed files with 14 additions and 10 deletions

View File

@ -70,6 +70,7 @@ If you want to customise your installation, you can export them or specify them
- `CUSTOMIZE_ENC=n` - `CUSTOMIZE_ENC=n`
- `CLIENT=clientname` - `CLIENT=clientname`
- `PASS=1` - `PASS=1`
- `CERTIFICATE_DIR=/path/to/your/custom/folder`
If the server is behind NAT, you can specify its endpoint with the `ENDPOINT` variable. If the endpoint is the public IP address which it is behind, you can use `ENDPOINT=$(curl -4 ifconfig.co)` (the script will default to this). The endpoint can be an IPv4 or a domain. If the server is behind NAT, you can specify its endpoint with the `ENDPOINT` variable. If the endpoint is the public IP address which it is behind, you can use `ENDPOINT=$(curl -4 ifconfig.co)` (the script will default to this). The endpoint can be an IPv4 or a domain.

View File

@ -1084,13 +1084,16 @@ function newClient() {
echo "Client $CLIENT added." echo "Client $CLIENT added."
fi fi
# Home directory of the user, where the client configuration (.ovpn) will be written
if [ -e "/home/$CLIENT" ]; then # if $1 is a user name if [[ -z $CERTIFICATE_DIR ]]; then
homeDir="/home/$CLIENT" # Home directory of the user, where the client configuration (.ovpn) will be written
elif [ "${SUDO_USER}" ]; then # if not, use SUDO_USER if [ -e "/home/$CLIENT" ]; then # if $1 is a user name
homeDir="/home/${SUDO_USER}" CERTIFICATE_DIR="/home/$CLIENT"
else # if not SUDO_USER, use /root elif [ "${SUDO_USER}" ]; then # if not, use SUDO_USER
homeDir="/root" CERTIFICATE_DIR="/home/${SUDO_USER}"
else # if not SUDO_USER, use /root
CERTIFICATE_DIR="/root"
fi
fi fi
# Determine if we use tls-auth or tls-crypt # Determine if we use tls-auth or tls-crypt
@ -1101,7 +1104,7 @@ function newClient() {
fi fi
# Generates the custom client.ovpn # Generates the custom client.ovpn
cp /etc/openvpn/client-template.txt "$homeDir/$CLIENT.ovpn" cp /etc/openvpn/client-template.txt "$CERTIFICATE_DIR/$CLIENT.ovpn"
{ {
echo "<ca>" echo "<ca>"
cat "/etc/openvpn/easy-rsa/pki/ca.crt" cat "/etc/openvpn/easy-rsa/pki/ca.crt"
@ -1128,10 +1131,10 @@ function newClient() {
echo "</tls-auth>" echo "</tls-auth>"
;; ;;
esac esac
} >>"$homeDir/$CLIENT.ovpn" } >>"$CERTIFICATE_DIR/$CLIENT.ovpn"
echo "" echo ""
echo "The configuration file has been written to $homeDir/$CLIENT.ovpn." echo "The configuration file has been written to $CERTIFICATE_DIR/$CLIENT.ovpn."
echo "Download the .ovpn file and import it in your OpenVPN client." echo "Download the .ovpn file and import it in your OpenVPN client."
exit 0 exit 0