Add check for missing elements and work through each array element regardless how it's spelt.
This commit is contained in:
parent
880b371d2c
commit
643af6b3a0
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# This script is inefficient by design, each setting is applied separately so that any that fail are easily identified and don't affect any of the others.
|
||||||
|
|
||||||
declare -A DOCKER_OPT
|
declare -A DOCKER_OPT
|
||||||
|
|
||||||
|
|
@ -69,15 +71,28 @@ DOCKER_OPT[65]='.["default-addresses-pools"] = [{"base":"172.80.0.0/16","size":2
|
||||||
|
|
||||||
if [ ! -f /tmp/daemon.json ]
|
if [ ! -f /tmp/daemon.json ]
|
||||||
then
|
then
|
||||||
touch /tmp/daemon.json
|
|
||||||
echo "{}" > /tmp/daemon.json
|
echo "{}" > /tmp/daemon.json
|
||||||
else
|
else
|
||||||
echo "/tmp/daemon.json exists."
|
echo "/tmp/daemon.json exists."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
for ((i = 0; i < ${#DOCKER_OPT[@]}; ++i)); do
|
# Count through the number of array elements, using ${#
|
||||||
|
# looking for one missing.
|
||||||
|
for ((i = 1; i < ${#DOCKER_OPT[@]}; ++i)); do
|
||||||
|
if [ -z "${DOCKER_OPT[$i]}" ]; then
|
||||||
|
echo Error: $i missing.
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Work through each array element, using ${!.
|
||||||
|
# regardless how it's spelled.
|
||||||
|
for i in "${!DOCKER_OPT[@]}"; do
|
||||||
OPTION="${DOCKER_OPT[$i]}"
|
OPTION="${DOCKER_OPT[$i]}"
|
||||||
jq "${OPTION}" /tmp/daemon.json > /tmp/daemon.json.new && \
|
jq "${OPTION}" /tmp/daemon.json > /tmp/daemon.json.new && \
|
||||||
mv -b /tmp/daemon.json.new /tmp/daemon.json
|
mv -b /tmp/daemon.json.new /tmp/daemon.json
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
cat /tmp/daemon.json | jq
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue