consolidate shell-local defaulting of InlineShebang and ExecuteCommand to the config validation
This commit is contained in:
parent
d304234725
commit
479d36734d
|
@ -68,18 +68,24 @@ func Validate(config *Config) error {
|
||||||
var errs *packer.MultiError
|
var errs *packer.MultiError
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
if config.InlineShebang == "" {
|
|
||||||
config.InlineShebang = ""
|
|
||||||
}
|
|
||||||
if len(config.ExecuteCommand) == 0 {
|
if len(config.ExecuteCommand) == 0 {
|
||||||
config.ExecuteCommand = []string{`{{.Vars}} "{{.Script}}"`}
|
config.ExecuteCommand = []string{
|
||||||
|
"cmd",
|
||||||
|
"/C",
|
||||||
|
"{{.Vars}}",
|
||||||
|
"{{.Script}}",
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if config.InlineShebang == "" {
|
if config.InlineShebang == "" {
|
||||||
// TODO: verify that provisioner defaulted to this as well
|
|
||||||
config.InlineShebang = "/bin/sh -e"
|
config.InlineShebang = "/bin/sh -e"
|
||||||
}
|
}
|
||||||
if len(config.ExecuteCommand) == 0 {
|
if len(config.ExecuteCommand) == 0 {
|
||||||
|
config.ExecuteCommand = []string{
|
||||||
|
"/bin/sh",
|
||||||
|
"-c",
|
||||||
|
"{{.Vars}}",
|
||||||
|
"{{.Script}}",
|
||||||
|
}
|
||||||
config.ExecuteCommand = []string{`chmod +x "{{.Script}}"; {{.Vars}} "{{.Script}}"`}
|
config.ExecuteCommand = []string{`chmod +x "{{.Script}}"; {{.Vars}} "{{.Script}}"`}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -106,24 +105,6 @@ func createInterpolatedCommands(config *Config, script string, flattenedEnvVars
|
||||||
Script: script,
|
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))
|
interpolatedCmds := make([]string, len(config.ExecuteCommand))
|
||||||
for i, cmd := range config.ExecuteCommand {
|
for i, cmd := range config.ExecuteCommand {
|
||||||
interpolatedCmd, err := interpolate.Render(cmd, &config.Ctx)
|
interpolatedCmd, err := interpolate.Render(cmd, &config.Ctx)
|
||||||
|
|
Loading…
Reference in New Issue