Add openvpn_alt_mode

https://github.com/alexbelgium/hassio-addons/issues/281
This commit is contained in:
Alexandre
2022-04-09 17:13:51 +02:00
committed by GitHub
parent 3dd4ff6583
commit aa61e7ca70

View File

@@ -10,16 +10,6 @@ if bashio::config.true 'openvpn_enabled'; then
bashio::log.info "Configuring openvpn" bashio::log.info "Configuring openvpn"
###############
# ENABLE IPV6 #
###############
# { echo "net.ipv6.conf.all.disable_ipv6 = 0";
# echo "net.ipv6.conf.default.disable_ipv6 = 0";
# echo "net.ipv6.conf.lo.disable_ipv6 = 0"; } >> /etc/sysctl.conf || true
# sysctl -p || true
##################### #####################
# CONFIGURE OPENVPN # # CONFIGURE OPENVPN #
##################### #####################
@@ -49,6 +39,30 @@ if bashio::config.true 'openvpn_enabled'; then
######################### #########################
QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf" QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf"
# WITH CONTAINER BINDING
#########################
# If alternative mode enabled, bind container
if bashio::config.true 'openvpn_alt_mode'; then
# Remove interface
sed -i '/Interface/d' "$QBT_CONFIG_FILE"
# Modify ovpn config
if grep -q route-nopull /etc/openvpn/config.ovpn; then
echo "... removing route-nopull from your config.ovpn"
sed -i '/route-nopull/d' /etc/openvpn/config.ovpn
fi
# Exit
exit 0
fi
# WITH INTERFACE BINDING
#########################
# Connection with interface binding
echo "Using interface binding in the qBittorrent app"
# Define preferences line # Define preferences line
cd /config/qBittorrent/ || exit 1 cd /config/qBittorrent/ || exit 1
LINE=$(sed -n '/Preferences/=' qBittorrent.conf) LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
@@ -58,9 +72,11 @@ if bashio::config.true 'openvpn_enabled'; then
# If qBittorrent.conf exists # If qBittorrent.conf exists
if [ -f "$QBT_CONFIG_FILE" ]; then if [ -f "$QBT_CONFIG_FILE" ]; then
# Remove previous line and bind tun0 # Remove previous line and bind tun0
echo "... deleting previous interface settings"
sed -i '/Interface/d' qBittorrent.conf sed -i '/Interface/d' qBittorrent.conf
# Bind tun0 # Bind tun0
echo "... binding tun0 interface in qBittorrent configuration"
sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf
sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf
@@ -76,13 +92,17 @@ if bashio::config.true 'openvpn_enabled'; then
fi fi
# Modify ovpn config # Modify ovpn config
if ! grep -q route-nopull /etc/openvpn/config.ovpn; then
echo "... adding route-nopull to your config.ovpn"
echo "route-nopull" >>/etc/openvpn/config.ovpn echo "route-nopull" >>/etc/openvpn/config.ovpn
fi
else else
################## ##################
# REMOVE OPENVPN # # REMOVE OPENVPN #
################## ##################
# Ensure no redirection by removing the direction tag # Ensure no redirection by removing the direction tag
cd /config/qBittorrent/ || exit 1 cd /config/qBittorrent/ || exit 1
sed -i '/Interface/d' qBittorrent.conf sed -i '/Interface/d' qBittorrent.conf