New generation

This commit is contained in:
Alexandre
2023-12-09 14:02:01 +01:00
parent 75c63d1293
commit ecd07200e5
18 changed files with 315 additions and 421 deletions

View File

@@ -1,9 +0,0 @@
#!/bin/bash
mkdir -p /config/addons_config/qBittorrent
if [ -f /config/addons_config/qbittorrent/qBittorrent.conf ] && [ -f /config/addons_config/qBittorrent/qBittorrent.conf ]; then
echo "Restore folders"
mv /config/addons_config/qBittorrent /config/addons_config/qBittorrent_old
mv /config/addons_config/qbittorrent /config/addons_config/qBittorrent
fi

View File

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

View File

@@ -0,0 +1,96 @@
#!/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
if [ -f /homeassistant/addons_config/qBittorrent/qBittorrent.conf ]; then
bashio::log.warning "----------------------------------------"
bashio::log.warning "Migrating configuration to the new addon"
bashio::log.warning "----------------------------------------"
mv /homeassistant/addons_config/qBittorrent/*.json /config/qBittorrent/config/
mv /homeassistant/addons_config/qBittorrent/*.conf /config/qBittorrent/config/
if [ -d /homeassistant/addons_config/qBittorrent/rss ]; then mv /homeassistant/addons_config/qBittorrent/rss /config/qBittorrent/config/; fi
mv /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
rm -r /homeassistant/addons_config/qBittorrent
bashio::log.yellow "... moved files from /config/addons_config/qBittorrent to /addon_configs/$HOSTNAME/qBitorrent (must be accessed with my Filebrowser addon)"
fi
if [ -d /homeassistant/openvpn ]; then
if [ "$(ls -A /homeassistant/openvpn)" ]; then
mv /homeassistant/openvpn/* /config/openvpn/
rm -r /homeassistant/openvpn
bashio::log.yellow "... moved files from /config/openvpn to /addon_configs/$HOSTNAME/openvpn"
fi
fi
if [ -f /homeassistant/addons_config/qbittorrent/config.yaml ]; then
mv /homeassistant/addons_config/qbittorrent/* /config/
rm -r /homeassistant/addons_config/qbittorrent
bashio::log.yellow "... moved config.yaml from /config/addons_config/qbittorrent to /addon_configs/$HOSTNAME"
fi
if [ -f /homeassistant/addons_autoscrips/qbittorrent.sh ]; then
mv /homeassistant/addons_autoscrips/qbittorrent.sh /config/
bashio::log.yellow "... moved qbittorrent.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME"
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"
fi
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"
fi
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"
fi
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"
fi
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"
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
mv "$openvpn_config" /config/openvpn/
fi
fi
if [ -d /config/qBittorrent/qBittorrent ]; then
rm -r /config/qBittorrent/qBittorrent
fi

View File

@@ -7,7 +7,7 @@ set -e
##########
# Define preferences line
CONFIG_LOCATION=/config/addons_config/qBittorrent
CONFIG_LOCATION=/config/qBittorrent/config/
mkdir -p "$CONFIG_LOCATION"
# copy default config
@@ -19,9 +19,8 @@ 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)"
###########
# TIMEOUT #
@@ -68,20 +67,16 @@ chown -R "$PUID:$PGID" "$DOWNLOADS" || bashio::log.fatal "Error, please check de
sed -i -e '/CSRFProtection/d' \
-e '/ClickjackingProtection/d' \
-e '/HostHeaderValidation/d' \
-e '/WebUI\Address/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 '/WebUI\ReverseProxySupportEnabled/d' qBittorrent.conf
#sed -i "$LINE i\WebUI\\\ReverseProxySupportEnabled=true" qBittorrent.conf
-e "$LINE i\WebUI\\\Address=\*" 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
################
@@ -110,7 +105,7 @@ fi
cd "$CONFIG_LOCATION"/ || true
WHITELIST="$(bashio::config 'whitelist')"
WHITELIST="$(bashio::config 'LAN_NETWORK')"
#clean data
sed -i '/AuthSubnetWhitelist/d' qBittorrent.conf
@@ -128,22 +123,45 @@ fi
###############
cd "$CONFIG_LOCATION"/ || true
if bashio::config.has_value 'Username'; then
USERNAME=$(bashio::config 'Username')
#clean data
sed -i '/WebUI\\\Username/d' qBittorrent.conf
#add data
sed -i "/\[Preferences\]/a\WebUI\\\Username=$USERNAME" qBittorrent.conf
bashio::log.info "WEBUI username set to $USERNAME"
if bashio::config.has_value 'QBT_USERNAME'; then
QBT_USERNAME=$(bashio::config 'QBT_USERNAME')
else
if ! grep -q Username qBittorrent.conf; then
sed -i "/\[Preferences\]/a\WebUI\\\Username=admin" qBittorrent.conf
fi
QBT_USERNAME="admin"
fi
LINE2="$(sed -n '/Password_PBKDF2/=' qBittorrent.conf)"
if [[ "$LINE" -gt "$LINE2" ]]; then sed -i '/Password_PBKDF2/d' qBittorrent.conf; fi
if ! grep -q Password_PBKDF2 qBittorrent.conf; then
sed -i "/\[Preferences\]/a\WebUI\\\Password_PBKDF2=\"@ByteArray(cps93Gf8ma8EM3QRon+spg==:wYFoMNVmdiqzWYQ6mFrvET+RRbBSIPVfXFFeEy0ZEagxvNuEF7uGVnG5iq8oeu38kGLtmJqCM2w8cTdtORDP2A==)\"" qBittorrent.conf
#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"
###############
# PASSWORD #
###############
# Set initial password to homeassistant
cd "$CONFIG_LOCATION"/ || true
NEEDREBOOT=""
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
NEEDREBOOT=true
fi
####################
# REBOOT IF NEEDED #
####################
# Reboot if first time password is set, or if password is changed
# Check file size
if [[ "$ORIGINAL_SIZE" != "$(wc -c "$CONFIG_LOCATION"/qBittorrent.conf)" ]]; then
bashio::log.info "Configuration changed, rebooting"
bashio::addon.restart
fi
@@ -217,5 +235,5 @@ fi
# CLOSE #
##########
bashio::log.info "Default username/password : $USERNAME/homeassistant"
bashio::log.info "Default username/password : $QBT_USERNAME/homeassistant. Please change your password on first connection"
bashio::log.info "Configuration can be found in $CONFIG_LOCATION"

View File

@@ -0,0 +1,31 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
if bashio::config.true "qbit_manage"; then
bashio::log.info "qbit_manage activated, setting system"
# Set folder
echo "... setting folder"
mkdir -p /config/qbit_manage
chmod -R 777 /config/qbit_manage
# Create default file
if [ ! -f /config/qbit_manage/qbit_manage.yml ]; then
echo "... create default file"
cp /qbit_manage/config/config.yml.sample /config/qbit_manage/qbit_manage.yml
fi
# Set qBittorrent options
echo "... align QBT username and password"
sed -i "/host:/c\ host: \"localhost:8080\"" /config/qbit_manage/qbit_manage.yml
sed -i "/user:/c\ user: \"$(bashio::config "QBT_USERNAME")\"" /config/qbit_manage/qbit_manage.yml
sed -i "s=root_dir: \"/data/torrents/\"=$(bashio::config.has_value "SavePath")=g" /config/qbit_manage/qbit_manage.yml
sed -i "s=remote_dir: \"/mnt/user/data/torrents/\"=$(bashio::config.has_value "SavePath")=g" /config/qbit_manage/qbit_manage.yml
# Startup delay 30s ; config file specific ; log file specific
python /qbit_manage/qbit_manage.py -sd 30 --config-file "/config/qbit_manage/qbit_manage.yml" --log-file "/config/qbit_manage/qbit_manage.log" & true
bashio::log.info "qbit_manage started with config in /addon_configs/$HOSTNAME/qbit_manage/qbit_manage.yaml accessible with the Filebrowser addon"
fi

View File

@@ -1,118 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
# ==============================================================================
declare openvpn_config
declare openvpn_username
declare openvpn_password
QBT_CONFIG_FILE="/config/addons_config/qBittorrent/qBittorrent.conf"
if bashio::config.true 'openvpn_enabled'; then
bashio::log.info "Configuring openvpn"
# Get current ip
curl -s ipecho.net/plain > /currentip
#####################
# 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}"
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
# 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
bashio::log.info "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/addons_config/qBittorrent/ || exit 1
LINE=$(sed -n '/\[Preferences\]/=' "$QBT_CONFIG_FILE")
LINE=$((LINE + 1))
SESSION=$(sed -n '/\[BitTorrent\]/=' "$QBT_CONFIG_FILE")
# 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 "$LINE i\Connection\\\Interface=tun0" "$QBT_CONFIG_FILE"
sed -i "$LINE i\Connection\\\InterfaceName=tun0" "$QBT_CONFIG_FILE"
if [ "$SESSION" != "" ]; then
SESSION=$((SESSION + 1))
sed -i "$SESSION i\Session\\\Interface=tun0" "$QBT_CONFIG_FILE"
sed -i "$SESSION i\Session\\\InterfaceName=tun0" "$QBT_CONFIG_FILE"
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"
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