diff --git a/common/shell/shell.go b/common/shell/shell.go new file mode 100644 index 000000000..5650440d6 --- /dev/null +++ b/common/shell/shell.go @@ -0,0 +1,42 @@ +// Package shell defines conde that is common in shells +package shell + +import "github.com/hashicorp/packer/common" + +// Provisioner contains common fields to all provisioners +type Provisioner struct { + common.PackerConfig `mapstructure:",squash"` + + // If true, the script contains binary and line endings will not be + // converted from Windows to Unix-style. + Binary bool + + // The command used to execute the script. The '{{ .Path }}' variable + // should be used to specify where the script goes, {{ .Vars }} + // can be used to inject the environment_vars into the environment. + ExecuteCommand string `mapstructure:"execute_command"` + + // An inline script to execute. Multiple strings are all executed + // in the context of a single shell. + Inline []string + + // The remote path where the local shell script will be uploaded to. + // This should be set to a writable file that is in a pre-existing directory. + // This defaults to remote_folder/remote_file + RemotePath string `mapstructure:"remote_path"` + + // The local path of the shell script to upload and execute. + Script string + + // An array of multiple scripts to run. + Scripts []string + + // Valid Exit Codes - 0 is not always the only valid error code! See + // http://www.symantec.com/connect/articles/windows-system-error-codes-exit-codes-description + // for examples such as 3010 - "The requested operation is successful. + ValidExitCodes []int `mapstructure:"valid_exit_codes"` + + // An array of environment variables that will be injected before + // your command(s) are executed. + Vars []string `mapstructure:"environment_vars"` +} diff --git a/provisioner/powershell/provisioner.go b/provisioner/powershell/provisioner.go index 74256355e..ae5b27a1c 100644 --- a/provisioner/powershell/provisioner.go +++ b/provisioner/powershell/provisioner.go @@ -13,6 +13,7 @@ import ( "time" "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/common/shell" "github.com/hashicorp/packer/common/uuid" commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/config" @@ -32,41 +33,13 @@ var psEscape = strings.NewReplacer( ) type Config struct { - common.PackerConfig `mapstructure:",squash"` - - // If true, the script contains binary and line endings will not be - // converted from Windows to Unix-style. - Binary bool - - // An inline script to execute. Multiple strings are all executed in the - // context of a single shell. - Inline []string - - // The local path of the powershell script to upload and execute. - Script string - - // An array of multiple scripts to run. - Scripts []string - - // An array of environment variables that will be injected before your - // command(s) are executed. - Vars []string `mapstructure:"environment_vars"` - - // The remote path where the local powershell script will be uploaded to. - // This should be set to a writable file that is in a pre-existing - // directory. - RemotePath string `mapstructure:"remote_path"` + shell.Provisioner `mapstructure:",squash"` // The remote path where the file containing the environment variables // will be uploaded to. This should be set to a writable file that is in a // pre-existing directory. RemoteEnvVarPath string `mapstructure:"remote_env_var_path"` - // The command used to execute the script. The '{{ .Path }}' variable - // should be used to specify where the script goes, {{ .Vars }} can be - // used to inject the environment_vars into the environment. - ExecuteCommand string `mapstructure:"execute_command"` - // The command used to execute the elevated script. The '{{ .Path }}' // variable should be used to specify where the script goes, {{ .Vars }} // can be used to inject the environment_vars into the environment. @@ -91,12 +64,6 @@ type Config struct { ElevatedUser string `mapstructure:"elevated_user"` ElevatedPassword string `mapstructure:"elevated_password"` - // Valid Exit Codes - 0 is not always the only valid error code! See - // http://www.symantec.com/connect/articles/windows-system-error-codes-exit-codes-description - // for examples such as 3010 - "The requested operation is successful. - // Changes will not be effective until the system is rebooted." - ValidExitCodes []int `mapstructure:"valid_exit_codes"` - ctx interpolate.Context } diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index f0eb325a4..4618ef043 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -15,6 +15,7 @@ import ( "time" "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/common/shell" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer/tmp" @@ -22,29 +23,11 @@ import ( ) type Config struct { - common.PackerConfig `mapstructure:",squash"` - - // If true, the script contains binary and line endings will not be - // converted from Windows to Unix-style. - Binary bool - - // An inline script to execute. Multiple strings are all executed - // in the context of a single shell. - Inline []string + shell.Provisioner `mapstructure:",squash"` // The shebang value used when running inline scripts. InlineShebang string `mapstructure:"inline_shebang"` - // The local path of the shell script to upload and execute. - Script string - - // An array of multiple scripts to run. - Scripts []string - - // An array of environment variables that will be injected before - // your command(s) are executed. - Vars []string `mapstructure:"environment_vars"` - // A duration of how long to pause after the provisioner RawPauseAfter string `mapstructure:"pause_after"` @@ -62,16 +45,6 @@ type Config struct { // This defaults to script_nnn.sh RemoteFile string `mapstructure:"remote_file"` - // The remote path where the local shell script will be uploaded to. - // This should be set to a writable file that is in a pre-existing directory. - // This defaults to remote_folder/remote_file - RemotePath string `mapstructure:"remote_path"` - - // The command used to execute the script. The '{{ .Path }}' variable - // should be used to specify where the script goes, {{ .Vars }} - // can be used to inject the environment_vars into the environment. - ExecuteCommand string `mapstructure:"execute_command"` - // The timeout for retrying to start the process. Until this timeout // is reached, if the provisioner can't start a process, it retries. // This can be set high to allow for reboots. diff --git a/provisioner/windows-shell/provisioner.go b/provisioner/windows-shell/provisioner.go index dc7b07fc3..1c052a7e5 100644 --- a/provisioner/windows-shell/provisioner.go +++ b/provisioner/windows-shell/provisioner.go @@ -13,6 +13,7 @@ import ( "time" "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/common/shell" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer/tmp" @@ -25,29 +26,7 @@ const DefaultRemotePath = "c:/Windows/Temp/script.bat" var retryableSleep = 2 * time.Second type Config struct { - common.PackerConfig `mapstructure:",squash"` - - // If true, the script contains binary and line endings will not be - // converted from Windows to Unix-style. - Binary bool - - // An inline script to execute. Multiple strings are all executed - // in the context of a single shell. - Inline []string - - // The local path of the shell script to upload and execute. - Script string - - // An array of multiple scripts to run. - Scripts []string - - // An array of environment variables that will be injected before - // your command(s) are executed. - Vars []string `mapstructure:"environment_vars"` - - // The remote path where the local shell script will be uploaded to. - // This should be set to a writable file that is in a pre-existing directory. - RemotePath string `mapstructure:"remote_path"` + shell.Provisioner `mapstructure:",squash"` // The command used to execute the script. The '{{ .Path }}' variable // should be used to specify where the script goes, {{ .Vars }} @@ -63,11 +42,6 @@ type Config struct { // inside the `ExecuteCommand` template. EnvVarFormat string - // Valid Exit Codes - 0 is not always the only valid error code! See - // http://www.symantec.com/connect/articles/windows-system-error-codes-exit-codes-description - // for examples such as 3010 - "The requested operation is successful. - ValidExitCodes []int `mapstructure:"valid_exit_codes"` - ctx interpolate.Context }