From 5d96e6e6d0799b8e60415b7e4476275a626d354b Mon Sep 17 00:00:00 2001 From: MarkusMcNugen Date: Mon, 16 Apr 2018 00:25:29 -0400 Subject: [PATCH] Update start.sh --- openvpn/start.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/openvpn/start.sh b/openvpn/start.sh index dd7799d..0fd42ea 100755 --- a/openvpn/start.sh +++ b/openvpn/start.sh @@ -43,24 +43,21 @@ if [[ $VPN_ENABLED == "yes" ]]; then echo "[info] OpenVPN config file (ovpn extension) is located at ${VPN_CONFIG}" | ts '%Y-%m-%d %H:%M:%.S' # Read username and password env vars and put them in credentials.conf, then add ovpn config for credentials file - if [[ ! -z "${vpn_username}" ]] && [[ ! -z "${vpn_password}" ]]; then + if [[ ! -z "${VPN_USERNAME}" ]] && [[ ! -z "${VPN_PASSWORD}" ]]; then if [[ ! -e /config/openvpn/credentials.conf ]]; then touch /config/openvpn/credentials.conf fi - echo "${vpn_username}" > /config/openvpn/credentials.conf - echo "${vpn_password}" >> /config/openvpn/credentials.conf + echo "${VPN_USERNAME}" > /config/openvpn/credentials.conf + echo "${VPN_PASSWORD}" >> /config/openvpn/credentials.conf - # Check if auth-user-pass points to credentials file and try to modify with sed if it doesnt - auth_cred_exist=${cat ${VPN_CONFIG} | grep -m 1 'auth-user-pass credentials.conf' } - if [[ -z "${auth_cred_exist}" ]]; then - sed -i 's/^auth-user-pass/auth-user-pass credentials.conf/' ${VPN_CONFIG} - fi + # Get line number of auth-user-pass + LINE_NUM=$(grep -Fn -m 1 'auth-user-pass' ${VPN_CONFIG} | cut -d: -f 1) - # If auth-user-pass doesnt point to credentials.conf now then we need to add it to the ovpn file - auth_cred_exist=${cat ${VPN_CONFIG} | grep -m 1 'auth-user-pass credentials.conf' } + # Replace line with one that points to credentials.conf + auth_cred_exist=$(cat ${VPN_CONFIG} | grep -m 1 'auth-user-pass credentials.conf') if [[ -z "${auth_cred_exist}" ]]; then - sed -i '1s/^/auth-user-pass credentials.conf\n/' ${VPN_CONFIG} + sed -i "${LINE_NUM}s/^/auth-user-pass credentials.conf\n/" ${VPN_CONFIG} fi fi