2
0
mirror of https://github.com/deajan/osync synced 2024-11-11 07:10:40 +00:00

Improved config file upgrade script

This commit is contained in:
deajan 2019-05-19 12:56:41 +02:00
parent e64ec1232e
commit 26b661396a

View File

@ -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