summaryrefslogtreecommitdiffstats
path: root/src/substvars.sh
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-23 12:59:54 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-23 12:59:54 (EDT)
commit7ef055e48c966fc1171cd60f3e9f34a18d47f91d (patch)
treeeeffbb7e0dc847c7c511e35994594a9b480ebd86 /src/substvars.sh
parentd41f612da5d6624398f9ddd84369c67f150f246f (diff)
set_substvar(): Sync with opkbuild
Diffstat (limited to 'src/substvars.sh')
-rw-r--r--src/substvars.sh41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/substvars.sh b/src/substvars.sh
index 60d1402..36ec308 100644
--- a/src/substvars.sh
+++ b/src/substvars.sh
@@ -1,6 +1,6 @@
# Functions for setting and substituting variables
#
-# Copyright (C) 2012, 2014 Patrick "P. J." McDermott
+# Copyright (C) 2012, 2014, 2019 Patrick McDermott
#
# This file is part of the ProteanOS Development Kit.
#
@@ -19,36 +19,33 @@
# <http://www.gnu.org/licenses/>.
SUBSTVARS_MAX_DEPTH=50
+SUBSTVAR_TRIM_SED='
+ H; # Store each input line in the hold space.
+ ${ # At the last line of input:
+ g; # restore the hold space into the pattern space,
+ s/^[\n]*//; # remove leading newline characters,
+ s/[\n]*$//; # remove trailing newline characters, and
+ p; # print the results.
+ };
+'
set_substvar()
{
local name="${1}"
local value="${2}"
- # Convert variable name to lower case and validate.
- name="$(printf '%s\n' "${name}" | tr 'A-Z-' 'a-z_')"
- case "${name:- }" in
- *[!a-z0-9_]*)
- warn "$(get_msg 'substvar_invalid')" "${name}"
- return 1
- ;;
+ # Validate variable name and convert to lower case.
+ case "${name}" in *[!A-Za-z0-9-]* | '')
+ warn "$(get_msg 'substvar_invalid')" "${name}"
+ return 1
+ ;;
esac
+ name="$(printf '%s' "${name}" | tr 'A-Z-' 'a-z_')"
- # Trim leading and trailing newline characters from value.
- value="$(printf '%s\n' "${value}" | sed -n '
- H; # Store each input line in the hold space.
- ${ # At the last line of input:
- g; # Restore the hold space into the pattern space.
- s/^[\n]*//; # Remove leading newline characters.
- s/[\n]*$//; # Remove trailing newline characters.
- p; # Print the results.
- };
- ')"
-
- # Escape single quotes in value.
- value="$(printf '%s\n' "${value}" | sed "s/'/'\\\\''/g")"
+ # Trim leading and trailing whitespace from value.
+ value="$(printf '%s' "${value}" | sed -n "${SUBSTVAR_TRIM_SED}")"
- eval "substvar_${name}='${value}'"
+ eval "substvar_${name}=\"\${value}\""
return 0
}