From 9635c4022d9d0819f8f61cd39911a47b5c7253a9 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Fri, 23 Apr 2021 22:09:34 +0200 Subject: [PATCH] Update 93-openvpn.sh --- .../rootfs/etc/cont-init.d/93-openvpn.sh | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh index ef8ca04ac..768fbac9d 100644 --- a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh @@ -8,6 +8,8 @@ declare openvpn_password if bashio::config.true 'openvpn_enabled'; then bashio::log.info "Configuring openvpn" + + # CONFIGURE OPENVPN openvpn_config=$(bashio::config 'openvpn_config') cp "/config/openvpn/${openvpn_config}.ovpn" /etc/openvpn/config.ovpn || bashio::log.error "openvpn config file not found in /config/openvpn/${openvpn_config}.ovpn" @@ -22,4 +24,25 @@ if bashio::config.true 'openvpn_enabled'; then sed -i "1a\/etc/openvpn/up-qbittorrent.sh \"\${4}\" &\n" /etc/openvpn/up.sh bashio::log.info "openvpn correctly set, please modify manually qbittorrent options to select it" + # CONFIGURE QBITTORRENT + port="$1" + + QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf" + if [ -f "$QBT_CONFIG_FILE" ]; then + # if Connection address line exists + if grep -q 'Connection\\PortRangeMin' "$QBT_CONFIG_FILE"; then + # Set connection interface address to the VPN address + sed -i -E 's/^.*\b(Connection.*PortRangeMin)\b.*$/Connection\\PortRangeMin='"$port"'/' "$QBT_CONFIG_FILE" + else + # add the line for configuring interface address to the qBittorrent config file + printf 'Connection\\PortRangeMin=%s' "$port" >>"$QBT_CONFIG_FILE" + fi + else + bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options " + exit 1 + fi +else + # Ensure no redirection by removing the direction tag + bashio::log.info "Direct connection without VPN enabled" + sed -i '/PortRangeMin/d' $QBT_CONFIG_FILE fi