summaryrefslogtreecommitdiff
path: root/functions/configuration.sh
diff options
context:
space:
mode:
authorLyndon Brown <jnqnfe@gmail.com>2020-02-20 06:58:11 +0000
committerLyndon Brown <jnqnfe@gmail.com>2020-03-16 22:10:03 +0000
commitc55eb8a0c3ca5b8ed1081e7eb8a423563288fb58 (patch)
tree6ea61f7291b27ce9e22b40c5593c6ab6f54555d2 /functions/configuration.sh
parentaf040d78035b88aaf2f99f38bf5f0db176c92d0a (diff)
downloadvyos-live-build-c55eb8a0c3ca5b8ed1081e7eb8a423563288fb58.tar.gz
vyos-live-build-c55eb8a0c3ca5b8ed1081e7eb8a423563288fb58.zip
use local scope for private function vars
all vars affected have been carefully checked to be quite certain that they are definitely local where variable is assigned the return value of a function/command, the local "declaration" is deliberately done on a separate line, since `local FOO` is actually treated itself as a command rather than a declaration; will thus always cause $? to be zero, and thus if done on the same line as such an assignment can not only clobber $? but in doing so unintentionally blocks failure of a command from triggering the expected exit from having `set -e`. also, from testing, i have found that when assigning "${@}" this must be done on a separate line confusingly as otherwise an error occurs. Gbp-Dch: Short
Diffstat (limited to 'functions/configuration.sh')
-rwxr-xr-xfunctions/configuration.sh23
1 files changed, 12 insertions, 11 deletions
diff --git a/functions/configuration.sh b/functions/configuration.sh
index 0fb84a962..70faa62a1 100755
--- a/functions/configuration.sh
+++ b/functions/configuration.sh
@@ -11,29 +11,30 @@
Get_configuration ()
{
- _CONFIGURATION_FILE="${1}"
- _FIELD_NAME="${2}"
+ local CONFIGURATION_FILE="${1}"
+ local FIELD_NAME="${2}"
+ local FIELD_BODY
- if [ -e "${_CONFIGURATION_FILE}" ]
+ if [ -e "${CONFIGURATION_FILE}" ]
then
- _FIELD_BODY="$(grep ^${_FIELD_NAME}: ${_CONFIGURATION_FILE} | awk '{ $1=""; print $0 }' | sed -e 's|^ ||')"
+ FIELD_BODY="$(grep ^${FIELD_NAME}: ${CONFIGURATION_FILE} | awk '{ $1=""; print $0 }' | sed -e 's|^ ||')"
fi
- echo ${_FIELD_BODY}
+ echo ${FIELD_BODY}
}
Set_configuration ()
{
- _CONFIGURATION_FILE="${1}"
- _FIELD_NAME="${2}"
- _FIELD_BODY="${3}"
+ local CONFIGURATION_FILE="${1}"
+ local FIELD_NAME="${2}"
+ local FIELD_BODY="${3}"
- if grep -qs "^${_FIELD_NAME}:" "${_CONFIGURATION_FILE}"
+ if grep -qs "^${FIELD_NAME}:" "${CONFIGURATION_FILE}"
then
# Update configuration
- sed -i -e "s|^${_FIELD_NAME}:.*$|${_FIELD_NAME}: ${_FIELD_BODY}|" "${_CONFIGURATION_FILE}"
+ sed -i -e "s|^${FIELD_NAME}:.*$|${FIELD_NAME}: ${FIELD_BODY}|" "${CONFIGURATION_FILE}"
else
# Append configuration
- echo "${_FIELD_NAME}: ${_FIELD_BODY}" >> "${_CONFIGURATION_FILE}"
+ echo "${FIELD_NAME}: ${FIELD_BODY}" >> "${CONFIGURATION_FILE}"
fi
}