This commit is contained in:
2021-06-29 12:37:08 +03:00
commit 12fdc96d20
282 changed files with 13627 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# Displays a simple add-on banner on startup
# ==============================================================================
if bashio::supervisor.ping; then
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue " Add-on: $(bashio::addon.name)"
bashio::log.blue " $(bashio::addon.description)"
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue " Add-on version: $(bashio::addon.version)"
if bashio::var.true "$(bashio::addon.update_available)"; then
bashio::log.magenta ' There is an update available for this add-on!'
bashio::log.magenta \
" Latest add-on version: $(bashio::addon.version_latest)"
bashio::log.magenta ' Please consider upgrading as soon as possible.'
else
bashio::log.green ' You are running the latest version of this add-on.'
fi
bashio::log.blue " System: $(bashio::info.operating_system)" \
" ($(bashio::info.arch) / $(bashio::info.machine))"
bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue \
' Please, share the above information when looking for help'
bashio::log.blue \
' or support in, e.g., GitHub, forums or the Discord chat.'
bashio::log.green \
' https://github.com/alexbelgium/hassio-addons'
bashio::log.blue \
'-----------------------------------------------------------'
fi

View File

@@ -0,0 +1,38 @@
#!/usr/bin/with-contenv bashio
#################
# NGINX SETTING #
#################
declare admin_port
declare qbittorrent_protocol=http
# Generate Ingress configuration
if bashio::config.true 'ssl'; then
qbittorrent_protocol=https
fi
bashio::var.json \
interface "$(bashio::addon.ip_address)" \
port "^$(bashio::addon.ingress_port)" \
protocol "${qbittorrent_protocol}" \
certfile "$(bashio::config 'certfile')" \
keyfile "$(bashio::config 'keyfile')" \
ssl "^$(bashio::config 'ssl')" \
| tempio \
-template /etc/nginx/templates/ingress.gtpl \
-out /etc/nginx/servers/ingress.conf
######################
# VUETORRENT INSTALL #
######################
LATEST_RELEASE=$(curl -s -L https://api.github.com/repos/wdaan/vuetorrent/releases/latest \
| grep "browser_download_url.*zip" \
| cut -d : -f 2,3 \
| tr -d \" \
| xargs)
curl -s -S -O -J -L $LATEST_RELEASE
unzip -o vuetorrent.zip -d / >/dev/null
rm /vuetorrent.zip >/dev/null

View File

@@ -0,0 +1,28 @@
#!/usr/bin/with-contenv bashio
###############
# DNS SETTING #
###############
# Avoid usage of local dns such as adguard home or pihole\n"
if bashio::config.has_value 'DNS_server'; then
# Define variables
DNSSERVER=$(bashio::config 'DNS_server')
DNS=""
DNSLIST=""
# Get DNS servers
for server in ${DNSSERVER//,/ } # Separate comma separated values
do
DNS="${DNS}nameserver $server\n"
DNSLIST="$server $DNSLIST"
done
# Write resolv.conf
printf "${DNS}" > /etc/resolv.conf
chmod 644 /etc/resolv.conf
bashio::log.info "DNS SERVERS set to $DNSLIST"
else
bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers."
fi

View File

@@ -0,0 +1,128 @@
#!/usr/bin/with-contenv bashio
##########
# INIT #
##########
# Define preferences line
cd /config/qBittorrent/
LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
LINE=$((LINE + 1))
##################
# Default folder #
##################
if bashio::config.has_value 'SavePath'; then
DOWNLOADS=$(bashio::config 'SavePath')
sed -i '/SavePath/d' qBittorrent.conf
sed -i "$LINE i\Downloads\\\SavePath=$DOWNLOADS" qBittorrent.conf
mkdir -p $DOWNLOADS || true
chown -R abc:abc $DOWNLOADS || bashio::log.info "Error, please check default save folder configuration in addon"
bashio::log.info "Downloads can be found in $DOWNLOADS"
else
mkdir -p /share/qBittorrent || true
chown -R abc:abc /share/qBittorrent
fi
################
# Correct Port #
################
sed -i '/PortRangeMin/d' qBittorrent.conf
sed -i "$LINE i\Connection\\\PortRangeMin=6881" qBittorrent.conf
################
# 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')
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/qBittorrent/
if bashio::config.has_value 'whitelist'; then
WHITELIST=$(bashio::config 'whitelist')
#clean data
sed -i '/AuthSubnetWhitelist/d' qBittorrent.conf
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"
fi
###############
# USERNAME #
###############
cd /config/qBittorrent/
if bashio::config.has_value 'Username'; then
USERNAME=$(bashio::config 'Username')
#clean data
sed -i '/WebUI\\\Username/d' qBittorrent.conf
#add data
sed -i "$LINE i\WebUI\\\Username=$USERNAME" qBittorrent.conf
bashio::log.info "WEBUI username set to $USERNAME"
fi
################
# Alternate UI #
################
# Clean data
sed -i '/AlternativeUIEnabled/d' qBittorrent.conf
sed -i '/RootFolder/d' qBittorrent.conf
rm -f -r /webui
mkdir -p /webui
chown abc:abc /webui
if bashio::config.has_value 'customUI'; then
### Variables
CUSTOMUI=$(bashio::config 'customUI')
bashio::log.info "Alternate UI enabled : $CUSTOMUI. If webui don't work, disable this option"
### Download WebUI
case $CUSTOMUI in
"vuetorrent")
curl -s -S -J -L -o /webui/release.zip $(curl -s https://api.github.com/repos/WDaan/VueTorrent/releases/latest | grep -o "http.*vuetorrent.zip") >/dev/null
;;
"qbit-matUI")
curl -s -S -J -L -o /webui/release.zip $(curl -s https://api.github.com/repos/bill-ahmed/qbit-matUI/releases/latest | grep -o "http.*Unix.*.zip") >/dev/null
;;
"qb-web")
curl -s -S -J -L -o /webui/release.zip $(curl -s https://api.github.com/repos/CzBiX/qb-web/releases | grep -o "http.*qb-web-.*zip") >/dev/null
;;
esac
### 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/qBittorrent/qBittorrent.conf
sed -i "$LINE i\WebUI\\\RootFolder=$CUSTOMUIDIR" /config/qBittorrent/qBittorrent.conf
fi
##########
# CLOSE #
##########
bashio::log.info "Default username/password : admin/adminadmin"
bashio::log.info "Configuration can be found in /config/qBittorrent"

View File

@@ -0,0 +1,62 @@
#!/usr/bin/with-contenv bashio
####################
# MOUNT SMB SHARES #
####################
if bashio::config.has_value 'networkdisks'; then
# Mount CIFS Share if configured and if Protection Mode is active
bashio::log.info 'Mounting smb share(s)...'
# Define variables
MOREDISKS=$(bashio::config 'networkdisks')
CIFS_USERNAME=$(bashio::config 'cifsusername')
CIFS_PASSWORD=$(bashio::config 'cifspassword')
MOUNTED=false
SMBVERS=""
SECVERS=""
if bashio::config.has_value 'cifsdomain'; then
DOMAIN=",domain=$(bashio::config 'cifsdomain')"
else
DOMAIN=""
fi
# Mounting disks
for disk in ${MOREDISKS//,/ } # Separate comma separated values
do
# Clean name of network share
disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name
diskname=${disk//\\//} #replace \ with /
diskname=${diskname##*/} # Get only last part of the name
# Prepare mount point
mkdir -p /mnt/$diskname
chown -R root:root /mnt/$diskname
#Tries to mount with default options
mount -t cifs -o rw,username=$CIFS_USERNAME,password=${CIFS_PASSWORD}$DOMAIN $disk /mnt/$diskname 2>ERRORCODE && MOUNTED=true || MOUNTED=false
# if Fail test different smb and sec versions
if [ $MOUNTED = false ]; then
for SMBVERS in ",vers=3" ",vers=1.0" ",vers=2.1" ",vers=3.0" ",nodfs" ",uid=0,gid=0,forceuid,forcegid" ",noforceuid,noforcegid" ",${DOMAIN}"
do
mount -t cifs -o rw,iocharset=utf8,file_mode=0777,dir_mode=0777,username=$CIFS_USERNAME,password=${CIFS_PASSWORD}$SMBVERS $disk /mnt/$diskname 2>/dev/null && MOUNTED=true && break || MOUNTED=false
for SECVERS in ",sec=ntlmi" ",sec=ntlmv2" ",sec=ntlmv2i" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=ntlm" ",sec=krb5i" ",sec=krb5"
do
mount -t cifs -o rw,iocharset=utf8,file_mode=0777,dir_mode=0777,username=$CIFS_USERNAME,password=${CIFS_PASSWORD}$SMBVERS$SECVERS $disk /mnt/$disk name 2>/dev/null && MOUNTED=true && break 2 && break || MOUNTED=false
done
done
fi
# Messages
if [ $MOUNTED = true ]; then
#Test write permissions
touch /mnt/$diskname/testaze && rm /mnt/$diskname/testaze && bashio::log.info "... $disk successfully mounted to /mnt/$diskname with options $SMBVERS$SECVERS" || bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check UID/GID for permissions, and if the share is rw"
else
# message if still fail
bashio::log.fatal "Unable to mount $disk to /mnt/$diskname with username $CIFS_USERNAME, $CIFS_PASSWORD. Please check your remote share path, username, password, domain, try putting 0 in UID and GID" # Mount share
bashio::log.fatal "Error read : $(<ERRORCODE)" # Mount share
rm ERRORCODE
fi
done
fi

View File

@@ -0,0 +1,83 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
declare openvpn_config
declare openvpn_username
declare openvpn_password
if bashio::config.true 'openvpn_enabled'; then
bashio::log.info "Configuring openvpn"
#####################
# 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 #
#########################
QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf"
# Define preferences line
cd /config/qBittorrent/
LINE=$(sed -n '/Preferences/=' qBittorrent.conf)
LINE=$((LINE + 1))
# If qBittorrent.conf exists
if [ -f "$QBT_CONFIG_FILE" ]; then
# Remove previous line and bind tun0
sed -i '/Interface/d' qBittorrent.conf
# sed -i '/PortRangeMin/d' qBittorrent.conf
# Bind tun0
# sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf
# sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf
else
bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options "
exit 1
fi
#####################
# ALTERNATIVE MODE #
#####################
if bashio::config.true 'openvpn_alternative_mode'; then
# Remove previous line and bind tun0
sed -i '/Interface/d' qBittorrent.conf
# Bind tun0
sed -i "$LINE i\Connection\\\Interface=tun0" qBittorrent.conf
sed -i "$LINE i\Connection\\\InterfaceName=tun0" qBittorrent.conf
# Modify ovpn config
echo "route-nopull" >> /etc/openvpn/config.ovpn
fi
else
##################
# REMOVE OPENVPN #
##################
# Ensure no redirection by removing the direction tag
cd /config/qBittorrent/
sed -i '/Interface/d' qBittorrent.conf
bashio::log.info "Direct connection without VPN enabled"
fi