This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
/
step_execute_online_activation_full.go
86 lines (64 loc) · 2.04 KB
/
step_execute_online_activation_full.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package common
import (
"fmt"
"bytes"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"strings"
"log"
)
type StepExecuteOnlineActivationFull struct {
Pk string
}
func (s *StepExecuteOnlineActivationFull) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
comm := state.Get("communicator").(packer.Communicator)
errorMsg := "Error Executing Online Activation: %s"
var remoteCmd packer.RemoteCmd
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
var err error
var stderrString string
var stdoutString string
ui.Say("Executing Online Activation Full version...")
var blockBuffer bytes.Buffer
blockBuffer.WriteString("{ cscript \"$env:SystemRoot/system32/slmgr.vbs\" /ipk "+ s.Pk +" //nologo }")
log.Printf("cmd: %s", blockBuffer.String())
remoteCmd.Command = "-ScriptBlock " + blockBuffer.String()
remoteCmd.Stdout = stdout
remoteCmd.Stderr = stderr
err = comm.Start(&remoteCmd)
stderrString = strings.TrimSpace(stderr.String())
stdoutString = strings.TrimSpace(stdout.String())
log.Printf("stdout: %s", stdoutString)
log.Printf("stderr: %s", stderrString)
if len(stderrString) > 0 {
err = fmt.Errorf(errorMsg, stderrString)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
// ui.Say(stdoutString)
/*
blockBuffer.Reset()
blockBuffer.WriteString("{ cscript \"$env:SystemRoot/system32/slmgr.vbs\" -ato //nologo }")
log.Printf("cmd: %s", blockBuffer.String())
remoteCmd.Command = "-ScriptBlock " + blockBuffer.String()
err = comm.Start(&remoteCmd)
stderrString = strings.TrimSpace(stderr.String())
stdoutString = strings.TrimSpace(stdout.String())
log.Printf("stdout: %s", stdoutString)
log.Printf("stderr: %s", stderrString)
if len(stderrString) > 0 {
err = fmt.Errorf(errorMsg, stderrString)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
ui.Say(stdoutString)
*/
return multistep.ActionContinue
}
func (s *StepExecuteOnlineActivationFull) Cleanup(state multistep.StateBag) {
// do nothing
}