Function to lookup variables in config.txt

This commit is contained in:
Philip Homburg
2020-06-23 10:28:15 -04:00
parent ec73955993
commit 4685d07795
3 changed files with 23 additions and 8 deletions
+2 -8
View File
@@ -21,15 +21,9 @@ fi
. $BIN_DIR/common.sh
# config variables
CONFIG_TXT="$BASE_DIR/state/config.txt"
# Look for options in config.txt
if [ -f "$CONFIG_TXT" ]
if [ $(config_lookup RXTXRPT no) = yes ]
then
if grep "^[ ]*RXTXRPT=yes" "$CONFIG_TXT"
then
do_rxtxrpt=yes
fi
do_rxtxrpt=yes
fi
$MOUNT_FS_CMD
+20
View File
@@ -176,3 +176,23 @@ hash_ssh_pubkey()
tr -d '\n' | sha256sum)
expr "$hash" : "\(.\{16\}\)"
}
config_lookup()
{
key="$1"
default_value="$2"
# Look for options in config.txt
if [ ! -f "$CONFIG_TXT" ]
then
echo "$default_value"
return
fi
value=$(sed < "$CONFIG_TXT" -n "s/^[ ]*$key=\(.*\)/\1/p" |
head -1 | sed 's/[ ]*$//')
if [ -n "$value" ]
then
echo "$value"
else
echo "$default_value"
fi
}
+1
View File
@@ -11,3 +11,4 @@ RUN_DIR=$BASE_DIR/run
CON_KEEP_PID=con_keep_pid.vol
RESOLV_CONF_STATIC='/etc/resolv.conf.static'
REG_INIT_REPLY=$STATUS_DIR/reg_init_reply.txt
CONFIG_TXT="$BASE_DIR/state/config.txt"