From 26b661396aed3e92cf0c755ee1008cc12e29e3e8 Mon Sep 17 00:00:00 2001 From: deajan Date: Sun, 19 May 2019 12:56:41 +0200 Subject: [PATCH] Improved config file upgrade script --- upgrade-v1.0x-v1.3x.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/upgrade-v1.0x-v1.3x.sh b/upgrade-v1.0x-v1.3x.sh index 1b5fb4a..89d0b9d 100755 --- a/upgrade-v1.0x-v1.3x.sh +++ b/upgrade-v1.0x-v1.3x.sh @@ -7,7 +7,7 @@ CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" OLD_PROGRAM_VERSION="v1.0x-v1.2x" NEW_PROGRAM_VERSION="v1.3x" CONFIG_FILE_REVISION=1.3.0 -PROGRAM_BUILD=2016121101 +PROGRAM_BUILD=2019051801 ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode if ! type "$BASH" > /dev/null; then @@ -515,15 +515,15 @@ function AddMissingConfigOptionsAndFixBooleans { echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]" else # Not the most elegant but the quickest way :) - if [ "${VALUES[$counter]}" == true ]; then + if grep "^{$KEYWORDS[$counter]}=yes" > /dev/null "$config_file"; then sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=true/g' "$config_file" if [ $? -ne 0 ]; then echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to true." exit 1 fi - elif [ "${VALUES[$counter]}" == false ]; then + elif grep "^{$KEYWORDS[$counter]}=no" > /dev/null "$config_file"; then if [ $? -ne 0 ]; then - echo "Cannot ${[KEYWORDS[$counter]} boolean to false." + echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to false." exit 1 fi sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=false/g' "$config_file" @@ -550,10 +550,12 @@ function RewriteSections { function UpdateConfigHeader { local config_file="${1}" - # "onfig file rev" to deal with earlier variants of the file where c was lower or uppercase - sed -i'.tmp' 's/.*onfig file rev.*//' "$config_file" - sed -i'.tmp' '/^\[GENERAL\]$/a\'$'\n'CONFIG_FILE_REVISION=$CONFIG_FILE_REVISION$'\n''' "$config_file" - rm -f "$config_file.tmp" + if ! grep "^CONFIG_FILE_REVISION=" > /dev/null "$config_file"; then + # "onfig file rev" to deal with earlier variants of the file where c was lower or uppercase + sed -i'.tmp' 's/.*onfig file rev.*//' "$config_file" + sed -i'.tmp' '/^\[GENERAL\]$/a\'$'\n'CONFIG_FILE_REVISION=$CONFIG_FILE_REVISION$'\n''' "$config_file" + rm -f "$config_file.tmp" + fi } _QUICK_SYNC=0