diff --git a/common/shell-local/config.go b/common/shell-local/config.go index 0d6fcb7fd..e3247f73a 100644 --- a/common/shell-local/config.go +++ b/common/shell-local/config.go @@ -165,18 +165,17 @@ func Validate(config *Config) error { // 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 { + supported_os := false 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 supported_os != true { + return fmt.Errorf("Invalid OS specified in only_on: '%s'", provided_os) } } } diff --git a/common/shell-local/run.go b/common/shell-local/run.go index 505823833..11165a36c 100644 --- a/common/shell-local/run.go +++ b/common/shell-local/run.go @@ -28,6 +28,24 @@ type EnvVarsTemplate struct { } func Run(ui packer.Ui, config *Config) (bool, error) { + // Check if shell-local can even execute against this runtime OS + runCommand := false + if len(config.OnlyOn) > 0 { + for _, os := range config.OnlyOn { + if os == runtime.GOOS { + runCommand = true + break + } + } + } else { + runCommand = true + } + if !runCommand { + ui.Say(fmt.Sprintf("Skipping shell-local due to runtime OS")) + log.Printf("[INFO] (shell-local): skipping shell-local due to missing runtime OS") + return true, nil + } + scripts := make([]string, len(config.Scripts)) if len(config.Scripts) > 0 { copy(scripts, config.Scripts) @@ -59,50 +77,31 @@ func Run(ui packer.Ui, config *Config) (bool, error) { if err != nil { return false, err } + ui.Say(fmt.Sprintf("Running local shell script: %s", script)) - // Check if command can execute against runtime. - runCommand := false - if len(config.OnlyOn) > 0 { - for _, os := range config.OnlyOn { - if os == runtime.GOOS { - runCommand = true - } - } - } else { - runCommand = true + comm := &Communicator{ + ExecuteCommand: interpolatedCmds, } - if runCommand { - ui.Say(fmt.Sprintf("Running local shell script: %s", script)) - - comm := &Communicator{ - ExecuteCommand: interpolatedCmds, - } - - // The remoteCmd generated here isn't actually run, but it allows us to - // use the same interafce for the shell-local communicator as we use for - // the other communicators; ultimately, this command is just used for - // buffers and for reading the final exit status. - flattenedCmd := strings.Join(interpolatedCmds, " ") - - cmd := &packer.RemoteCmd{Command: flattenedCmd} - log.Printf("[INFO] (shell-local): starting local command: %s", flattenedCmd) - if err := cmd.StartWithUi(comm, ui); err != nil { - return false, fmt.Errorf( - "Error executing script: %s\n\n"+ - "Please see output above for more information.", - script) - } - if cmd.ExitStatus != 0 { - return false, fmt.Errorf( - "Erroneous exit code %d while executing script: %s\n\n"+ - "Please see output above for more information.", - cmd.ExitStatus, - script) - } - } else { - ui.Say(fmt.Sprintf("Skipping local shell script due to runtime OS: %s", script)) - log.Printf("[INFO] (shell-local): skipping command due to runtime OS not specified.") + // The remoteCmd generated here isn't actually run, but it allows us to + // use the same interafce for the shell-local communicator as we use for + // the other communicators; ultimately, this command is just used for + // buffers and for reading the final exit status. + flattenedCmd := strings.Join(interpolatedCmds, " ") + cmd := &packer.RemoteCmd{Command: flattenedCmd} + log.Printf("[INFO] (shell-local): starting local command: %s", flattenedCmd) + if err := cmd.StartWithUi(comm, ui); err != nil { + return false, fmt.Errorf( + "Error executing script: %s\n\n"+ + "Please see output above for more information.", + script) + } + if cmd.ExitStatus != 0 { + return false, fmt.Errorf( + "Erroneous exit code %d while executing script: %s\n\n"+ + "Please see output above for more information.", + cmd.ExitStatus, + script) } }