consolidate shell-local defaulting of InlineShebang and ExecuteCommand to the config validation

This commit is contained in:
Megan Marsh 2018-02-28 14:43:58 -08:00
parent d304234725
commit 479d36734d
2 changed files with 12 additions and 25 deletions

View File

@ -68,18 +68,24 @@ func Validate(config *Config) error {
var errs *packer.MultiError
if runtime.GOOS == "windows" {
if config.InlineShebang == "" {
config.InlineShebang = ""
}
if len(config.ExecuteCommand) == 0 {
config.ExecuteCommand = []string{`{{.Vars}} "{{.Script}}"`}
}
config.ExecuteCommand = []string{
"cmd",
"/C",
"{{.Vars}}",
"{{.Script}}",
}
} else {
if config.InlineShebang == "" {
// TODO: verify that provisioner defaulted to this as well
config.InlineShebang = "/bin/sh -e"
}
if len(config.ExecuteCommand) == 0 {
config.ExecuteCommand = []string{
"/bin/sh",
"-c",
"{{.Vars}}",
"{{.Script}}",
}
config.ExecuteCommand = []string{`chmod +x "{{.Script}}"; {{.Vars}} "{{.Script}}"`}
}
}

View File

@ -6,7 +6,6 @@ import (
"io/ioutil"
"log"
"os"
"runtime"
"sort"
"strings"
@ -106,24 +105,6 @@ func createInterpolatedCommands(config *Config, script string, flattenedEnvVars
Script: script,
}
if len(config.ExecuteCommand) == 0 {
// Get default Execute Command
if runtime.GOOS == "windows" {
config.ExecuteCommand = []string{
"cmd",
"/C",
"{{.Vars}}",
"{{.Script}}",
}
} else {
config.ExecuteCommand = []string{
"/bin/sh",
"-c",
"{{.Vars}}",
"{{.Script}}",
}
}
}
interpolatedCmds := make([]string, len(config.ExecuteCommand))
for i, cmd := range config.ExecuteCommand {
interpolatedCmd, err := interpolate.Render(cmd, &config.Ctx)