From 13b92e9af4887b81b8a1615318038394802523da Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:06:23 +0100 Subject: [PATCH] Update 93-openvpn.sh --- .../rootfs/etc/cont-init.d/93-openvpn.sh | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh index 47df03bde..bc7ceff4a 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh @@ -29,23 +29,21 @@ if bashio::config.true 'openvpn_enabled'; then return 1 fi - cp "$file" /tmpfile + # Avoid single auth-user-pass + if grep -q "^auth-user-pass" "$file" ; then + second_word="$(sed -n "/^auth-user-pass/p" "$file" | awk -F' ' '{print $2}')" + # If the second word is empty or starts with a dash + if [ -z "$second_word" ] || [[ "$second_word" == -* ]]; then + # Comment out the line with # + sed -i '/^auth-user-pass/s/^/#/' "$file" + continue + fi + fi - # Loop through each line of the input file + # Check referenced files + cp "$file" /tmpfile while read -r line do - # If the line contains only auth-user-pass disable it - if [[ "$line" == "auth-user-pass"* ]]; then - # Split the line by whitespace and get the second word - second_word=$(echo "$line" | awk '{print $2}') - # If the second word is empty or starts with a dash - if [ -z "$second_word" ] || [[ "$second_word" == -* ]]; then - # Comment out the line with # - sed -i '/^auth-user-pass/s/^/#/' "$file" - continue - fi - fi - # Check if the line contains a txt file if [[ ! $line =~ ^"#" ]] && [[ ! $line =~ ^";" ]] && [[ "$line" =~ \.txt ]] || [[ "$line" =~ \.crt ]] || [[ "$line" =~ auth-user-pass ]]; then # Extract the txt file name from the line @@ -65,7 +63,6 @@ if bashio::config.true 'openvpn_enabled'; then fi fi done < /tmpfile - rm /tmpfile # Standardize lf @@ -145,10 +142,10 @@ if bashio::config.true 'openvpn_enabled'; then fi # Add credentials file - file_name="$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config" | awk -F' ' '{print $2}')" - file_name="${file_name:-null}" if grep -q ^auth-user-pass /config/openvpn/"$openvpn_config" ; then # Credentials specified are they custom ? + file_name="$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config" | awk -F' ' '{print $2}')" + file_name="${file_name:-null}" if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [[ "$file_name" != "null" ]]; then if [ -f "$file_name" ]; then # If credential specified, exists, and is not the addon default