improve selective status update which makes most preset values unnecessary

This commit is contained in:
2016-12-26 15:10:29 +01:00
parent 1984a70b99
commit 0b871f8099
2 changed files with 7 additions and 5 deletions

View File

@@ -3,10 +3,7 @@ TMP=/tmp/status
# Default values when first starting the tool
var_conn="on"
var_mailqueue_runs=9
var_ip4=127.0.0.1
var_ip6=::1
var_vpn="off"
var_mailqueue_runs=0
# status-ip.sh
IPSERV4="http://returns.plain-ipv4"

View File

@@ -26,7 +26,12 @@ function wtmp {
VAR_NAME=${!i} # variable name
VAR_VAL=${!VAR_NAME} # value of the variable's name
sed -Ei "s/^$VAR_NAME=.*/$VAR_NAME=$VAR_VAL/" $TMP
if [ $(grep -q "^$VAR_NAME=" $TMP; echo $?) == 0 ] ; then # variable already exists in status file
sed -Ei "s/^$VAR_NAME=.*/$VAR_NAME=$VAR_VAL/" $TMP
else
echo "$VAR_NAME=$VAR_VAL" >> $TMP
fi
done
fi