From 0912adea340e43680637b0aaae7402ccaf0e4e0f Mon Sep 17 00:00:00 2001 From: Joel Vasallo Date: Fri, 19 Oct 2018 00:46:50 -0500 Subject: [PATCH] fix: converted onlyon param to only_on and added validation step --- common/shell-local/config.go | 21 ++++++++++++++++++- .../docs/post-processors/shell-local.html.md | 6 ++++++ .../docs/provisioners/shell-local.html.md | 10 ++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/common/shell-local/config.go b/common/shell-local/config.go index bd895b547..0d6fcb7fd 100644 --- a/common/shell-local/config.go +++ b/common/shell-local/config.go @@ -30,7 +30,7 @@ type Config struct { InlineShebang string `mapstructure:"inline_shebang"` // An array of multiple Runtime OSs to run on. - OnlyOn []string + OnlyOn []string `mapstructure:"only_on"` // The file extension to use for the file generated from the inline commands TempfileExtension string `mapstructure:"tempfile_extension"` @@ -162,6 +162,25 @@ func Validate(config *Config) error { fmt.Errorf("Bad script '%s': %s", path, err)) } } + + // Check for properly formatted go os types + supported_syslist := []string{"darwin", "freebsd", "linux", "openbsd", "solaris", "windows"} + supported_os := false + if len(config.OnlyOn) > 0 { + for _, provided_os := range config.OnlyOn { + for _, go_os := range supported_syslist { + if provided_os == go_os { + supported_os = true + break + } + if supported_os != true { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("Invalid OS specified in only_on: '%s'", provided_os)) + } + } + } + } + if config.UseLinuxPathing { for index, script := range config.Scripts { scriptAbsPath, err := filepath.Abs(script) diff --git a/website/source/docs/post-processors/shell-local.html.md b/website/source/docs/post-processors/shell-local.html.md index 1c412180f..c21c7e908 100644 --- a/website/source/docs/post-processors/shell-local.html.md +++ b/website/source/docs/post-processors/shell-local.html.md @@ -91,6 +91,12 @@ Optional parameters: **Important:** If you customize this, be sure to include something like the `-e` flag, otherwise individual steps failing won't fail the provisioner. +- `only_on` (array of strings) - This is an array of + [runtime operating systems](https://golang.org/doc/install/source#environment) + where `shell-local` will execute. This allows you to execute `shell-local` + *only* on specific operating systems. By default, shell-local will always run + if `only_on` is not set." + - `use_linux_pathing` (bool) - This is only relevant to windows hosts. If you are running Packer in a Windows environment with the Windows Subsystem for Linux feature enabled, and would like to invoke a bash script rather than diff --git a/website/source/docs/provisioners/shell-local.html.md b/website/source/docs/provisioners/shell-local.html.md index 99724cb86..881d1759a 100644 --- a/website/source/docs/provisioners/shell-local.html.md +++ b/website/source/docs/provisioners/shell-local.html.md @@ -108,13 +108,11 @@ Optional parameters: **Important:** If you customize this, be sure to include something like the `-e` flag, otherwise individual steps failing won't fail the provisioner. -- `onlyon` (array of strings) - This is an array of +- `only_on` (array of strings) - This is an array of [runtime operating systems](https://golang.org/doc/install/source#environment) - where `shell-local` will only run on. This allows you to run `shell-local` *only* - on specific compatible operating systems. If specified, shell-local will only - execute if runtime operating system is in the list; otherwise it will skip the - `shell-local` command. The default behavior is for `shell-local` to run if - `onlyon` is not specified. + where `shell-local` will execute. This allows you to execute `shell-local` + *only* on specific operating systems. By default, shell-local will always run + if `only_on` is not set." - `use_linux_pathing` (bool) - This is only relevant to windows hosts. If you are running Packer in a Windows environment with the Windows Subsystem for