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,40 +39,70 @@ if bashio::config.true 'openvpn_enabled'; then
######################### #########################
QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf" QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf"
# Define preferences line
cd /config/qBittorrent/ || exit 1
LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
LINE=$((LINE + 1))
SESSION=$(sed -n '/BitTorrent/=' qBittorrent.conf)
# If qBittorrent.conf exists # WITH CONTAINER BINDING
if [ -f "$QBT_CONFIG_FILE" ]; then #########################
# Remove previous line and bind tun0 # If alternative mode enabled, bind container
sed -i '/Interface/d' qBittorrent.conf if bashio::config.true 'openvpn_alt_mode'; then
# Bind tun0 # Remove interface
sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf sed -i '/Interface/d' "$QBT_CONFIG_FILE"
sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf
if [ "$SESSION" != "" ]; then # Modify ovpn config
SESSION=$((SESSION + 1)) if grep -q route-nopull /etc/openvpn/config.ovpn; then
sed -i "$SESSION i\Session\\\Interface=tun0" qBittorrent.conf echo "... removing route-nopull from your config.ovpn"
sed -i "$SESSION i\Session\\\InterfaceName=tun0" qBittorrent.conf sed -i '/route-nopull/d' /etc/openvpn/config.ovpn
fi fi
else # Exit
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options " exit 0
exit 1
fi fi
# Modify ovpn config # WITH INTERFACE BINDING
echo "route-nopull" >>/etc/openvpn/config.ovpn #########################
# Connection with interface binding
echo "Using interface binding in the qBittorrent app"
# Define preferences line
cd /config/qBittorrent/ || exit 1
LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
LINE=$((LINE + 1))
SESSION=$(sed -n '/BitTorrent/=' qBittorrent.conf)
# If qBittorrent.conf exists
if [ -f "$QBT_CONFIG_FILE" ]; then
# Remove previous line and bind tun0
echo "... deleting previous interface settings"
sed -i '/Interface/d' qBittorrent.conf
# Bind tun0
echo "... binding tun0 interface in qBittorrent configuration"
sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf
sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf
if [ "$SESSION" != "" ]; then
SESSION=$((SESSION + 1))
sed -i "$SESSION i\Session\\\Interface=tun0" qBittorrent.conf
sed -i "$SESSION i\Session\\\InterfaceName=tun0" qBittorrent.conf
fi
else
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options "
exit 1
fi
# 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
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