Skip to content

Commit

Permalink
chown/chmod client file when name match system user (angristan#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Jan 19, 2022
1 parent 8c62660 commit 1dcd1ce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions openvpn-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ function newClient() {
if [ -e "/home/${CLIENT}" ]; then
# if $1 is a user name
homeDir="/home/${CLIENT}"
CLIENT_OWNER="$CLIENT"
elif [ "${SUDO_USER}" ]; then
# if not, use SUDO_USER
if [ "${SUDO_USER}" == "root" ]; then
Expand All @@ -1105,11 +1106,14 @@ function newClient() {
else
homeDir="/home/${SUDO_USER}"
fi
CLIENT_OWNER="$SUDO_USER"
else
# if not SUDO_USER, use /root
homeDir="/root"
fi
CLIENT_FILEPATH = "$homeDir/$CLIENT.ovpn"
# Determine if we use tls-auth or tls-crypt
if grep -qs "^tls-crypt" /etc/openvpn/server.conf; then
TLS_SIG="1"
Expand All @@ -1118,7 +1122,7 @@ function newClient() {
fi
# Generates the custom client.ovpn
cp /etc/openvpn/client-template.txt "$homeDir/$CLIENT.ovpn"
cp /etc/openvpn/client-template.txt "$CLIENT_FILEPATH"
{
echo "<ca>"
cat "/etc/openvpn/easy-rsa/pki/ca.crt"
Expand All @@ -1145,10 +1149,16 @@ function newClient() {
echo "</tls-auth>"
;;
esac
} >>"$homeDir/$CLIENT.ovpn"
} >>"$CLIENT_FILEPATH"
if [[ ! -z "$CLIENT_OWNER" ]]; then
echo "Setting owner permission for $CLIENT_FILEPATH"
chmod go-rw "$CLIENT_FILEPATH"
chown "$CLIENT_OWNER" "$CLIENT_FILEPATH"
fi
echo ""
echo "The configuration file has been written to $homeDir/$CLIENT.ovpn."
echo "The configuration file has been written to $CLIENT_FILEPATH."
echo "Download the .ovpn file and import it in your OpenVPN client."
exit 0
Expand Down

0 comments on commit 1dcd1ce

Please sign in to comment.