mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-03-03 16:00:29 +01:00
Correct code
This commit is contained in:
@@ -9,7 +9,10 @@ if bashio::config.true 'openvpn_enabled'; then
|
||||
|
||||
bashio::log.info "Configuring openvpn"
|
||||
|
||||
# CONFIGURE OPENVPN
|
||||
#####################
|
||||
# CONFIGURE OPENVPN #
|
||||
#####################
|
||||
|
||||
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}"
|
||||
@@ -20,44 +23,41 @@ if bashio::config.true 'openvpn_enabled'; then
|
||||
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 "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"
|
||||
bashio::log.info "openvpn correctly set, qbittorrent will run tunnelled through openvpn"
|
||||
|
||||
# CONFIGURE QBITTORRENT
|
||||
#########################
|
||||
# CONFIGURE QBITTORRENT #
|
||||
#########################
|
||||
|
||||
port="$1"
|
||||
QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf"
|
||||
# Define preferences line
|
||||
cd /config/qBittorrent/
|
||||
LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
|
||||
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
|
||||
|
||||
# If qBittorrent.conf exists
|
||||
if [ -f "$QBT_CONFIG_FILE" ]; then
|
||||
|
||||
# Other configs
|
||||
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
|
||||
# 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
|
||||
else
|
||||
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options "
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
##################
|
||||
# REMOVE OPENVPN #
|
||||
##################
|
||||
# Ensure no redirection by removing the direction tag
|
||||
bashio::log.info "Direct connection without VPN enabled"
|
||||
cd /config/qBittorrent/
|
||||
sed -i '/PortRangeMin/d' qBittorrent.conf
|
||||
sed -i '/Interface/d' qBittorrent.conf
|
||||
sed -i "$LINE i\Connection\\\Interface=" qBittorrent.conf
|
||||
sed -i "$LINE i\Connection\\\InterfaceAddress=" qBittorrent.conf
|
||||
sed -i "$LINE i\Connection\\\InterfaceName=" qBittorrent.conf
|
||||
bashio::log.info "Direct connection without VPN enabled"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user