From a9302a946530ac0e0a4154094e55f4fd18f06ed8 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 31 Oct 2021 13:55:17 +0100 Subject: [PATCH] Json repair script --- .../rootfs/etc/cont-init.d/19-json_repair.sh | 32 +++++++++++++++++++ transmission/rootfs/etc/cont-init.d/20-config | 24 ++++---------- 2 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 transmission/rootfs/etc/cont-init.d/19-json_repair.sh diff --git a/transmission/rootfs/etc/cont-init.d/19-json_repair.sh b/transmission/rootfs/etc/cont-init.d/19-json_repair.sh new file mode 100644 index 000000000..0dc21638d --- /dev/null +++ b/transmission/rootfs/etc/cont-init.d/19-json_repair.sh @@ -0,0 +1,32 @@ +!/bin/bash + +JSONTOCHECK='/config/transmission/settings.json' +JSONSOURCE='/defaults/settings.json' + +# If json already exists +if [ -f ${JSONTOCHECK} ]; then + # Variables + echo "Checking settings.json format" + + # Get the default keys from the original file + mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) + + # Check if all keys are still there, or add them + for KEYS in ${arr[@]}; do + KEYSTHERE=$(jq "has(\"${KEYS}\")" ${JSONTOCHECK}) + [ $KEYSTHERE != "true" ] && sed -i "3 i\"${KEYS}\": null," ${JSONTOCHECK} && echo "... $KEYS was missing, added" + done + + # Show structure in a nice way + jq . -S ${JSONTOCHECK} | cat >temp.json && mv temp.json ${JSONTOCHECK} +fi + +# Repair structure +################ +#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 diff --git a/transmission/rootfs/etc/cont-init.d/20-config b/transmission/rootfs/etc/cont-init.d/20-config index 175682fd6..800ec6666 100644 --- a/transmission/rootfs/etc/cont-init.d/20-config +++ b/transmission/rootfs/etc/cont-init.d/20-config @@ -14,6 +14,7 @@ CONFIGDIR="/config/transmission" ############### # PERMISSIONS # ############### + #Default folders echo "Updating folders" mkdir -p /config/transmission || true @@ -24,9 +25,12 @@ if ! bashio::fs.file_exists "$CONFIGDIR/settings.json"; then cp "/defaults/settings.json" "$CONFIGDIR/settings.json" fi -################ -# Alternate UI # -################ +################# +# CONFIGURATION # +################# + +# Alternate UI +############## if bashio::config.has_value 'customUI'; then ### Variables @@ -39,20 +43,6 @@ if bashio::config.has_value 'customUI'; then fi bashio::log.info "UI selected : $CUSTOMUI" -################# -# CONFIGURATION # -################# - -# Repair structure -################ -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 ################