From 4463083a605ff98d973af461afd6cca7e628c139 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 18 Jun 2015 10:38:23 +0200 Subject: [PATCH] provisioner/shell: randomize default script name --- provisioner/shell/provisioner.go | 6 +++--- provisioner/shell/provisioner_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index 338092755..c2ae4d938 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -9,6 +9,7 @@ import ( "io" "io/ioutil" "log" + "math/rand" "os" "strings" "time" @@ -19,8 +20,6 @@ import ( "github.com/mitchellh/packer/template/interpolate" ) -const DefaultRemotePath = "/tmp/script.sh" - type Config struct { common.PackerConfig `mapstructure:",squash"` @@ -102,7 +101,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } if p.config.RemotePath == "" { - p.config.RemotePath = DefaultRemotePath + p.config.RemotePath = fmt.Sprintf( + "/tmp/script_%d.sh", rand.Intn(9999)) } if p.config.Scripts == nil { diff --git a/provisioner/shell/provisioner_test.go b/provisioner/shell/provisioner_test.go index 54c41c956..165490e2a 100644 --- a/provisioner/shell/provisioner_test.go +++ b/provisioner/shell/provisioner_test.go @@ -30,7 +30,7 @@ func TestProvisionerPrepare_Defaults(t *testing.T) { t.Fatalf("err: %s", err) } - if p.config.RemotePath != DefaultRemotePath { + if p.config.RemotePath == "" { t.Errorf("unexpected remote path: %s", p.config.RemotePath) } }