Use correct quotation of variables

This commit is contained in:
Taliesin Sisson 2015-11-02 20:05:53 +00:00
parent 4b394c8563
commit e8c2b49be8
3 changed files with 13 additions and 13 deletions

View File

@ -58,7 +58,7 @@ $t.XmlText = @'
</Actions>
</Task>
'@
$ProgressPreference='SilentlyContinue';
$ProgressPreference="SilentlyContinue";
$f = $s.GetFolder("\")
$f.RegisterTaskDefinition($name, $t, 6, "{{.User}}", "{{.Password}}", 1, $null) | Out-Null
$t = $f.GetTask("\$name")

View File

@ -120,11 +120,11 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}
if p.config.ExecuteCommand == "" {
p.config.ExecuteCommand = `powershell '& {$ProgressPreference='SilentlyContinue'; {{.Vars}}{{.Path}}; exit $LastExitCode}'`
p.config.ExecuteCommand = `powershell '& {$ProgressPreference=\"SilentlyContinue\"; {{.Vars}}{{.Path}}; exit $LastExitCode}'`
}
if p.config.ElevatedExecuteCommand == "" {
p.config.ElevatedExecuteCommand = `powershell '& {$ProgressPreference='SilentlyContinue'; {{.Vars}}{{.Path}}; exit $LastExitCode}'`
p.config.ElevatedExecuteCommand = `powershell '& {$ProgressPreference=\"SilentlyContinue\"; {{.Vars}}{{.Path}}; exit $LastExitCode}'`
}
if p.config.Inline != nil && len(p.config.Inline) == 0 {
@ -425,7 +425,7 @@ func (p *Provisioner) generateElevatedRunner(command string) (uploadedPath strin
Password: p.config.ElevatedPassword,
TaskDescription: "Packer elevated task",
TaskName: fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID()),
EncodedCommand: powershellEncode([]byte("$ProgressPreference='SilentlyContinue'; " + command + "; exit $LASTEXITCODE")),
EncodedCommand: powershellEncode([]byte("$ProgressPreference=\"SilentlyContinue\"; " + command + "; exit $LASTEXITCODE")),
})
if err != nil {

View File

@ -75,12 +75,12 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
t.Error("expected elevated_password to be empty")
}
if p.config.ExecuteCommand != "powershell '& {$ProgressPreference='SilentlyContinue'; {{.Vars}}{{.Path}}; exit $LastExitCode}'" {
t.Fatalf("Default command should be powershell '& { {{.Vars}}{{.Path}}; exit $LastExitCode}', but got %s", p.config.ExecuteCommand)
if p.config.ExecuteCommand != `powershell '& {$ProgressPreference=\"SilentlyContinue\"; {{.Vars}}{{.Path}}; exit $LastExitCode}'` {
t.Fatalf("Default command should be powershell '& {$ProgressPreference=\"SilentlyContinue\"; {{.Vars}}{{.Path}}; exit $LastExitCode}', but got %s", p.config.ExecuteCommand)
}
if p.config.ElevatedExecuteCommand != "powershell '& {$ProgressPreference='SilentlyContinue'; {{.Vars}}{{.Path}}; exit $LastExitCode}'" {
t.Fatalf("Default command should be powershell powershell '& { {{.Vars}}{{.Path}}; exit $LastExitCode}', but got %s", p.config.ElevatedExecuteCommand)
if p.config.ElevatedExecuteCommand != `powershell '& {$ProgressPreference=\"SilentlyContinue\"; {{.Vars}}{{.Path}}; exit $LastExitCode}'` {
t.Fatalf("Default command should be powershell powershell '& {$ProgressPreference=\"SilentlyContinue\"; {{.Vars}}{{.Path}}; exit $LastExitCode}', but got %s", p.config.ElevatedExecuteCommand)
}
if p.config.ValidExitCodes == nil {
@ -389,7 +389,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
t.Fatal("should not have error")
}
expectedCommand := `powershell '& {$ProgressPreference='SilentlyContinue'; $env:PACKER_BUILDER_TYPE=\"iso\"; $env:PACKER_BUILD_NAME=\"vmware\"; c:/Windows/Temp/inlineScript.bat; exit $LastExitCode}'`
expectedCommand := `powershell '& {$ProgressPreference=\"SilentlyContinue\"; $env:PACKER_BUILDER_TYPE=\"iso\"; $env:PACKER_BUILD_NAME=\"vmware\"; c:/Windows/Temp/inlineScript.bat; exit $LastExitCode}'`
// Should run the command without alteration
if comm.StartCmd.Command != expectedCommand {
@ -408,7 +408,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
t.Fatal("should not have error")
}
expectedCommand = `powershell '& {$ProgressPreference='SilentlyContinue'; $env:BAR=\"BAZ\"; $env:FOO=\"BAR\"; $env:PACKER_BUILDER_TYPE=\"iso\"; $env:PACKER_BUILD_NAME=\"vmware\"; c:/Windows/Temp/inlineScript.bat; exit $LastExitCode}'`
expectedCommand = `powershell '& {$ProgressPreference=\"SilentlyContinue\"; $env:BAR=\"BAZ\"; $env:FOO=\"BAR\"; $env:PACKER_BUILDER_TYPE=\"iso\"; $env:PACKER_BUILD_NAME=\"vmware\"; c:/Windows/Temp/inlineScript.bat; exit $LastExitCode}'`
// Should run the command without alteration
if comm.StartCmd.Command != expectedCommand {
@ -435,7 +435,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
}
//powershell -Command "$env:PACKER_BUILDER_TYPE=''"; powershell -Command "$env:PACKER_BUILD_NAME='foobuild'"; powershell -Command c:/Windows/Temp/script.ps1
expectedCommand := `powershell '& {$ProgressPreference='SilentlyContinue'; $env:PACKER_BUILDER_TYPE=\"footype\"; $env:PACKER_BUILD_NAME=\"foobuild\"; c:/Windows/Temp/script.ps1; exit $LastExitCode}'`
expectedCommand := `powershell '& {$ProgressPreference=\"SilentlyContinue\"; $env:PACKER_BUILDER_TYPE=\"footype\"; $env:PACKER_BUILD_NAME=\"foobuild\"; c:/Windows/Temp/script.ps1; exit $LastExitCode}'`
// Should run the command without alteration
if comm.StartCmd.Command != expectedCommand {
@ -468,7 +468,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
t.Fatal("should not have error")
}
expectedCommand := `powershell '& {$ProgressPreference='SilentlyContinue'; $env:BAR=\"BAZ\"; $env:FOO=\"BAR\"; $env:PACKER_BUILDER_TYPE=\"footype\"; $env:PACKER_BUILD_NAME=\"foobuild\"; c:/Windows/Temp/script.ps1; exit $LastExitCode}'`
expectedCommand := `powershell '& {$ProgressPreference=\"SilentlyContinue\"; $env:BAR=\"BAZ\"; $env:FOO=\"BAR\"; $env:PACKER_BUILDER_TYPE=\"footype\"; $env:PACKER_BUILD_NAME=\"foobuild\"; c:/Windows/Temp/script.ps1; exit $LastExitCode}'`
// Should run the command without alteration
if comm.StartCmd.Command != expectedCommand {
@ -582,7 +582,7 @@ func TestProvision_createCommandText(t *testing.T) {
// Non-elevated
cmd, _ := p.createCommandText()
if cmd != `powershell '& {$ProgressPreference='SilentlyContinue'; $env:PACKER_BUILDER_TYPE=\"\"; $env:PACKER_BUILD_NAME=\"\"; c:/Windows/Temp/script.ps1; exit $LastExitCode}'` {
if cmd != `powershell '& {$ProgressPreference=\"SilentlyContinue\"; $env:PACKER_BUILDER_TYPE=\"\"; $env:PACKER_BUILD_NAME=\"\"; c:/Windows/Temp/script.ps1; exit $LastExitCode}'` {
t.Fatalf("Got unexpected non-elevated command: %s", cmd)
}