Failsafe home dir obtaining

+ When estimating $INSTALL_HOME, assure grep can only match user names, to avoid possible wrong multi-line value
+ Remove possible trailing slash from $INSTALL_HOME, to avoid double slash in "$INSTALL_HOME/ovpns"
+ Avoid "cat <file> | grep <pattern>", since grep can process files directly

Signed-off-by: MichaIng <micha@dietpi.com>
This commit is contained in:
MichaIng 2019-09-01 17:39:38 +02:00 committed by GitHub
parent 9ee4c6179f
commit 73b23c525b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1131,7 +1131,8 @@ confOVPN() {
# verify server name to strengthen security
$SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt
INSTALL_HOME=$(cat /etc/passwd | grep "$INSTALL_USER" | cut -d: -f6)
INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6)
INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash
if [ ! -d "$INSTALL_HOME/ovpns" ]; then
$SUDO mkdir "$INSTALL_HOME/ovpns"
fi