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