mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-12 02:21:28 +02:00
Functional code
This commit is contained in:
@@ -9,17 +9,19 @@ declare PASS
|
|||||||
declare WHITELIST
|
declare WHITELIST
|
||||||
declare HOST_WHITELIST
|
declare HOST_WHITELIST
|
||||||
|
|
||||||
|
CONFIGDIR="/config/transmission"
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# PERMISSIONS #
|
# PERMISSIONS #
|
||||||
###############
|
###############
|
||||||
#Default folders
|
#Default folders
|
||||||
echo "Updating folders"
|
echo "Updating folders"
|
||||||
mkdir -p /config/transmission || true
|
mkdir -p /config/transmission || true
|
||||||
chown -R abc:abc /config/transmission || true
|
chown -R abc:abc /config/transmission || true
|
||||||
|
|
||||||
if ! bashio::fs.file_exists '/config/transmission/settings.json'; then
|
if ! bashio::fs.file_exists "$CONFIGDIR/settings.json"; then
|
||||||
echo "Creating default config"
|
echo "Creating default config"
|
||||||
cp "/defaults/settings.json" "/config/transmission/settings.json"
|
cp "/defaults/settings.json" "$CONFIGDIR/settings.json"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
################
|
################
|
||||||
@@ -35,91 +37,88 @@ if bashio::config.has_value 'customUI'; then
|
|||||||
mv /$CUSTOMUI /flood-for-transmission
|
mv /$CUSTOMUI /flood-for-transmission
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
bashio::log.info "UI selected : $CUSTOMUI"
|
bashio::log.info "UI selected : $CUSTOMUI"
|
||||||
|
|
||||||
#################
|
#################
|
||||||
# CONFIGURATION #
|
# CONFIGURATION #
|
||||||
#################
|
#################
|
||||||
|
|
||||||
# Repair structure
|
# Repair structure
|
||||||
jq . /config/transmission/settings.json | cat > temp.json && mv temp.json /config/transmission/settings.json
|
################
|
||||||
|
jq . -S $CONFIGDIR/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json
|
||||||
|
echo "Making sure settings.json structure is good"
|
||||||
|
for KEYS in "incomplete-dir" "download-dir" "rpc-host-whitelist-enabled" "rpc-authentication-required" "rpc-username" "rpc-password" "rpc-whitelist-enabled" "rpc-whitelist"; do
|
||||||
|
KEYSTHERE=$(jq "has(\"${KEYS}\")" $CONFIGDIR/settings.json)
|
||||||
|
[ $KEYSTHERE != true ] && sed -i "3 i\"${KEYS}\": null," $CONFIGDIR/settings.json
|
||||||
|
echo "... $KEYS was missing, added"
|
||||||
|
done
|
||||||
|
jq . -S $CONFIGDIR/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json
|
||||||
|
|
||||||
# INCOMPLETE DIR
|
# INCOMPLETE DIR
|
||||||
################
|
################
|
||||||
|
|
||||||
echo "Creating config"
|
echo "Creating config"
|
||||||
download_dir=$(bashio::config 'download_dir')
|
download_dir=$(bashio::config 'download_dir')
|
||||||
incomplete_dir=$(bashio::config 'incomplete_dir')
|
incomplete_dir=$(bashio::config 'incomplete_dir')
|
||||||
CONFIG=$(</config/transmission/settings.json)
|
CONFIG=$(<$CONFIGDIR/settings.json)
|
||||||
|
|
||||||
# Permissions
|
# Permissions
|
||||||
echo "Updating permissions"
|
echo "Updating permissions"
|
||||||
mkdir -p $download_dir
|
mkdir -p $download_dir
|
||||||
chown abc:abc $download_dir
|
chown abc:abc $download_dir
|
||||||
|
|
||||||
# if incomplete dir > 2, to allow both null and '', set it as existing
|
# if incomplete dir > 2, to allow both null and '', set it as existing
|
||||||
if [ ${#incomplete_dir} -ge 2 ]; then
|
if [ ${#incomplete_dir} -ge 2 ]; then
|
||||||
echo "Incomplete dir set: $incomplete_dir"
|
echo "Incomplete dir set: $incomplete_dir"
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=true")
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=true")
|
||||||
mkdir -p $incomplete_dir
|
mkdir -p $incomplete_dir
|
||||||
chown abc:abc $incomplete_dir
|
chown abc:abc $incomplete_dir
|
||||||
else
|
else
|
||||||
echo "Incomplete dir disabled"
|
echo "Incomplete dir disabled"
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=false")
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=false")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Defaults
|
# Defaults
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir\"=\"${incomplete_dir}\"")
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir\"=\"${incomplete_dir}\"")
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"download-dir\"=\"${download_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}" ".\"rpc-host-whitelist-enabled\"=false")
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"bind-address-ipv4\"=\"0.0.0.0\"")
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"bind-address-ipv4\"=\"0.0.0.0\"")
|
||||||
|
|
||||||
echo "${CONFIG}" > /config/transmission/settings.json
|
echo "${CONFIG}" >$CONFIGDIR/settings.json &&
|
||||||
jq . /config/transmission/settings.json | cat > temp.json && mv temp.json /config/transmission/settings.json
|
jq . -S $CONFIGDIR/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json
|
||||||
|
|
||||||
# USER and PASS
|
# USER and PASS
|
||||||
###############
|
###############
|
||||||
|
|
||||||
CONFIG=$(</config/transmission/settings.json)
|
CONFIG=$(<$CONFIGDIR/settings.json)
|
||||||
USER=$(bashio::config 'user')
|
USER=$(bashio::config 'user')
|
||||||
PASS=$(bashio::config 'pass')
|
PASS=$(bashio::config 'pass')
|
||||||
if bashio::config.has_value 'user'; then
|
if bashio::config.has_value 'user'; then
|
||||||
BOOLEAN=true
|
BOOLEAN=true
|
||||||
bashio::log.info "User & Pass set, authentification will be with user : $USER and pass : $PASS"
|
bashio::log.info "User & Pass set, authentification will be with user : $USER and pass : $PASS"
|
||||||
else
|
else
|
||||||
BOOLEAN=false
|
BOOLEAN=false
|
||||||
bashio::log.warning "User & Pass not set, no authentification required"
|
bashio::log.warning "User & Pass not set, no authentification required"
|
||||||
fi
|
fi
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-authentication-required\"=${BOOLEAN}") || sed -i "3 i\"rpc-authentication-required\": ${BOOLEAN}," /config/transmission/settings.json
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-authentication-required\"=${BOOLEAN}")
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-username\"=\"${USER}\"") || sed -i "3 i\"rpc-username\": \"$USER\"," /config/transmission/settings.json
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-username\"=\"${USER}\"")
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-username\"=\"${PASS}\"") || sed -i "3 i\"rpc-password\": \"$PASS\"," /config/transmission/settings.json
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-username\"=\"${PASS}\"")
|
||||||
echo "${CONFIG}" > /config/transmission/settings.json
|
echo "${CONFIG}" >$CONFIGDIR/settings.json &&
|
||||||
jq . /config/transmission/settings.json | cat > temp.json && mv temp.json /config/transmission/settings.json
|
jq . -S $CONFIGDIR/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json
|
||||||
|
|
||||||
# WHITELIST
|
# WHITELIST
|
||||||
###########
|
###########
|
||||||
|
|
||||||
CONFIG=$(</config/transmission/settings.json)
|
CONFIG=$(<$CONFIGDIR/settings.json)
|
||||||
WHITELIST=$(bashio::config 'whitelist')
|
WHITELIST=$(bashio::config 'whitelist')
|
||||||
if bashio::config.has_value 'whitelist'; then
|
if bashio::config.has_value 'whitelist'; then
|
||||||
BOOLEAN=true
|
BOOLEAN=true
|
||||||
bashio::log.info "Whitelist set, no authentification from IP $WHITELIST"
|
bashio::log.info "Whitelist set, no authentification from IP $WHITELIST"
|
||||||
else
|
else
|
||||||
BOOLEAN=false
|
BOOLEAN=false
|
||||||
sed -i "2 i\"rpc-whitelist-enabled\": false," /config/transmission/settings.json
|
sed -i "2 i\"rpc-whitelist-enabled\": false," $CONFIGDIR/settings.json
|
||||||
fi
|
fi
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-whitelist-enabled\"=${BOOLEAN}") || sed -i "3 i\"rpc-whitelist-enabled\": ${BOOLEAN}," /config/transmission/settings.json
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-whitelist-enabled\"=${BOOLEAN}")
|
||||||
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-whitelist\"=\"$WHITELIST\"") || sed -i "3 i\"rpc-whitelist\": \"$WHITELIST\"," /config/transmission/settings.json
|
CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-whitelist\"=\"$WHITELIST\"")
|
||||||
echo "${CONFIG}" > /config/transmission/settings.json
|
echo "${CONFIG}" >$CONFIGDIR/settings.json &&
|
||||||
jq . /config/transmission/settings.json | cat > temp.json && mv temp.json /config/transmission/settings.json
|
jq . -S $CONFIGDIR/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
echo "${CONFIG}" > /config/transmission/settings.json
|
|
||||||
|
|||||||
Reference in New Issue
Block a user