common.sh: Handle single quotes in load_environment_var()

This is used to read version.txt, which was written with single quotes
when Jenkins reverted a build. These quotes were then erroneously
written into /etc/os-release, which caused havoc. This has already been
addressed in jenkins-os, but let's make this code more robust anyway.

Fix this by grepping out the lines we need (in one go) and actually
parsing them with Bash. Less safe, but we already parse version.txt with
Bash in other places.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
This commit is contained in:
James Le Cuirot 2026-04-03 17:41:04 +01:00
parent 44bd310fb7
commit 874ed2576d
No known key found for this signature in database
GPG Key ID: 1226415D00DD3137

View File

@ -296,12 +296,10 @@ load_environment_allowlist() {
}
load_environment_var() {
local file="$1" name value
shift
for name in "$@"; do
value=$(grep "^${name}=" "${file}" | sed 's|"||g')
[[ -n "${value}" ]] && export "${value}"
done
local file="$1"; shift
unset "${@}"
. <(grep -f <(printf "^%s=\n" "${@}") "${file}")
export "${@}"
}
# Find root of source tree