mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-15 17:08:19 +01:00
Json repair script
This commit is contained in:
32
transmission/rootfs/etc/cont-init.d/19-json_repair.sh
Normal file
32
transmission/rootfs/etc/cont-init.d/19-json_repair.sh
Normal file
@@ -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
|
||||
@@ -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
|
||||
################
|
||||
|
||||
|
||||
Reference in New Issue
Block a user