Beautify bash

This commit is contained in:
alexbelgium
2022-03-16 09:56:19 +00:00
committed by GitHub
parent 9ad60be58b
commit dc791623d5
146 changed files with 2017 additions and 2017 deletions

View File

@@ -8,84 +8,84 @@ declare openvpn_password
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
###############
# ENABLE IPV6 #
###############
#####################
# CONFIGURE OPENVPN #
#####################
# { 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
openvpn_config=$(bashio::config 'openvpn_config')
# sysctl -p || true
cp "/config/openvpn/${openvpn_config}" /etc/openvpn/config.ovpn || bashio::log.error "openvpn config file not found in /config/openvpn/${openvpn_config}"
#####################
# CONFIGURE OPENVPN #
#####################
openvpn_username=$(bashio::config 'openvpn_username')
echo "${openvpn_username}" >/etc/openvpn/credentials
openvpn_password=$(bashio::config 'openvpn_password')
echo "${openvpn_password}" >>/etc/openvpn/credentials
sed -i 's/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/credentials/g' /etc/openvpn/config.ovpn
openvpn_config=$(bashio::config 'openvpn_config')
# Permissions
chmod 600 /etc/openvpn/credentials
chmod 755 /etc/openvpn/up.sh
chmod 755 /etc/openvpn/down.sh
chmod 755 /etc/openvpn/up-qbittorrent.sh
chmod +x /etc/openvpn/up.sh
chmod +x /etc/openvpn/up-qbittorrent.sh
cp "/config/openvpn/${openvpn_config}" /etc/openvpn/config.ovpn || bashio::log.error "openvpn config file not found in /config/openvpn/${openvpn_config}"
bashio::log.info "openvpn correctly set, qbittorrent will run tunnelled through openvpn"
openvpn_username=$(bashio::config 'openvpn_username')
echo "${openvpn_username}" >/etc/openvpn/credentials
openvpn_password=$(bashio::config 'openvpn_password')
echo "${openvpn_password}" >>/etc/openvpn/credentials
sed -i 's/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/credentials/g' /etc/openvpn/config.ovpn
#########################
# CONFIGURE QBITTORRENT #
#########################
# Permissions
chmod 600 /etc/openvpn/credentials
chmod 755 /etc/openvpn/up.sh
chmod 755 /etc/openvpn/down.sh
chmod 755 /etc/openvpn/up-qbittorrent.sh
chmod +x /etc/openvpn/up.sh
chmod +x /etc/openvpn/up-qbittorrent.sh
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)
bashio::log.info "openvpn correctly set, qbittorrent will run tunnelled through openvpn"
# If qBittorrent.conf exists
if [ -f "$QBT_CONFIG_FILE" ]; then
# Remove previous line and bind tun0
sed -i '/Interface/d' qBittorrent.conf
#########################
# CONFIGURE QBITTORRENT #
#########################
# Bind tun0
sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf
sed -i "$LINE i\Connection\\\InterfaceName=tun0" 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 [ "$SESSION" != "" ]; then
SESSION=$((SESSION + 1))
sed -i "$SESSION i\Session\\\Interface=tun0" qBittorrent.conf
sed -i "$SESSION i\Session\\\InterfaceName=tun0" qBittorrent.conf
# If qBittorrent.conf exists
if [ -f "$QBT_CONFIG_FILE" ]; then
# Remove previous line and bind tun0
sed -i '/Interface/d' qBittorrent.conf
# Bind tun0
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
else
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options "
exit 1
fi
# Modify ovpn config
echo "route-nopull" >>/etc/openvpn/config.ovpn
# Modify ovpn config
echo "route-nopull" >>/etc/openvpn/config.ovpn
else
##################
# REMOVE OPENVPN #
##################
# Ensure no redirection by removing the direction tag
cd /config/qBittorrent/ || exit 1
sed -i '/Interface/d' qBittorrent.conf
bashio::log.info "Direct connection without VPN enabled"
##################
# REMOVE OPENVPN #
##################
# Ensure no redirection by removing the direction tag
cd /config/qBittorrent/ || exit 1
sed -i '/Interface/d' qBittorrent.conf
bashio::log.info "Direct connection without VPN enabled"
fi