diff --git a/internal/osbuild/shell_init_stage.go b/internal/osbuild/shell_init_stage.go index fb95c9ab8..f007f35ef 100644 --- a/internal/osbuild/shell_init_stage.go +++ b/internal/osbuild/shell_init_stage.go @@ -3,6 +3,8 @@ package osbuild import ( "fmt" "regexp" + + "github.com/osbuild/osbuild-composer/internal/shell" ) const filenameRegex = "^[a-zA-Z0-9\\.\\-_]{1,250}$" @@ -55,3 +57,19 @@ func NewShellInitStage(options *ShellInitStageOptions) *Stage { Options: options, } } + +// GenShellInitStage generates an org.osbuild.shell.init stage from a basic map +// of the form filename->key->value. +func GenShellInitStage(initFiles []shell.InitFile) *Stage { + options := new(ShellInitStageOptions) + options.Files = make(map[string]ShellInitFile, len(initFiles)) + for _, file := range initFiles { + vars := make([]EnvironmentVariable, len(file.Variables)) + for idx, envVar := range file.Variables { + vars[idx] = EnvironmentVariable{Key: envVar.Key, Value: envVar.Value} + } + options.Files[file.Filename] = ShellInitFile{Env: vars} + } + + return NewShellInitStage(options) +}