mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-17 04:49:13 +02:00
Correct code
This commit is contained in:
@@ -9,7 +9,10 @@ if bashio::config.true 'openvpn_enabled'; then
|
|||||||
|
|
||||||
bashio::log.info "Configuring openvpn"
|
bashio::log.info "Configuring openvpn"
|
||||||
|
|
||||||
# CONFIGURE OPENVPN
|
#####################
|
||||||
|
# CONFIGURE OPENVPN #
|
||||||
|
#####################
|
||||||
|
|
||||||
openvpn_config=$(bashio::config 'openvpn_config')
|
openvpn_config=$(bashio::config 'openvpn_config')
|
||||||
|
|
||||||
cp "/config/openvpn/${openvpn_config}" /etc/openvpn/config.ovpn || bashio::log.error "openvpn config file not found in /config/openvpn/${openvpn_config}"
|
cp "/config/openvpn/${openvpn_config}" /etc/openvpn/config.ovpn || bashio::log.error "openvpn config file not found in /config/openvpn/${openvpn_config}"
|
||||||
@@ -20,44 +23,41 @@ if bashio::config.true 'openvpn_enabled'; then
|
|||||||
echo "${openvpn_password}" >> /etc/openvpn/credentials
|
echo "${openvpn_password}" >> /etc/openvpn/credentials
|
||||||
|
|
||||||
sed -i 's/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/credentials/g' /etc/openvpn/config.ovpn
|
sed -i 's/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/credentials/g' /etc/openvpn/config.ovpn
|
||||||
#sed -i "1a\/etc/openvpn/up-qbittorrent.sh \"\${4}\" &\n" /etc/openvpn/up.sh
|
bashio::log.info "openvpn correctly set, qbittorrent will run tunnelled through openvpn"
|
||||||
bashio::log.info "openvpn correctly set, please modify manually qbittorrent options to select it"
|
|
||||||
|
|
||||||
# CONFIGURE QBITTORRENT
|
#########################
|
||||||
|
# CONFIGURE QBITTORRENT #
|
||||||
|
#########################
|
||||||
|
|
||||||
|
port="$1"
|
||||||
|
QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf"
|
||||||
# Define preferences line
|
# Define preferences line
|
||||||
cd /config/qBittorrent/
|
cd /config/qBittorrent/
|
||||||
LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
|
LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
|
||||||
LINE=$((LINE + 1))
|
LINE=$((LINE + 1))
|
||||||
# Remove previous line and bind tun0
|
|
||||||
sed -i '/Interface/d' qBittorrent.conf
|
|
||||||
sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf
|
|
||||||
sed -i "$LINE i\Connection\\\InterfaceAddress=" qBittorrent.conf
|
|
||||||
sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf
|
|
||||||
|
|
||||||
# Other configs
|
# If qBittorrent.conf exists
|
||||||
port="$1"
|
|
||||||
QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf"
|
|
||||||
if [ -f "$QBT_CONFIG_FILE" ]; then
|
if [ -f "$QBT_CONFIG_FILE" ]; then
|
||||||
# if Connection address line exists
|
|
||||||
if grep -q 'Connection\\PortRangeMin' "$QBT_CONFIG_FILE"; then
|
# Remove previous line and bind tun0
|
||||||
# Set connection interface address to the VPN address
|
sed -i '/Interface/d' qBittorrent.conf
|
||||||
sed -i -E 's/^.*\b(Connection.*PortRangeMin)\b.*$/Connection\\PortRangeMin='"$port"'/' "$QBT_CONFIG_FILE"
|
sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf
|
||||||
else
|
sed -i "$LINE i\Connection\\\InterfaceAddress=" qBittorrent.conf
|
||||||
# add the line for configuring interface address to the qBittorrent config file
|
sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf
|
||||||
printf 'Connection\\PortRangeMin=%s' "$port" >>"$QBT_CONFIG_FILE"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options "
|
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options "
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
##################
|
||||||
|
# REMOVE OPENVPN #
|
||||||
|
##################
|
||||||
# Ensure no redirection by removing the direction tag
|
# Ensure no redirection by removing the direction tag
|
||||||
bashio::log.info "Direct connection without VPN enabled"
|
|
||||||
cd /config/qBittorrent/
|
cd /config/qBittorrent/
|
||||||
sed -i '/PortRangeMin/d' qBittorrent.conf
|
sed -i '/PortRangeMin/d' qBittorrent.conf
|
||||||
sed -i '/Interface/d' qBittorrent.conf
|
sed -i '/Interface/d' qBittorrent.conf
|
||||||
sed -i "$LINE i\Connection\\\Interface=" qBittorrent.conf
|
sed -i "$LINE i\Connection\\\Interface=" qBittorrent.conf
|
||||||
sed -i "$LINE i\Connection\\\InterfaceAddress=" qBittorrent.conf
|
sed -i "$LINE i\Connection\\\InterfaceAddress=" qBittorrent.conf
|
||||||
sed -i "$LINE i\Connection\\\InterfaceName=" qBittorrent.conf
|
sed -i "$LINE i\Connection\\\InterfaceName=" qBittorrent.conf
|
||||||
|
bashio::log.info "Direct connection without VPN enabled"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user