mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-05 00:24:58 +02:00
133 lines
4.4 KiB
Plaintext
133 lines
4.4 KiB
Plaintext
#!/usr/bin/with-contenv bashio
|
|
|
|
declare CONFIG
|
|
declare incomplete_bool
|
|
declare download_dir
|
|
declare incomplete_dir
|
|
declare USER
|
|
declare PASS
|
|
declare WHITELIST
|
|
declare HOST_WHITELIST
|
|
|
|
###############
|
|
# PERMISSIONS #
|
|
###############
|
|
#Default folders
|
|
echo "Updating folders"
|
|
mkdir -p /config/transmission || true
|
|
chown -R abc:abc /config/transmission || true
|
|
|
|
if ! bashio::fs.file_exists '/config/transmission/settings.json'; then
|
|
echo "Creating default config"
|
|
cp "/defaults/settings.json" "/config/transmission/settings.json"
|
|
fi
|
|
|
|
#################
|
|
# CONFIGURATION #
|
|
#################
|
|
# Variables
|
|
echo "Creating config"
|
|
download_dir=$(bashio::config 'download_dir')
|
|
incomplete_dir=$(bashio::config 'incomplete_dir')
|
|
CONFIG=$(</config/transmission/settings.json)
|
|
|
|
# Permissions
|
|
echo "Updating permissions"
|
|
mkdir -p $download_dir
|
|
chown abc:abc $download_dir
|
|
|
|
# if incomplete dir > 2, to allow both null and '', set it as existing
|
|
if [ ${#incomplete_dir} -ge 2 ]; then
|
|
echo "Incomplete dir set: $incomplete_dir"
|
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=true")
|
|
mkdir -p $incomplete_dir
|
|
chown abc:abc $incomplete_dir
|
|
else
|
|
echo "Incomplete dir disabled"
|
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=false")
|
|
fi
|
|
|
|
# Defaults
|
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir\"=\"${incomplete_dir}\"")
|
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"download-dir\"=\"${download_dir}\"")
|
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-whitelist-enabled\"=false")
|
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-host-whitelist-enabled\"=false")
|
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"bind-address-ipv4\"=\"0.0.0.0\"")
|
|
|
|
echo "${CONFIG}" > /config/transmission/settings.json
|
|
|
|
################
|
|
# Alternate UI #
|
|
################
|
|
|
|
if bashio::config.has_value 'customUI'; then
|
|
### Variables
|
|
CUSTOMUI=$(bashio::config 'customUI')
|
|
if [ "$CUSTOMUI" != "flood-for-transmission" ]; then
|
|
echo "Setting custom UI"
|
|
mv /flood-for-transmission /a
|
|
mv /$CUSTOMUI /flood-for-transmission
|
|
fi
|
|
fi
|
|
bashio::log.info "UI selected : $CUSTOMUI"
|
|
|
|
#####################
|
|
# net.core.rmem_max #
|
|
#####################
|
|
|
|
SIZE="4194304"
|
|
# If net.core.rmem_max present in /etc/sysctl.conf, change value to "$SIZE"
|
|
# else, add "net.core.rmem_max = $SIZE" to /etc/sysctl.conf
|
|
if grep --silent ^net.core.rmem_max /etc/sysctl.conf; then
|
|
sed -i 's/^net.core.rmem_max.*/net.core.rmem_max = '$SIZE'/g' /etc/sysctl.conf
|
|
else
|
|
echo "" >> /etc/sysctl.conf
|
|
echo "net.core.rmem_max = $SIZE" >> /etc/sysctl.conf
|
|
fi
|
|
|
|
####################
|
|
# From linuxserver #
|
|
####################
|
|
|
|
# USER and PASS
|
|
###############
|
|
|
|
# Clean lines
|
|
#sed -i "/rpc-authentication-required/d" /config/transmission/settings.json
|
|
#sed -i "/rpc-username/d" /config/transmission/settings.json
|
|
#sed -i "/rpc-password/d" /config/transmission/settings.json
|
|
|
|
# Set lines
|
|
#if bashio::config.has_value 'user'; then
|
|
# USER=$(bashio::config 'user')
|
|
# PASS=$(bashio::config 'pass')
|
|
# sed -i "2 i\"rpc-authentication-required\": true," /config/transmission/settings.json
|
|
# sed -i "2 i\"rpc-username\": \"$USER\"," /config/transmission/settings.json
|
|
# sed -i "2 i\"rpc-password\": \"$PASS\"," /config/transmission/settings.json
|
|
# bashio::log.info "User & Pass set, authentification will be with user : $USER and pass : $PASS"
|
|
#else
|
|
# sed -i "2 i\"rpc-authentication-required\": false," /config/transmission/settings.json
|
|
# bashio::log.warning "User & Pass not set, no authentification required"
|
|
#fi
|
|
|
|
# WHITELIST
|
|
###########
|
|
|
|
#sed -i "/whitelist/d" /config/transmission/settings.json
|
|
#if bashio::config.has_value 'whitelist'; then
|
|
# WHITELIST=$(bashio::config 'whitelist')
|
|
# bashio::log.info "Whitelist set, no authentification from IP $WHITELIST"
|
|
# sed -i "2 i\"rpc-whitelist-enabled\": true," /config/transmission/settings.json
|
|
# sed -i "2 i\"rpc-whitelist\": \"$WHITELIST\"," /config/transmission/settings.json
|
|
#else
|
|
# sed -i "2 i\"rpc-whitelist-enabled\": false," /config/transmission/settings.json
|
|
#fi
|
|
|
|
#if [ ! -z "$HOST_WHITELIST" ]; then
|
|
# sed -i '/rpc-host-whitelist-enabled/c\ "rpc-host-whitelist-enabled": true,' /config/transmission/settings.json
|
|
# sed -i "/\"rpc-host-whitelist\"/c\ \"rpc-host-whitelist\": \"$HOST_WHITELIST\"," /config/transmission/settings.json
|
|
#else
|
|
# sed -i '/rpc-host-whitelist-enabled/c\ "rpc-host-whitelist-enabled": false,' /config/transmission/settings.json
|
|
# sed -i "/\"rpc-host-whitelist\"/c\ \"rpc-host-whitelist\": \"$HOST_WHITELIST\"," /config/transmission/settings.json
|
|
#fi
|