mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-09-05 05:01:28 +00:00
Enable Environment Variables in Configuration File
This code change enables the use of Linux Environment variables in the configuration file. This is very useful for paths to avoid having to hard-code paths. Added Environment Variable Checking For proper use, it will also require a similar patch to the bundle-chroot-builder project. See https://github.com/clearlinux/bundle-chroot-builder/pull/12 Signed-off-by: Mark Horn <mark.d.horn@intel.com>
This commit is contained in:
+13
-1
@@ -115,9 +115,21 @@ func (b *Builder) ReadBuilderConf() {
|
||||
|
||||
for _, h := range fields {
|
||||
r := regexp.MustCompile(h.re)
|
||||
// Look for Environment variables in the config file
|
||||
re := regexp.MustCompile(`\$\{?([[:word:]]+)\}?`)
|
||||
for _, i := range lines {
|
||||
if m := r.FindIndex([]byte(i)); m != nil {
|
||||
*h.dest = i[m[1]:]
|
||||
// We want the variable without the $ or {} for lookup checking
|
||||
matches := re.FindAllStringSubmatch(i[m[1]:], -1)
|
||||
for _, s := range matches {
|
||||
if _, ok := os.LookupEnv(s[1]); !ok {
|
||||
helpers.PrintError(fmt.Errorf("buildconf contains an undefined environment variable: %s", s[1]))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Replace valid Environment Variables
|
||||
*h.dest = os.ExpandEnv(i[m[1]:])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user