provisioner/shell: inline_shebang for inline scripts
This commit is contained in:
parent
6a5bbaa05d
commit
b22743767e
|
@ -11,6 +11,10 @@ IMPROVEMENTS:
|
||||||
|
|
||||||
* core: If SCP is not available, a more descriptive error message
|
* core: If SCP is not available, a more descriptive error message
|
||||||
is shown telling the user. [GH-127]
|
is shown telling the user. [GH-127]
|
||||||
|
* shell: Scripts are now executed by default according to their shebang,
|
||||||
|
not with `/bin/sh`. [GH-105]
|
||||||
|
* shell: You can specify what interpreter you want inline scripts to
|
||||||
|
run with `inline_shebang`.
|
||||||
* virtualbox: Delete the packer-made SSH port forwarding prior to
|
* virtualbox: Delete the packer-made SSH port forwarding prior to
|
||||||
exporting the VM.
|
exporting the VM.
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ type config struct {
|
||||||
// in the context of a single shell.
|
// in the context of a single shell.
|
||||||
Inline []string
|
Inline []string
|
||||||
|
|
||||||
|
// The shebang value used when running inline scripts.
|
||||||
|
InlineShebang string `mapstructure:"inline_shebang"`
|
||||||
|
|
||||||
// The local path of the shell script to upload and execute.
|
// The local path of the shell script to upload and execute.
|
||||||
Script string
|
Script string
|
||||||
|
|
||||||
|
@ -69,6 +72,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
p.config.Inline = nil
|
p.config.Inline = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.config.InlineShebang == "" {
|
||||||
|
p.config.InlineShebang = "/bin/sh"
|
||||||
|
}
|
||||||
|
|
||||||
if p.config.RemotePath == "" {
|
if p.config.RemotePath == "" {
|
||||||
p.config.RemotePath = DefaultRemotePath
|
p.config.RemotePath = DefaultRemotePath
|
||||||
}
|
}
|
||||||
|
@ -136,6 +143,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
|
|
||||||
// Write our contents to it
|
// Write our contents to it
|
||||||
writer := bufio.NewWriter(tf)
|
writer := bufio.NewWriter(tf)
|
||||||
|
writer.WriteString(fmt.Sprintf("#!%s\n", p.config.InlineShebang))
|
||||||
for _, command := range p.config.Inline {
|
for _, command := range p.config.Inline {
|
||||||
if _, err := writer.WriteString(command + "\n"); err != nil {
|
if _, err := writer.WriteString(command + "\n"); err != nil {
|
||||||
return fmt.Errorf("Error preparing shell script: %s", err)
|
return fmt.Errorf("Error preparing shell script: %s", err)
|
||||||
|
|
|
@ -35,6 +35,33 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProvisionerPrepare_InlineShebang(t *testing.T) {
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
delete(config, "inline_shebang")
|
||||||
|
p := new(Provisioner)
|
||||||
|
err := p.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.config.InlineShebang != "/bin/sh" {
|
||||||
|
t.Fatalf("bad value: %s", p.config.InlineShebang)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with a good one
|
||||||
|
config["inline_shebang"] = "foo"
|
||||||
|
p = new(Provisioner)
|
||||||
|
err = p.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.config.InlineShebang != "foo" {
|
||||||
|
t.Fatalf("bad value: %s", p.config.InlineShebang)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProvisionerPrepare_Script(t *testing.T) {
|
func TestProvisionerPrepare_Script(t *testing.T) {
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
delete(config, "inline")
|
delete(config, "inline")
|
||||||
|
|
Loading…
Reference in New Issue