This commit is contained in:
Alexandre
2023-12-22 07:35:57 +01:00
parent fe9df8fadb
commit 006efea300
21 changed files with 579 additions and 398 deletions

View File

@@ -0,0 +1,59 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
mkdir -p /config/qBittorrent
mkdir -p /config/wireguard
mkdir -p /config/openvpn
MIGRATED=""
# Move main folder
if [ -f /homeassistant/addons_config/qBittorrent/qBittorrent.conf ] && [ ! -f /homeassistant/addons_config/qBittorrent/migrated ]; then
bashio::log.warning "----------------------------------------"
bashio::log.warning "Migrating configuration to the new addon"
bashio::log.warning "----------------------------------------"
cp -rnp /homeassistant/addons_config/qBittorrent/* /config/qBittorrent/ &>/dev/null || true
if [ -d /config/qBittorrent/addons_config ]; then rm -r /config/qBittorrent/addons_config; fi
if [ -d /config/qBittorrent/qBittorrent ]; then rm -r /config/qBittorrent/qBittorrent; fi
echo "Files moved to /addon_configs/$HOSTNAME/openvpn" > /homeassistant/addons_config/qBittorrent/migrated
bashio::log.yellow "... moved files from /config/addons_config/qBittorrent to /addon_configs/$HOSTNAME/qBitorrent (must be accessed with my Filebrowser addon)"
MIGRATED=true
fi
# Move config
if [ -f /config/qBittorrent/config/qBittorrent.conf ]; then
mv /config/qBittorrent/config/* /config/qBittorrent/ || true
mv /config/qBittorrent/data/* /config/qBittorrent/ || true
rm -r /config/qBittorrent/config || true
rm -r /config/qBittorrent/data || true
MIGRATED=true
fi
# Move openvpn
if [ -d /homeassistant/openvpn ]; then
if [ ! -f /homeassistant/openvpn/migrated ] && [ "$(ls -A /homeassistant/openvpn)" ]; then
cp -rnf /homeassistant/openvpn/* /config/openvpn &>/dev/null || true
echo "Files moved to /addon_configs/$HOSTNAME/openvpn" > /homeassistant/openvpn/migrated
fi
fi
# Move config.yaml
if [ -f /homeassistant/addons_config/qbittorrent/config.yaml ] && [ ! -f /homeassistant/addons_config/qbittorrent/migrated ]; then
cp -rnf /homeassistant/addons_config/qbittorrent/* /config/ &>/dev/null || true
rm -r /homeassistant/addons_config/qbittorrent
bashio::log.yellow "... moved config.yaml from /config/addons_config/qbittorrent to /addon_configs/$HOSTNAME"
fi
# Move autoscript
if [ -f /homeassistant/addons_autoscrips/qbittorrent.sh ]; then
cp -rnf /homeassistant/addons_autoscrips/qbittorrent.sh /config/ &>/dev/null || true
mv /homeassistant/addons_autoscrips/qbittorrent.sh /homeassistant/addons_autoscrips/qbittorrent.sh.bak
bashio::log.yellow "... moved qbittorrent.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME"
fi
# Reboot post migration
if [[ "$MIGRATED" == "true" ]]; then
bashio::log.warning "Options were changed, restarting the addon"
sleep 5
bashio::addon.restart
fi

View File

@@ -1,112 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# Create new folders
mkdir -p /config/wireguard
mkdir -p /config/openvpn
mkdir -p /config/qBittorrent/config
mkdir -p /config/qBittorrent/data
MIGRATED=""
if [ -f /homeassistant/addons_config/qBittorrent/qBittorrent.conf ] && [ ! -f /homeassistant/addons_config/qBittorrent/migrated ]; then
bashio::log.warning "----------------------------------------"
bashio::log.warning "Migrating configuration to the new addon"
bashio::log.warning "----------------------------------------"
cp -rnf /homeassistant/addons_config/qBittorrent/*.json /config/qBittorrent/config/
cp -rnf /homeassistant/addons_config/qBittorrent/*.conf /config/qBittorrent/config/
if [ -d /homeassistant/addons_config/qBittorrent/rss ]; then cp -rnf /homeassistant/addons_config/qBittorrent/rss /config/qBittorrent/config/; fi
cp -rnf /homeassistant/addons_config/qBittorrent/* /config/qBittorrent/data/
if [ -d /config/qBittorrent/data/addons_config ]; then rm -r /config/qBittorrent/data/addons_config; fi
if [ -d /config/qBittorrent/data/qBittorrent ]; then rm -r /config/qBittorrent/data/qBittorrent; fi
touch /homeassistant/addons_config/qBittorrent/migrated
bashio::log.yellow "... moved files from /config/addons_config/qBittorrent to /addon_configs/$HOSTNAME/qBitorrent (must be accessed with my Filebrowser addon)"
if [ -d /homeassistant/openvpn ]; then
if [ "$(ls -A /homeassistant/openvpn)" ]; then
cp -rnf /homeassistant/openvpn/* /config/openvpn/
fi
fi
fi
if [ -f /homeassistant/addons_config/qbittorrent/config.yaml ] && [ ! -f /homeassistant/addons_config/qbittorrent/migrated ]; then
cp -rnf /homeassistant/addons_config/qbittorrent/* /config/
rm -r /homeassistant/addons_config/qbittorrent
touch /homeassistant/addons_config/qbittorrent/migrated
bashio::log.yellow "... moved config.yaml from /config/addons_config/qbittorrent to /addon_configs/$HOSTNAME"
MIGRATED=true
fi
if [ -f /homeassistant/addons_autoscrips/qbittorrent.sh ]; then
cp -rnf /homeassistant/addons_autoscrips/qbittorrent.sh /config/
mv /homeassistant/addons_autoscrips/qbittorrent.sh /homeassistant/addons_autoscrips/qbittorrent.sh.bak
bashio::log.yellow "... moved qbittorrent.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME"
MIGRATED=true
fi
if bashio::config.has_value 'openvpn_enable'; then
if bashio::config.true 'openvpn_enabled'; then
bashio::addon.option "VPN_ENABLED" "yes"
bashio::log.yellow "... openvpn_enable : was true, VPN_ENABLED set to yes"
bashio::addon.option "VPN_TYPE" "openvpn"
bashio::log.yellow "... openvpn_enable : was true, VPN_TYPE set to openvpn"
fi
bashio::addon.option "openvpn_enable"
bashio::log.yellow "... openvpn_enable : removed as not used anymore"
MIGRATED=true
fi || true
if bashio::config.has_value 'openvpn_username'; then
bashio::addon.option "VPN_USERNAME" "$(bashio::config "openvpn_username")"
bashio::log.yellow "... openvpn_username : was set, VPN_USERNAME set to $(bashio::config "openvpn_username")"
bashio::addon.option "openvpn_username"
bashio::log.yellow "... openvpn_username : removed as not used anymore"
MIGRATED=true
fi || true
if bashio::config.has_value 'Username'; then
bashio::addon.option "QBT_USERNAME" "$(bashio::config "Username")"
bashio::log.yellow "... Username : was set, QBT_USERNAME set to $(bashio::config "Username")"
bashio::addon.option "Username"
bashio::log.yellow "... Username : removed as not used anymore"
MIGRATED=true
fi || true
if bashio::config.has_value 'openvpn_password'; then
bashio::addon.option "VPN_PASSWORD" "$(bashio::config "openvpn_password")"
bashio::log.yellow "... openvpn_password : was set, VPN_PASSWORD set to $(bashio::config "openvpn_password")"
bashio::addon.option "openvpn_password"
bashio::log.yellow "... openvpn_password : removed as not used anymore"
MIGRATED=true
fi || true
if bashio::config.has_value 'whitelist'; then
bashio::addon.option "LAN_NETWORK" "$(bashio::config "whitelist")"
bashio::log.yellow "... whitelist : was set, LAN_NETWORK set to $(bashio::config "whitelist")"
bashio::addon.option "whitelist"
bashio::log.yellow "... whitelist : removed as not used anymore"
MIGRATED=true
fi
if bashio::config.has_value 'smbv1'; then
bashio::addon.option "smbv1"
bashio::log.yellow "... smbv1 : removed as not used anymore"
fi
if bashio::config.has_value 'openvpn_config'; then
openvpn_config="$(bashio::config "openvpn_config")"
if [ -f "$openvpn_config" ]; then
cp -rnf "$openvpn_config" /config/openvpn/
bashio::log.yellow "... openvpn file migrated to new location"
fi
bashio::addon.option "openvpn_config"
fi
if [[ "$MIGRATED" == "true" ]]; then
bashio::log.warning "Options were changed, restarting the addon"
bashio::addon.restart
fi
if [ -d /config/qBittorrent/qBittorrent ]; then
rm -r /config/qBittorrent/qBittorrent
fi

View File

@@ -1,4 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
curl --max-time 10 --connect-timeout 5 -s https://ipecho.net/plain > /currentip

View File

@@ -1,53 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
mkdir -p /config/openvpn
chmod -R 777 /config/openvpn
QBT_CONFIG_FILE="/config/qBittorrent/config/qBittorrent.conf"
# Ensure no redirection by removing the direction tag
if [ -f "$QBT_CONFIG_FILE" ]; then
sed -i '/Interface/d' "$QBT_CONFIG_FILE"
fi
# Correct openvpn files
if [[ "$(bashio::config "VPN_ENABLED")" == "yes" ]] && [[ "$(bashio::config "VPN_TYPE")" == "openvpn" ]]; then
# If there is a config file, remove nopull
if [ -n "$(ls -A /config/openvpn 2>/dev/null)" ]; then
for file in /config/openvpn/*.ovpn; do
if [ -f "$file" ]; then
# Convert to unix
echo "... converting to unix format $file"
dos2unix "$file"
# Remove route-nopull
if grep -q route-nopull "$file"; then
echo "... removing route-nopull from $file"
sed -i "/route-nopull/d" "$file"
fi
# Correct paths
sed -i "s=/etc/openvpn=/config/openvpn=g" "$file"
# Remove blank characters and add a trailing blank line
sed -i '/^[[:space:]]*$/d' "$file"
echo "" >> "$file"
fi
done
fi
# Add iproute
ip route add 10.0.0.0/8 via 172.30.32.1
ip route add 192.168.0.0/16 via 172.30.32.1
ip route add 172.16.0.0/12 via 172.30.32.1
elif [[ "$(bashio::config "VPN_TYPE")" == "openvpn" ]]; then
export WG_I_PREFER_BUGGY_USERSPACE_TO_POLISHED_KMOD=1
sed -i -E 's/&& cmd sysctl -q net.ipv4.conf.all.src_valid_mark=1//gm' "$(command -v wg-quick)" || true
fi

View File

@@ -1,63 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
################
# SSL CONFIG #
################
if bashio::config.true 'ssl'; then
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths"
# Enable ssl in script
sed -i "1a ENABLE_SSL=yes" /etc/cont-init.d/04-qbittorrent-setup.sh
#set variables
CERTFILE=$(bashio::config 'certfile')
CERTFILE="${CERTFILE:-null}"
KEYFILE=$(bashio::config 'keyfile')
KEYFILE="${KEYFILE:-null}"
# Correct certificate file
if [ ! -f /ssl/"$CERTFILE" ]; then
bashio::log.warning "... CERTFILE option not found or valid, using self-generated /config/qBittorrent/config/WebUICertificate.crt"
else
chmod 744 /ssl/"$CERTFILE"
sed -i "s|/config/qBittorrent/config/WebUICertificate.crt|/ssl/$CERTFILE|g" /etc/cont-init.d/04-qbittorrent-setup.sh
sed -i "s|WebUICertificate.crt|$CERTFILE|g" /etc/cont-init.d/04-qbittorrent-setup.sh
fi
# Correct keyfile
if [ ! -f /ssl/"$KEYFILE" ]; then
bashio::log.warning "... KEYFILE option not found or valid, using self-generated /config/qBittorrent/config/WebUICertificate.crt"
else
chmod 744 /ssl/"$KEYFILE"
sed -i "s|/config/qBittorrent/config/WebUIKey.key|/ssl/$KEYFILE|g" /etc/cont-init.d/04-qbittorrent-setup.sh
sed -i "s|WebUIKey.key|$KEYFILE|g" /etc/cont-init.d/04-qbittorrent-setup.sh
fi
# Set nginx protocol
qbittorrent_protocol=https
else
# Disable ssl in script
sed -i "1a ENABLE_SSL=no" /etc/cont-init.d/04-qbittorrent-setup.sh
# Prepare ingress
qbittorrent_protocol="http"
# Correct qBittorrent.conf
if [ -f /config/qBittorrent/config/qBittorrent.conf ]; then
sed -i "/HTTPS/d" /config/qBittorrent/config/qBittorrent.conf
fi
fi
#################
# NGINX SETTING #
#################
cp /etc/nginx/templates/ingress.gtpl /etc/nginx/servers/ingress.conf
sed -i "s|{{ .interface }}|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .port }}|$(bashio::addon.ingress_port)|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .protocol }}|${qbittorrent_protocol}|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .certfile }}|$(bashio::config 'certfile')|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .keyfile }}|$(bashio::config 'keyfile')|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .ssl }}|$(bashio::config 'ssl')|g" /etc/nginx/servers/ingress.conf

View File

@@ -1,22 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# wait until vpn is up
sleep 5
# test if vpn is up
counter=0
until [ "$counter" -gt 10 ]
do
echo "... waiting until vpn is up"
( ping -c 1 "1.1.1.1" &> /dev/null ) && exit 0 || true
((counter++))
sleep 5
done
bashio::log.fatal "vpn failed to get up for 60 seconds. Issue with your config file ?"
if [ ! -d /REBOOT ]; then
touch /REBOOT
bashio::addon.restart
fi

View File

@@ -0,0 +1,32 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
DEBUG=$(bashio::config 'TZ')
[ "$DEBUG" = "debug" ] && echo "Before declare"
#################
# NGINX SETTING #
#################
#declare admin_port
declare qbittorrent_protocol=http
[ "$DEBUG" = "debug" ] && echo "Before ssl"
# Generate Ingress configuration
if bashio::config.true 'ssl'; then
qbittorrent_protocol=https
fi
[ "$DEBUG" = "debug" ] && echo "Before cp"
cp /etc/nginx/templates/ingress.gtpl /etc/nginx/servers/ingress.conf
[ "$DEBUG" = "debug" ] && echo "Before sed"
sed -i "s|{{ .interface }}|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .port }}|$(bashio::addon.ingress_port)|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .protocol }}|${qbittorrent_protocol}|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .certfile }}|$(bashio::config 'certfile')|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .keyfile }}|$(bashio::config 'keyfile')|g" /etc/nginx/servers/ingress.conf
sed -i "s|{{ .ssl }}|$(bashio::config 'ssl')|g" /etc/nginx/servers/ingress.conf

View File

@@ -6,15 +6,11 @@ set -e
# INIT #
##########
if [ -f /REBOOT ]; then
rm /REBOOT
fi
# Define preferences line
CONFIG_LOCATION=/config/qBittorrent/config/
CONFIG_LOCATION=/config/qBittorrent
mkdir -p "$CONFIG_LOCATION"
# copy default config
# copy default config
if [ ! -f "$CONFIG_LOCATION"/qBittorrent.conf ]; then
cp /defaults/qBittorrent.conf "$CONFIG_LOCATION"/qBittorrent.conf
fi
@@ -23,6 +19,10 @@ cd "$CONFIG_LOCATION"/ || true
LINE=$(sed -n '/\[Preferences\]/=' qBittorrent.conf) || bashio::exit.nok "qBittorrent.conf not valid"
LINE=$((LINE + 1))
# Remove unused folders
if [ -d "$CONFIG_LOCATION"/addons_config ]; then rm -r "$CONFIG_LOCATION"/addons_config; fi
if [ -d "$CONFIG_LOCATION"/qBittorrent ]; then rm -r "$CONFIG_LOCATION"/qBittorrent; fi
# Check file size
ORIGINAL_SIZE="$(wc -c "$CONFIG_LOCATION"/qBittorrent.conf)"
@@ -61,7 +61,7 @@ if bashio::config.has_value 'SavePath'; then
fi
# Create default location
if [ ! -d "$DOWNLOADS" ]; then
if [ ! -d "$DOWNLOADS" ]; then
mkdir -p "$DOWNLOADS" || bashio::log.fatal "Error : folder defined in SavePath doesn't exist and can't be created. Check path"
fi
chown -R "$PUID:$PGID" "$DOWNLOADS" || bashio::log.fatal "Error, please check default save folder configuration in addon"
@@ -70,28 +70,53 @@ chown -R "$PUID:$PGID" "$DOWNLOADS" || bashio::log.fatal "Error, please check de
# Avoid bugs #
##############
sed -i -e '/CSRFProtection/d' \
-e '/ClickjackingProtection/d' \
-e '/HostHeaderValidation/d' \
-e '/Address/d' \
-e "$LINE i\WebUI\\\CSRFProtection=false" \
-e "$LINE i\WebUI\\\ClickjackingProtection=false" \
-e "$LINE i\WebUI\\\HostHeaderValidation=false" \
-e "$LINE i\WebUI\\\Address=\*" qBittorrent.conf
sed -i -e "/CSRFProtection/d" \
-e "/ClickjackingProtection/d" \
-e "/HostHeaderValidation/d" \
-e "/WebUI\\\Address/d" \
-e "/\[Preferences\]/a \WebUI\\\CSRFProtection=false" \
-e "/\[Preferences\]/a \WebUI\\\ClickjackingProtection=false" \
-e "/\[Preferences\]/a \WebUI\\\HostHeaderValidation=false" \
-e "/\[Preferences\]/a \WebUI\\\Address=\*" qBittorrent.conf
#sed -i '/WebUI\ReverseProxySupportEnabled/d' qBittorrent.conf
#sed -i "$LINE i\WebUI\\\ReverseProxySupportEnabled=true" qBittorrent.conf
################
# Correct Port #
################
# sed -i '/PortRangeMin/d' qBittorrent.conf
# sed -i "$LINE i\Connection\\\PortRangeMin=6881" qBittorrent.conf
sed -i "s|6881|59595|g" qBittorrent.conf # Correction if required
################
# SSL CONFIG #
################
# Clean data
sed -i '/HTTPS/d' qBittorrent.conf
bashio::config.require.ssl
if bashio::config.true 'ssl'; then
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths"
#set variables
CERTFILE=$(bashio::config 'certfile')
KEYFILE=$(bashio::config 'keyfile')
#Modify configuration
sed -i "$LINE i\WebUI\\\HTTPS\\\Enabled=True" qBittorrent.conf
sed -i "$LINE i\WebUI\\\HTTPS\\\CertificatePath=/ssl/$CERTFILE" qBittorrent.conf
sed -i "$LINE i\WebUI\\\HTTPS\\\KeyPath=/ssl/$KEYFILE" qBittorrent.conf
fi
################
# WHITELIST #
################
cd "$CONFIG_LOCATION"/ || true
WHITELIST="$(bashio::config 'LAN_NETWORK')"
WHITELIST="$(bashio::config 'whitelist')"
#clean data
sed -i '/AuthSubnetWhitelist/d' qBittorrent.conf
@@ -109,32 +134,21 @@ fi
###############
cd "$CONFIG_LOCATION"/ || true
if bashio::config.has_value 'QBT_USERNAME'; then
QBT_USERNAME=$(bashio::config 'QBT_USERNAME')
if bashio::config.has_value 'Username'; then
USERNAME="$(bashio::config 'Username')"
else
QBT_USERNAME="admin"
USERNAME=admin
fi
#clean data
sed -i '/WebUI\\\Username/d' qBittorrent.conf
#add data
sed -i "/\[Preferences\]/a\WebUI\\\Username=$QBT_USERNAME" qBittorrent.conf
bashio::log.info "WEBUI username set to $QBT_USERNAME"
sed -i "/\[Preferences\]/a\WebUI\\\Username=$USERNAME" qBittorrent.conf
bashio::log.info "WEBUI username set to $USERNAME"
###############
# PASSWORD #
###############
# Set initial password to homeassistant
cd "$CONFIG_LOCATION"/ || true
if ! grep -q "Password_PBKDF2" qBittorrent.conf; then
function escape_special_characters() {
local value="$1"
value=$(echo "$value" | sed 's/[&/\;.<>`$*(){}[\]~^|!?@%#=,:+_-]/\\&/g')
echo "$value"
}
PBKDF2="UDxNW6zG8wJHG9PvnGFP4A==:gJZEXLbR2XYNN042G4ygLMvZi2BhHm2m6Soz6GVCrCuVZH6OSkUan7AvUDEiSodHckUm8oNTkx9atQwcUf/JLQ=="
PBKDF2="$(escape_special_characters "$PBKDF2")"
sed -i "/\[Preferences\]/a\WebUI\\\Password_PBKDF2=\"@ByteArray($PBKDF2)\"" qBittorrent.conf
# Add default password if not existing
if ! grep -q Password_PBKDF2 qBittorrent.conf; then
sed -i "/\[Preferences\]/a\WebUI\\\Password_PBKDF2=\"@ByteArray(cps93Gf8ma8EM3QRon+spg==:wYFoMNVmdiqzWYQ6mFrvET+RRbBSIPVfXFFeEy0ZEagxvNuEF7uGVnG5iq8oeu38kGLtmJqCM2w8cTdtORDP2A==)\"" qBittorrent.conf
fi
####################
@@ -146,6 +160,7 @@ fi
# Check file size
if [[ "$ORIGINAL_SIZE" != "$(wc -c "$CONFIG_LOCATION"/qBittorrent.conf)" ]]; then
bashio::log.warning "Configuration changed, rebooting"
sleep 5
bashio::addon.restart
fi
@@ -219,5 +234,5 @@ fi
# CLOSE #
##########
bashio::log.info "Default username/password : $QBT_USERNAME/homeassistant. Please change your password on first connection"
bashio::log.info "Default username/password : $USERNAME/homeassistant"
bashio::log.info "Configuration can be found in $CONFIG_LOCATION"

View File

@@ -0,0 +1,175 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
declare openvpn_config
declare openvpn_username
declare openvpn_password
QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf"
if bashio::config.true 'openvpn_enabled'; then
bashio::log.info "----------------------------"
bashio::log.info "Openvpn enabled, configuring"
bashio::log.info "----------------------------"
# Get current ip
curl -s ipecho.net/plain > /currentip
#####################
# CONFIGURE OPENVPN #
#####################
# If openvpn_config option used
if bashio::config.has_value "openvpn_config"; then
openvpn_config=$(bashio::config 'openvpn_config')
# If file found
if [ -f /config/openvpn/"$openvpn_config" ]; then
# If correct type
if [[ "$openvpn_config" == *".ovpn" ]] || [[ "$openvpn_config" == *".conf" ]]; then
echo "... configured ovpn file : using /addon_configs/$HOSTNAME/openvpn/$openvpn_config"
# Copy potential additional files
cp /config/openvpn/* /etc/openvpn/
# Standardize file  
cp /config/openvpn/"${openvpn_config}" /etc/openvpn/config.ovpn
# Not correct type
else
bashio::exit.nok "Configured ovpn file : $openvpn_config is set but does not end by .ovpn ; it can't be used!"
fi
# File not found
else
bashio::exit.nok "Configured ovpn file : $openvpn_config not found! Are you sure you added it in /addon_configs/$HOSTNAME/openvpn using the Filebrowser addon ?"
fi
# If openvpn_config not set, but folder is not empty
elif [ "$(ls -A /config/openvpn/*.ovpn 2>/dev/null)" ]; then
# Look for openvpn files
# Wildcard search for openvpn config files and store results in array
mapfile -t VPN_CONFIGS < <( find /config/openvpn -maxdepth 1 -name "*.ovpn" -print )
# Choose random config
VPN_CONFIG="${VPN_CONFIGS[$RANDOM % ${#VPN_CONFIGS[@]}]}"
# Get the VPN_CONFIG name without the path and extension
openvpn_config="${VPN_CONFIG##*/}"
echo "... Openvpn enabled, but openvpn_config option empty. Selecting a random ovpn file : ${openvpn_config}"
# Copy potential additional files
cp /config/openvpn/* /etc/openvpn/
# Standardize file
cp /config/openvpn/"${openvpn_config}" /etc/openvpn/config.ovpn
 
# If openvpn_config not set, and folder is empty
else
bashio::exit.nok "Openvpn enabled, but no .ovpn files in the /addon_configs/$HOSTNAME/openvpn folder ! Exiting"  
fi
# Correct paths
sed -i "s=/etc/openvpn=/config/openvpn=g" /etc/openvpn/config.ovpn
# Remove ipv6
if grep -q "ipv6" /etc/openvpn/config.ovpn; then
bashio::log.warning "ipv6 configured in the ovpn file but not compatible with the addon. You should remove it."
fi
 
# Set credentials
if bashio::config.has_value "openvpn_username"; then
openvpn_username=$(bashio::config 'openvpn_username')
echo "${openvpn_username}" >/etc/openvpn/credentials
else
bashio::exit.nok "Openvpn is enabled, but openvpn_username option is empty! Exiting"
fi
if bashio::config.has_value "openvpn_password"; then
openvpn_password=$(bashio::config 'openvpn_password')
echo "${openvpn_password}" >>/etc/openvpn/credentials
else
bashio::exit.nok "Openvpn is enabled, but openvpn_password option is empty! Exiting"
fi
 
# Add credentials file
if grep -q auth-user-pass /etc/openvpn/config.ovpn; then
sed -i "s/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/credentials/g" /etc/openvpn/config.ovpn
else
echo "auth-user-pass /etc/openvpn/credentials" >> /etc/openvpn/config.ovpn
fi
# Permissions
chmod 755 /etc/openvpn/*
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
echo "... openvpn correctly set, qbittorrent will run tunnelled through openvpn"
#########################
# CONFIGURE QBITTORRENT #
#########################
# WITH CONTAINER BINDING
#########################
# If alternative mode enabled, bind container
if bashio::config.true 'openvpn_alt_mode'; then
echo "Using container binding"
# Remove interface
echo "... deleting previous interface settings"
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
cd /config/qBittorrent/ || exit 1
# 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' "$QBT_CONFIG_FILE"
# Bind tun0
echo "... binding tun0 interface in qBittorrent configuration"
sed -i "/\[Preferences\]/ i\Connection\\\Interface=tun0" "$QBT_CONFIG_FILE"
sed -i "/\[Preferences\]/ i\Connection\\\InterfaceName=tun0" "$QBT_CONFIG_FILE"
# Add to ongoing session
sed -i "/\[BitTorrent\]/a \Session\\\Interface=tun0" "$QBT_CONFIG_FILE"
sed -i "/\[BitTorrent\]/a \Session\\\InterfaceName=tun0" "$QBT_CONFIG_FILE"
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"
sed -i "1a route-nopull" /etc/openvpn/config.ovpn
fi
else
##################
# REMOVE OPENVPN #
##################
# Ensure no redirection by removing the direction tag
if [ -f "$QBT_CONFIG_FILE" ]; then
sed -i '/Interface/d' "$QBT_CONFIG_FILE"
fi
bashio::log.info "Direct connection without VPN enabled"
fi

View File

@@ -0,0 +1,36 @@
#!/bin/sh
# shellcheck disable=SC2154,SC2004,SC2059,SC2086
# Copyright (c) 2006-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Contributed by Roy Marples (uberlord@gentoo.org)
# If we have a service specific script, run this now
if [ -x /etc/openvpn/"${RC_SVCNAME}"-down.sh ] ; then
/etc/openvpn/"${RC_SVCNAME}"-down.sh "$@"
fi
# Restore resolv.conf to how it was
if [ "${PEER_DNS}" != "no" ]; then
if [ -x /sbin/resolvconf ] ; then
/sbin/resolvconf -d "${dev}"
elif [ -e /etc/resolv.conf-"${dev}".sv ] ; then
# Important that we cat instead of move incase resolv.conf is
# a symlink and not an actual file
cat /etc/resolv.conf-"${dev}".sv > /etc/resolv.conf
rm -f /etc/resolv.conf-"${dev}".sv
fi
fi
if [ -n "${RC_SVCNAME}" ]; then
# Re-enter the init script to start any dependant services
if /etc/init.d/"${RC_SVCNAME}" --quiet status ; then
export IN_BACKGROUND=true
if [ -d /var/run/s6/container_environment ]; then printf "%s" "true" > /var/run/s6/container_environment/IN_BACKGROUND; fi
printf "%s" "IN_BACKGROUND=\"true\"" >> ~/.bashrc
/etc/init.d/"${RC_SVCNAME}" --quiet stop
fi
fi
exit 0
# vim: ts=4 :

View File

@@ -0,0 +1,9 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
WEBUI_PORT=${WEBUI_PORT:-8080}
exec \
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${WEBUI_PORT}" \
s6-setuidgid abc /usr/bin/qbittorrent-nox --webui-port="${WEBUI_PORT}"

View File

@@ -0,0 +1,97 @@
#!/bin/sh
# shellcheck disable=SC2154,SC2004,SC2059,SC2086
# launch qbittorrent
/etc/openvpn/up-qbittorrent.sh "${4}" &
# Copyright (c) 2006-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Contributed by Roy Marples (uberlord@gentoo.org)
# Setup our resolv.conf
# Vitally important that we use the domain entry in resolv.conf so we
# can setup the nameservers are for the domain ONLY in resolvconf if
# we're using a decent dns cache/forwarder like dnsmasq and NOT nscd/libc.
# nscd/libc users will get the VPN nameservers before their other ones
# and will use the first one that responds - maybe the LAN ones?
# non resolvconf users just the the VPN resolv.conf
# FIXME:- if we have >1 domain, then we have to use search :/
# We need to add a flag to resolvconf to say
# "these nameservers should only be used for the listed search domains
# if other global nameservers are present on other interfaces"
# This however, will break compatibility with Debians resolvconf
# A possible workaround would be to just list multiple domain lines
# and try and let resolvconf handle it
if [ "${PEER_DNS}" != "no" ]; then
NS=
DOMAIN=
SEARCH=
i=1
while true ; do
eval opt=\$foreign_option_${i}
[ -z "${opt}" ] && break
if [ "${opt}" != "${opt#dhcp-option DOMAIN *}" ] ; then
if [ -z "${DOMAIN}" ] ; then
DOMAIN="${opt#dhcp-option DOMAIN *}"
else
SEARCH="${SEARCH}${SEARCH:+ }${opt#dhcp-option DOMAIN *}"
fi
elif [ "${opt}" != "${opt#dhcp-option DNS *}" ] ; then
NS="${NS}nameserver ${opt#dhcp-option DNS *}\n"
fi
i=$((${i} + 1))
done
if [ -n "${NS}" ] ; then
DNS="# Generated by openvpn for interface ${dev}\n"
if [ -n "${SEARCH}" ] ; then
DNS="${DNS}search ${DOMAIN} ${SEARCH}\n"
elif [ -n "${DOMAIN}" ]; then
DNS="${DNS}domain ${DOMAIN}\n"
fi
DNS="${DNS}${NS}"
if [ -x /sbin/resolvconf ] ; then
printf "${DNS}" | /sbin/resolvconf -a "${dev}"
else
# Preserve the existing resolv.conf
if [ -e /etc/resolv.conf ] ; then
cp /etc/resolv.conf /etc/resolv.conf-"${dev}".sv
fi
printf "${DNS}" > /etc/resolv.conf
chmod 644 /etc/resolv.conf
fi
fi
fi
# Below section is Gentoo specific
# Quick summary - our init scripts are re-entrant and set the RC_SVCNAME env var
# as we could have >1 openvpn service
if [ -n "${RC_SVCNAME}" ]; then
# If we have a service specific script, run this now
if [ -x /etc/openvpn/"${RC_SVCNAME}"-up.sh ] ; then
/etc/openvpn/"${RC_SVCNAME}"-up.sh "$@"
fi
# Re-enter the init script to start any dependant services
if ! /etc/init.d/"${RC_SVCNAME}" --quiet status ; then
export IN_BACKGROUND=true
if [ -d /var/run/s6/container_environment ]; then printf "%s" "true" > /var/run/s6/container_environment/IN_BACKGROUND; fi
printf "%s" "IN_BACKGROUND=\"true\"" >> ~/.bashrc
/etc/init.d/${RC_SVCNAME} --quiet start
fi
fi
###############
# ALLOW WEBUI #
###############
ip route add 10.0.0.0/8 via 172.30.32.1
ip route add 192.168.0.0/16 via 172.30.32.1
ip route add 172.16.0.0/12 via 172.30.32.1
exit 0
# vim: ts=4 :

View File

@@ -0,0 +1,24 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
WEBUI_PORT=${WEBUI_PORT:-8080}
if bashio::config.true 'silent'; then
sed -i 's|/proc/1/fd/1 hassio;|off;|g' /etc/nginx/nginx.conf
fi
if bashio::config.true 'openvpn_enabled'; then
cd /etc/openvpn || true
exec /usr/sbin/openvpn --config /etc/openvpn/config.ovpn --script-security 2 --up /etc/openvpn/up.sh --down /etc/openvpn/down.sh
else
if bashio::config.true 'silent'; then
exec \
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${WEBUI_PORT}" \
s6-setuidgid abc /usr/bin/qbittorrent-nox --webui-port="${WEBUI_PORT}" >/dev/null
else
exec \
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${WEBUI_PORT}" \
s6-setuidgid abc /usr/bin/qbittorrent-nox --webui-port="${WEBUI_PORT}"
fi
fi

View File

@@ -8,15 +8,20 @@ bashio::net.wait_for 8080 localhost 900
bashio::log.info "Starting NGinx..."
if [[ "$(bashio::config 'VPN_ENABLED')" == "yes" ]]; then
# Check vpn is working
if [ -f /currentip ]; then
exec nginx & \
while true; do
# Get vpn ip
curl -s ipecho.net/plain --interface tun0 > /vpnip
if bashio::config.true 'openvpn_alt_mode'; then
curl -s ipecho.net/plain > /vpnip
else
curl -s ipecho.net/plain --interface tun0 > /vpnip
fi
# Verify ip has changed
if [[ "$(cat /vpnip)" = "$(cat /currentip)" ]]; then
bashio::log.fatal "VPN is not properly configured. Your ip is exposed."
bashio::log.fatal "VPN is not properly configured. Your ip is exposed. Please fix this, or do not use the vpn alt mode"
bashio::exit.nok
fi
@@ -27,7 +32,7 @@ if [[ "$(bashio::config 'VPN_ENABLED')" == "yes" ]]; then
bashio::log.info "VPN is up and running with ip $(cat /vpnip), based in country : $COUNTRY"
# Check every 15m
sleep 30m
sleep 15m
true
done