mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-08 08:35:57 +02:00
fix: auto-fix linting issues
This commit is contained in:
committed by
github-actions[bot]
parent
e5adbd266f
commit
f728166b14
@@ -9,51 +9,51 @@ 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
|
||||
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
|
||||
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
|
||||
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"
|
||||
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"
|
||||
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
|
||||
bashio::log.warning "Options were changed, restarting the addon"
|
||||
sleep 5
|
||||
bashio::addon.restart
|
||||
fi
|
||||
|
||||
@@ -16,7 +16,7 @@ declare qbittorrent_protocol=http
|
||||
|
||||
# Generate Ingress configuration
|
||||
if bashio::config.true 'ssl'; then
|
||||
qbittorrent_protocol=https
|
||||
qbittorrent_protocol=https
|
||||
fi
|
||||
|
||||
[ "$DEBUG" = "debug" ] && echo "Before cp"
|
||||
|
||||
@@ -12,7 +12,7 @@ mkdir -p "$CONFIG_LOCATION"
|
||||
|
||||
# copy default config
|
||||
if [ ! -f "$CONFIG_LOCATION"/qBittorrent.conf ]; then
|
||||
cp /defaults/qBittorrent.conf "$CONFIG_LOCATION"/qBittorrent.conf
|
||||
cp /defaults/qBittorrent.conf "$CONFIG_LOCATION"/qBittorrent.conf
|
||||
fi
|
||||
|
||||
cd "$CONFIG_LOCATION"/ || true
|
||||
@@ -31,9 +31,9 @@ ORIGINAL_SIZE="$(wc -c "$CONFIG_LOCATION"/qBittorrent.conf)"
|
||||
###########
|
||||
|
||||
if bashio::config.has_value 'run_duration'; then
|
||||
echo "Timer mode set"
|
||||
echo "Timer mode set"
|
||||
else
|
||||
rm -r /etc/services.d/timer
|
||||
rm -r /etc/services.d/timer
|
||||
fi
|
||||
|
||||
##################
|
||||
@@ -43,26 +43,25 @@ fi
|
||||
# Set configuration
|
||||
if bashio::config.has_value 'SavePath'; then
|
||||
|
||||
# Set variable
|
||||
DOWNLOADS=$(bashio::config 'SavePath')
|
||||
DOWNLOADS=${DOWNLOADS:-/share/downloads} # Default if not set
|
||||
# Set variable
|
||||
DOWNLOADS=$(bashio::config 'SavePath')
|
||||
DOWNLOADS=${DOWNLOADS:-/share/downloads} # Default if not set
|
||||
|
||||
# Replace save path
|
||||
sed -i -e "/SavePath/d" \
|
||||
-e "/\[Preferences\]/a Downloads\\\SavePath=$DOWNLOADS" \
|
||||
-e "/\[AutoRun\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \
|
||||
-e "/\[Preferences\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \
|
||||
-e "/\[BitTorrent\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \
|
||||
-e "/\[BitTorrent\]/a Session\\\DefaultSavePath=$DOWNLOADS" qBittorrent.conf
|
||||
# Replace save path
|
||||
sed -i -e "/SavePath/d" \
|
||||
-e "/\[Preferences\]/a Downloads\\\SavePath=$DOWNLOADS" \
|
||||
-e "/\[AutoRun\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \
|
||||
-e "/\[Preferences\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \
|
||||
-e "/\[BitTorrent\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \
|
||||
-e "/\[BitTorrent\]/a Session\\\DefaultSavePath=$DOWNLOADS" qBittorrent.conf
|
||||
|
||||
|
||||
# Info
|
||||
bashio::log.info "Downloads can be found in $DOWNLOADS"
|
||||
# Info
|
||||
bashio::log.info "Downloads can be found in $DOWNLOADS"
|
||||
fi
|
||||
|
||||
# Create default location
|
||||
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"
|
||||
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"
|
||||
|
||||
@@ -71,13 +70,13 @@ 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 "/\[Preferences\]/a \WebUI\\\CSRFProtection=false" \
|
||||
-e "/\[Preferences\]/a \WebUI\\\ClickjackingProtection=false" \
|
||||
-e "/\[Preferences\]/a \WebUI\\\HostHeaderValidation=false" \
|
||||
-e "/\[Preferences\]/a \WebUI\\\Address=\*" qBittorrent.conf
|
||||
-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
|
||||
@@ -99,15 +98,15 @@ 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')
|
||||
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
|
||||
#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
|
||||
|
||||
################
|
||||
@@ -124,12 +123,12 @@ WHITELIST="${WHITELIST//,/,\ }"
|
||||
sed -i '/AuthSubnetWhitelist/d' qBittorrent.conf
|
||||
|
||||
if [[ "${#WHITELIST}" -gt 5 ]]; then
|
||||
sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=true" qBittorrent.conf
|
||||
sed -i "$LINE i\WebUI\\\AuthSubnetWhitelist=$WHITELIST" qBittorrent.conf
|
||||
bashio::log.info "Whitelisted subsets will not require a password : $WHITELIST"
|
||||
sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=true" qBittorrent.conf
|
||||
sed -i "$LINE i\WebUI\\\AuthSubnetWhitelist=$WHITELIST" qBittorrent.conf
|
||||
bashio::log.info "Whitelisted subsets will not require a password : $WHITELIST"
|
||||
else
|
||||
sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=false" qBittorrent.conf
|
||||
bashio::log.info "Whitelisted subsets deactivated"
|
||||
sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=false" qBittorrent.conf
|
||||
bashio::log.info "Whitelisted subsets deactivated"
|
||||
fi
|
||||
|
||||
###############
|
||||
@@ -138,9 +137,9 @@ fi
|
||||
|
||||
cd "$CONFIG_LOCATION"/ || true
|
||||
if bashio::config.has_value 'Username'; then
|
||||
USERNAME="$(bashio::config 'Username')"
|
||||
USERNAME="$(bashio::config 'Username')"
|
||||
else
|
||||
USERNAME="admin"
|
||||
USERNAME="admin"
|
||||
fi
|
||||
|
||||
#clean data
|
||||
@@ -151,7 +150,7 @@ bashio::log.info "WEBUI username set to $USERNAME"
|
||||
|
||||
# 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
|
||||
sed -i "/\[Preferences\]/a\WebUI\\\Password_PBKDF2=\"@ByteArray(cps93Gf8ma8EM3QRon+spg==:wYFoMNVmdiqzWYQ6mFrvET+RRbBSIPVfXFFeEy0ZEagxvNuEF7uGVnG5iq8oeu38kGLtmJqCM2w8cTdtORDP2A==)\"" qBittorrent.conf
|
||||
fi
|
||||
|
||||
####################
|
||||
@@ -162,9 +161,9 @@ 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
|
||||
bashio::log.warning "Configuration changed, rebooting"
|
||||
sleep 5
|
||||
bashio::addon.restart
|
||||
fi
|
||||
|
||||
################
|
||||
@@ -175,62 +174,62 @@ CUSTOMUI=$(bashio::config 'customUI')
|
||||
|
||||
# Clean data if not custom
|
||||
if [ ! "$CUSTOMUI" = custom ]; then
|
||||
sed -i '/AlternativeUIEnabled/d' qBittorrent.conf
|
||||
sed -i '/RootFolder/d' qBittorrent.conf
|
||||
rm -f -r /webui
|
||||
mkdir -p /webui
|
||||
chown "$PUID:$PGID" /webui
|
||||
sed -i '/AlternativeUIEnabled/d' qBittorrent.conf
|
||||
sed -i '/RootFolder/d' qBittorrent.conf
|
||||
rm -f -r /webui
|
||||
mkdir -p /webui
|
||||
chown "$PUID:$PGID" /webui
|
||||
fi
|
||||
|
||||
# Clean data if not custom
|
||||
if [ "$CUSTOMUI" = default ]; then
|
||||
echo ""
|
||||
bashio::log.warning "Default Webui selected ! It will not work for ingress, which will stay with vuetorrent"
|
||||
echo ""
|
||||
sed -i '/AlternativeUIEnabled/d' qBittorrent.conf
|
||||
sed -i '/RootFolder/d' qBittorrent.conf
|
||||
# Update ingress webui
|
||||
curl -f -s -S -O -J -L "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null
|
||||
unzip -o vuetorrent.zip -d / >/dev/null
|
||||
rm vuetorrent.zip
|
||||
echo ""
|
||||
bashio::log.warning "Default Webui selected ! It will not work for ingress, which will stay with vuetorrent"
|
||||
echo ""
|
||||
sed -i '/AlternativeUIEnabled/d' qBittorrent.conf
|
||||
sed -i '/RootFolder/d' qBittorrent.conf
|
||||
# Update ingress webui
|
||||
curl -f -s -S -O -J -L "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null
|
||||
unzip -o vuetorrent.zip -d / >/dev/null
|
||||
rm vuetorrent.zip
|
||||
fi
|
||||
|
||||
# Install webui
|
||||
if bashio::config.has_value 'customUI' && [ ! "$CUSTOMUI" = default ] && [ ! "$CUSTOMUI" = custom ]; then
|
||||
### Variables
|
||||
bashio::log.info "Alternate UI enabled : $CUSTOMUI. If webui don't work, disable this option"
|
||||
### Variables
|
||||
bashio::log.info "Alternate UI enabled : $CUSTOMUI. If webui don't work, disable this option"
|
||||
|
||||
### Download WebUI
|
||||
case $CUSTOMUI in
|
||||
"vuetorrent")
|
||||
curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases/latest | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null
|
||||
;;
|
||||
### Download WebUI
|
||||
case $CUSTOMUI in
|
||||
"vuetorrent")
|
||||
curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases/latest | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null
|
||||
;;
|
||||
|
||||
"qbit-matUI")
|
||||
curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/bill-ahmed/qbit-matUI/releases/latest | grep -o "http.*Unix.*.zip" | head -1)" >/dev/null
|
||||
echo ""
|
||||
bashio::log.warning "qbit-matUI selected ! It will not work for ingress, which will stay with vuetorrent"
|
||||
echo ""
|
||||
;;
|
||||
"qbit-matUI")
|
||||
curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/bill-ahmed/qbit-matUI/releases/latest | grep -o "http.*Unix.*.zip" | head -1)" >/dev/null
|
||||
echo ""
|
||||
bashio::log.warning "qbit-matUI selected ! It will not work for ingress, which will stay with vuetorrent"
|
||||
echo ""
|
||||
;;
|
||||
|
||||
"qb-web")
|
||||
curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/CzBiX/qb-web/releases | grep -o "http.*qb-web-.*zip" | head -1)" >/dev/null
|
||||
;;
|
||||
"qb-web")
|
||||
curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/CzBiX/qb-web/releases | grep -o "http.*qb-web-.*zip" | head -1)" >/dev/null
|
||||
;;
|
||||
|
||||
esac || { bashio::log.warning "$CUSTOMUI could not be downloaded, please raise an issue on the github repository. The default UI will be used" && exit 0 ; }
|
||||
esac || { bashio::log.warning "$CUSTOMUI could not be downloaded, please raise an issue on the github repository. The default UI will be used" && exit 0; }
|
||||
|
||||
### Install WebUI
|
||||
mkdir -p /webui/"$CUSTOMUI"
|
||||
unzip -q /webui/release.zip -d /webui/"$CUSTOMUI"
|
||||
rm /webui/*.zip
|
||||
CUSTOMUIDIR="$(dirname "$(find /webui/"$CUSTOMUI" -iname "public" -type d)")"
|
||||
sed -i "$LINE i\WebUI\\\AlternativeUIEnabled=true" "$CONFIG_LOCATION"/qBittorrent.conf
|
||||
sed -i "$LINE i\WebUI\\\RootFolder=$CUSTOMUIDIR" "$CONFIG_LOCATION"/qBittorrent.conf
|
||||
# Set ingress ui
|
||||
if [[ "$CUSTOMUI" != qbit-matUI ]]; then
|
||||
sed -i "s=/vuetorrent/public/=$CUSTOMUIDIR/public/=g" /etc/nginx/servers/ingress.conf || true
|
||||
sed -i "s=vue.torrent=$CUSTOMUI.torrent=g" /etc/nginx/servers/ingress.conf || true
|
||||
fi
|
||||
### Install WebUI
|
||||
mkdir -p /webui/"$CUSTOMUI"
|
||||
unzip -q /webui/release.zip -d /webui/"$CUSTOMUI"
|
||||
rm /webui/*.zip
|
||||
CUSTOMUIDIR="$(dirname "$(find /webui/"$CUSTOMUI" -iname "public" -type d)")"
|
||||
sed -i "$LINE i\WebUI\\\AlternativeUIEnabled=true" "$CONFIG_LOCATION"/qBittorrent.conf
|
||||
sed -i "$LINE i\WebUI\\\RootFolder=$CUSTOMUIDIR" "$CONFIG_LOCATION"/qBittorrent.conf
|
||||
# Set ingress ui
|
||||
if [[ "$CUSTOMUI" != qbit-matUI ]]; then
|
||||
sed -i "s=/vuetorrent/public/=$CUSTOMUIDIR/public/=g" /etc/nginx/servers/ingress.conf || true
|
||||
sed -i "s=vue.torrent=$CUSTOMUI.torrent=g" /etc/nginx/servers/ingress.conf || true
|
||||
fi
|
||||
fi
|
||||
|
||||
##########
|
||||
|
||||
@@ -4,37 +4,38 @@ set -e
|
||||
|
||||
if bashio::config.true "qbit_manage"; then
|
||||
|
||||
bashio::log.info "qbit_manage activated, setting system"
|
||||
bashio::log.info "qbit_manage activated, setting system"
|
||||
|
||||
# Set folder
|
||||
echo "... setting folder"
|
||||
mkdir -p /config/qbit_manage
|
||||
chmod -R 777 /config/qbit_manage
|
||||
# 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
|
||||
# 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"
|
||||
# qBittorrent path to local
|
||||
echo "... default url set to 127.0.0.1, change manually if you have an external qbt system"
|
||||
sed -i "s/localhost/127.0.0.1/g" /config/qbit_manage/qbit_manage.yml
|
||||
# Set password from options
|
||||
echo "... setting username to the addon options one"
|
||||
sed -i "/user:/c\ user: '$(bashio::config 'Username')'" /config/qbit_manage/qbit_manage.yml
|
||||
# If password is default, correct
|
||||
echo "... default password set to homeassistant, change manually in the file if not"
|
||||
sed -i "/pass: password/c\ pass: homeassistant" /config/qbit_manage/qbit_manage.yml
|
||||
# Set root dir
|
||||
echo "... downloads directory set to $(bashio::config 'SavePath')"
|
||||
sed -i "/ root_dir/d" /config/qbit_manage/qbit_manage.yml
|
||||
sed -i "/directory:/a\ root_dir: \"$(bashio::config 'SavePath')\"" /config/qbit_manage/qbit_manage.yml
|
||||
# Set qBittorrent options
|
||||
echo "... align QBT username and password"
|
||||
# qBittorrent path to local
|
||||
echo "... default url set to 127.0.0.1, change manually if you have an external qbt system"
|
||||
sed -i "s/localhost/127.0.0.1/g" /config/qbit_manage/qbit_manage.yml
|
||||
# Set password from options
|
||||
echo "... setting username to the addon options one"
|
||||
sed -i "/user:/c\ user: '$(bashio::config 'Username')'" /config/qbit_manage/qbit_manage.yml
|
||||
# If password is default, correct
|
||||
echo "... default password set to homeassistant, change manually in the file if not"
|
||||
sed -i "/pass: password/c\ pass: homeassistant" /config/qbit_manage/qbit_manage.yml
|
||||
# Set root dir
|
||||
echo "... downloads directory set to $(bashio::config 'SavePath')"
|
||||
sed -i "/ root_dir/d" /config/qbit_manage/qbit_manage.yml
|
||||
sed -i "/directory:/a\ root_dir: \"$(bashio::config 'SavePath')\"" /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"
|
||||
# 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
|
||||
|
||||
@@ -10,260 +10,260 @@ 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 "----------------------------"
|
||||
bashio::log.info "----------------------------"
|
||||
bashio::log.info "Openvpn enabled, configuring"
|
||||
bashio::log.info "----------------------------"
|
||||
|
||||
# Get current ip
|
||||
curl -s ipecho.net/plain > /currentip
|
||||
# Get current ip
|
||||
curl -s ipecho.net/plain >/currentip
|
||||
|
||||
# Function to check for files path
|
||||
function check_path () {
|
||||
# Function to check for files path
|
||||
function check_path() {
|
||||
|
||||
# Get variable
|
||||
file="$1"
|
||||
# Get variable
|
||||
file="$1"
|
||||
|
||||
# Double check exists
|
||||
if [ ! -f "$file" ]; then
|
||||
bashio::warning "$file not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check each lines
|
||||
cp "$file" /tmpfile
|
||||
line_number=0
|
||||
while read -r line; do
|
||||
# Increment the line number
|
||||
((line_number=line_number+1))
|
||||
# Double check exists
|
||||
if [ ! -f "$file" ]; then
|
||||
bashio::warning "$file not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if lines starting with auth-user-pass have a valid argument
|
||||
###################################################################
|
||||
if [[ "$line" == "auth-user-pass"* ]]; then
|
||||
# Extract the second argument
|
||||
file_name="$(echo "$line" | awk -F' ' '{print $2}')"
|
||||
# If second argument is null or -
|
||||
if [ -z "$file_name" ] || [[ "$file_name" == -* ]]; then
|
||||
# Insert to explain why a comment is made
|
||||
sed -i "${line_number}i # The following line is commented out as does not contain a valid argument" "$file"
|
||||
# Increment as new line added
|
||||
((line_number=line_number+1))
|
||||
# Comment out the line
|
||||
sed -i "${line_number}s/^/# /" "$file"
|
||||
# Go to next line
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if the line contains a txt file
|
||||
#######################################
|
||||
if [[ ! $line =~ ^"#" ]] && [[ ! $line =~ ^";" ]] && [[ "$line" == *" "*"."* ]] || [[ "$line" == "auth-user-pass"* ]]; then
|
||||
# Extract the txt file name from the line
|
||||
file_name="$(echo "$line" | awk -F' ' '{print $2}')"
|
||||
# if contains only numbers and dots it is likely an ip, don't check it
|
||||
if [[ "$file_name" =~ ^[0-9\.]+$ ]]; then
|
||||
continue
|
||||
fi
|
||||
# Check if the txt file exists
|
||||
if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [ ! -f "$file_name" ]; then
|
||||
# Check if the txt file exists in the /config/openvpn/ directory
|
||||
if [ -f "/config/openvpn/${file_name##*/}" ]; then
|
||||
# Append /config/openvpn/ in front of the original txt file in the ovpn file
|
||||
sed -i "${line_number}s|$file_name|/config/openvpn/${file_name##*/}|" "$file"
|
||||
# Print a success message
|
||||
bashio::log.warning "Appended /config/openvpn/ to ${file_name##*/} in $file"
|
||||
else
|
||||
# Print an error message
|
||||
bashio::log.warning "$file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < /tmpfile
|
||||
rm /tmpfile
|
||||
# Check each lines
|
||||
cp "$file" /tmpfile
|
||||
line_number=0
|
||||
while read -r line; do
|
||||
# Increment the line number
|
||||
((line_number = line_number + 1))
|
||||
|
||||
# Standardize lf
|
||||
dos2unix "$file"
|
||||
# Check if lines starting with auth-user-pass have a valid argument
|
||||
###################################################################
|
||||
if [[ "$line" == "auth-user-pass"* ]]; then
|
||||
# Extract the second argument
|
||||
file_name="$(echo "$line" | awk -F' ' '{print $2}')"
|
||||
# If second argument is null or -
|
||||
if [ -z "$file_name" ] || [[ "$file_name" == -* ]]; then
|
||||
# Insert to explain why a comment is made
|
||||
sed -i "${line_number}i # The following line is commented out as does not contain a valid argument" "$file"
|
||||
# Increment as new line added
|
||||
((line_number = line_number + 1))
|
||||
# Comment out the line
|
||||
sed -i "${line_number}s/^/# /" "$file"
|
||||
# Go to next line
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Remove custom up & down
|
||||
sed -i '/^up /s/^/#/' "$file"
|
||||
sed -i '/^down /s/^/#/' "$file"
|
||||
# Check if the line contains a txt file
|
||||
#######################################
|
||||
if [[ ! $line =~ ^"#" ]] && [[ ! $line =~ ^";" ]] && [[ "$line" == *" "*"."* ]] || [[ "$line" == "auth-user-pass"* ]]; then
|
||||
# Extract the txt file name from the line
|
||||
file_name="$(echo "$line" | awk -F' ' '{print $2}')"
|
||||
# if contains only numbers and dots it is likely an ip, don't check it
|
||||
if [[ "$file_name" =~ ^[0-9\.]+$ ]]; then
|
||||
continue
|
||||
fi
|
||||
# Check if the txt file exists
|
||||
if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [ ! -f "$file_name" ]; then
|
||||
# Check if the txt file exists in the /config/openvpn/ directory
|
||||
if [ -f "/config/openvpn/${file_name##*/}" ]; then
|
||||
# Append /config/openvpn/ in front of the original txt file in the ovpn file
|
||||
sed -i "${line_number}s|$file_name|/config/openvpn/${file_name##*/}|" "$file"
|
||||
# Print a success message
|
||||
bashio::log.warning "Appended /config/openvpn/ to ${file_name##*/} in $file"
|
||||
else
|
||||
# Print an error message
|
||||
bashio::log.warning "$file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done </tmpfile
|
||||
rm /tmpfile
|
||||
|
||||
# Remove blank lines
|
||||
sed -i '/^[[:blank:]]*$/d' "$file"
|
||||
# Standardize lf
|
||||
dos2unix "$file"
|
||||
|
||||
# Ensure config ends with a line feed
|
||||
sed -i "\$q" "$file"
|
||||
# Remove custom up & down
|
||||
sed -i '/^up /s/^/#/' "$file"
|
||||
sed -i '/^down /s/^/#/' "$file"
|
||||
|
||||
# Correct paths
|
||||
sed -i "s=/etc/openvpn=/config/openvpn=g" "$file"
|
||||
sed -i "s=/config/openvpn/credentials=/etc/openvpn/credentials=g" "$file"
|
||||
# Remove blank lines
|
||||
sed -i '/^[[:blank:]]*$/d' "$file"
|
||||
|
||||
}
|
||||
# Ensure config ends with a line feed
|
||||
sed -i "\$q" "$file"
|
||||
|
||||
#####################
|
||||
# CONFIGURE OPENVPN #
|
||||
#####################
|
||||
# Correct paths
|
||||
sed -i "s=/etc/openvpn=/config/openvpn=g" "$file"
|
||||
sed -i "s=/config/openvpn/credentials=/etc/openvpn/credentials=g" "$file"
|
||||
|
||||
# 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"
|
||||
else
|
||||
bashio::exit.nok "Configured ovpn file : $openvpn_config is set but does not end by .ovpn ; it can't be used!"
|
||||
fi
|
||||
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 /config/openvpn/*.ovpn > /dev/null 2>&1; 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}. Other available files :"
|
||||
printf '%s\n' "${VPN_CONFIGS[@]}"
|
||||
# If openvpn_enabled set, config not set, and openvpn folder empty
|
||||
else
|
||||
bashio::exit.nok "openvpn_enabled is set, however, your openvpn folder is empty ! Are you sure you added it in /addon_configs/$HOSTNAME/openvpn using the Filebrowser addon ?"
|
||||
fi
|
||||
#####################
|
||||
# CONFIGURE OPENVPN #
|
||||
#####################
|
||||
|
||||
# Send to openvpn script
|
||||
sed -i "s|/config/openvpn/config.ovpn|/config/openvpn/$openvpn_config|g" /etc/s6-overlay/s6-rc.d/svc-qbittorrent/run
|
||||
|
||||
# Check path
|
||||
check_path /config/openvpn/"${openvpn_config}"
|
||||
# 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"
|
||||
else
|
||||
bashio::exit.nok "Configured ovpn file : $openvpn_config is set but does not end by .ovpn ; it can't be used!"
|
||||
fi
|
||||
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
|
||||
|
||||
# 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
|
||||
# If openvpn_config not set, but folder is not empty
|
||||
elif ls /config/openvpn/*.ovpn >/dev/null 2>&1; 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}. Other available files :"
|
||||
printf '%s\n' "${VPN_CONFIGS[@]}"
|
||||
# If openvpn_enabled set, config not set, and openvpn folder empty
|
||||
else
|
||||
bashio::exit.nok "openvpn_enabled is set, however, your openvpn folder is empty ! Are you sure you added it in /addon_configs/$HOSTNAME/openvpn using the Filebrowser addon ?"
|
||||
fi
|
||||
|
||||
# Add credentials file
|
||||
if grep -q ^auth-user-pass /config/openvpn/"$openvpn_config" ; then
|
||||
# Credentials specified are they custom ?
|
||||
file_name="$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config" | awk -F' ' '{print $2}')"
|
||||
file_name="${file_name:-null}"
|
||||
if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [[ "$file_name" != "null" ]]; then
|
||||
if [ -f "$file_name" ]; then
|
||||
# If credential specified, exists, and is not the addon default
|
||||
bashio::log.warning "auth-user-pass specified in the ovpn file, addon username and passwords won't be used !"
|
||||
else
|
||||
# Credential referenced but doesn't exist
|
||||
bashio::log.warning "auth-user-pass $file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory. The addon will attempt to use it's own username and password instead."
|
||||
# Comment previous lines
|
||||
sed -i '/^auth-user-pass/i # specified auth-user-pass file not found, disabling' /config/openvpn/"$openvpn_config"
|
||||
sed -i '/^auth-user-pass/s/^/#/' /config/openvpn/"$openvpn_config"
|
||||
# No credentials specified, using addons username and password
|
||||
echo "# Please do not remove the line below, it allows using the addon username and password" >> /config/openvpn/"$openvpn_config"
|
||||
echo "auth-user-pass /etc/openvpn/credentials" >> /etc/openvpn/"$openvpn_config"
|
||||
fi
|
||||
else
|
||||
# Standardize just to be sure
|
||||
sed -i "/\/etc\/openvpn\/credentials/c auth-user-pass \/etc\/openvpn\/credentials" /config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
else
|
||||
# No credentials specified, using addons username and password
|
||||
echo "# Please do not remove the line below, it allows using the addon username and password" >> /config/openvpn/"$openvpn_config"
|
||||
echo "auth-user-pass /etc/openvpn/credentials" >> /config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
# Send to openvpn script
|
||||
sed -i "s|/config/openvpn/config.ovpn|/config/openvpn/$openvpn_config|g" /etc/s6-overlay/s6-rc.d/svc-qbittorrent/run
|
||||
|
||||
# Permissions
|
||||
chmod 755 /config/openvpn/*
|
||||
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/down.sh
|
||||
chmod +x /etc/openvpn/up-qbittorrent.sh
|
||||
# Check path
|
||||
check_path /config/openvpn/"${openvpn_config}"
|
||||
|
||||
echo "... openvpn correctly set, qbittorrent will run tunnelled through openvpn"
|
||||
# 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
|
||||
|
||||
#########################
|
||||
# CONFIGURE QBITTORRENT #
|
||||
#########################
|
||||
# Add credentials file
|
||||
if grep -q ^auth-user-pass /config/openvpn/"$openvpn_config"; then
|
||||
# Credentials specified are they custom ?
|
||||
file_name="$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config" | awk -F' ' '{print $2}')"
|
||||
file_name="${file_name:-null}"
|
||||
if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [[ "$file_name" != "null" ]]; then
|
||||
if [ -f "$file_name" ]; then
|
||||
# If credential specified, exists, and is not the addon default
|
||||
bashio::log.warning "auth-user-pass specified in the ovpn file, addon username and passwords won't be used !"
|
||||
else
|
||||
# Credential referenced but doesn't exist
|
||||
bashio::log.warning "auth-user-pass $file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory. The addon will attempt to use it's own username and password instead."
|
||||
# Comment previous lines
|
||||
sed -i '/^auth-user-pass/i # specified auth-user-pass file not found, disabling' /config/openvpn/"$openvpn_config"
|
||||
sed -i '/^auth-user-pass/s/^/#/' /config/openvpn/"$openvpn_config"
|
||||
# No credentials specified, using addons username and password
|
||||
echo "# Please do not remove the line below, it allows using the addon username and password" >>/config/openvpn/"$openvpn_config"
|
||||
echo "auth-user-pass /etc/openvpn/credentials" >>/etc/openvpn/"$openvpn_config"
|
||||
fi
|
||||
else
|
||||
# Standardize just to be sure
|
||||
sed -i "/\/etc\/openvpn\/credentials/c auth-user-pass \/etc\/openvpn\/credentials" /config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
else
|
||||
# No credentials specified, using addons username and password
|
||||
echo "# Please do not remove the line below, it allows using the addon username and password" >>/config/openvpn/"$openvpn_config"
|
||||
echo "auth-user-pass /etc/openvpn/credentials" >>/config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
|
||||
# WITH CONTAINER BINDING
|
||||
#########################
|
||||
# If alternative mode enabled, bind container
|
||||
if bashio::config.true 'openvpn_alt_mode'; then
|
||||
echo "Using container binding"
|
||||
# Permissions
|
||||
chmod 755 /config/openvpn/*
|
||||
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/down.sh
|
||||
chmod +x /etc/openvpn/up-qbittorrent.sh
|
||||
|
||||
# Remove interface
|
||||
echo "... deleting previous interface settings"
|
||||
sed -i '/Interface/d' "$QBT_CONFIG_FILE"
|
||||
echo "... openvpn correctly set, qbittorrent will run tunnelled through openvpn"
|
||||
|
||||
# Modify ovpn config
|
||||
if grep -q route-nopull /config/openvpn/"$openvpn_config"; then
|
||||
echo "... removing route-nopull from your config.ovpn"
|
||||
sed -i '/route-nopull/d' /config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
#########################
|
||||
# CONFIGURE QBITTORRENT #
|
||||
#########################
|
||||
|
||||
# Exit
|
||||
exit 0
|
||||
fi
|
||||
# WITH CONTAINER BINDING
|
||||
#########################
|
||||
# If alternative mode enabled, bind container
|
||||
if bashio::config.true 'openvpn_alt_mode'; then
|
||||
echo "Using container binding"
|
||||
|
||||
# WITH INTERFACE BINDING
|
||||
#########################
|
||||
# Connection with interface binding
|
||||
echo "Using interface binding in the qBittorrent app"
|
||||
# Remove interface
|
||||
echo "... deleting previous interface settings"
|
||||
sed -i '/Interface/d' "$QBT_CONFIG_FILE"
|
||||
|
||||
# Define preferences line
|
||||
cd /config/qBittorrent/ || exit 1
|
||||
# Modify ovpn config
|
||||
if grep -q route-nopull /config/openvpn/"$openvpn_config"; then
|
||||
echo "... removing route-nopull from your config.ovpn"
|
||||
sed -i '/route-nopull/d' /config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
|
||||
# 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"
|
||||
# Exit
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 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"
|
||||
# WITH INTERFACE BINDING
|
||||
#########################
|
||||
# Connection with interface binding
|
||||
echo "Using interface binding in the qBittorrent app"
|
||||
|
||||
# Add to ongoing session
|
||||
sed -i "/\[BitTorrent\]/a \Session\\\Interface=tun0" "$QBT_CONFIG_FILE"
|
||||
sed -i "/\[BitTorrent\]/a \Session\\\InterfaceName=tun0" "$QBT_CONFIG_FILE"
|
||||
# Define preferences line
|
||||
cd /config/qBittorrent/ || exit 1
|
||||
|
||||
else
|
||||
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options "
|
||||
exit 1
|
||||
fi
|
||||
# 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"
|
||||
|
||||
# Modify ovpn config
|
||||
if ! grep -q route-nopull /config/openvpn/"$openvpn_config"; then
|
||||
echo "... adding route-nopull to your config.ovpn"
|
||||
sed -i "1a route-nopull" /config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
# 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 /config/openvpn/"$openvpn_config"; then
|
||||
echo "... adding route-nopull to your config.ovpn"
|
||||
sed -i "1a route-nopull" /config/openvpn/"$openvpn_config"
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
##################
|
||||
# REMOVE OPENVPN #
|
||||
##################
|
||||
##################
|
||||
# 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"
|
||||
# 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
|
||||
|
||||
@@ -5,30 +5,30 @@
|
||||
# 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 "$@"
|
||||
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
|
||||
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\n" "IN_BACKGROUND=\"true\"" >> ~/.bashrc
|
||||
/etc/init.d/"${RC_SVCNAME}" --quiet stop
|
||||
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\n" "IN_BACKGROUND=\"true\"" >>~/.bashrc
|
||||
/etc/init.d/"${RC_SVCNAME}" --quiet stop
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -5,5 +5,5 @@ 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}"
|
||||
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${WEBUI_PORT}" \
|
||||
s6-setuidgid abc /usr/bin/qbittorrent-nox --webui-port="${WEBUI_PORT}"
|
||||
|
||||
@@ -25,44 +25,44 @@
|
||||
# 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
|
||||
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
|
||||
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
|
||||
@@ -70,18 +70,18 @@ fi
|
||||
# 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
|
||||
# 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\n" "IN_BACKGROUND=\"true\"" >> ~/.bashrc
|
||||
/etc/init.d/${RC_SVCNAME} --quiet start
|
||||
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\n" "IN_BACKGROUND=\"true\"" >>~/.bashrc
|
||||
/etc/init.d/${RC_SVCNAME} --quiet start
|
||||
fi
|
||||
fi
|
||||
|
||||
###############
|
||||
|
||||
Reference in New Issue
Block a user