@@ -31,17 +31,21 @@ function start_powershell_command() {
3131function get_powershell_pid_exit_code() {
3232 local powershell_pid=" ${1} "
3333
34- echo " Getting exit code for ${powershell_pid} " >&2
35- # -X blocks until the guest process exits
36- json_out=$(
37- govc guest.ps \
38- -vm.ipath=" ${vm_ipath} " \
39- -l=" ${vm_username} :${vm_password} " \
40- -X -json \
41- -p=" ${powershell_pid} "
42- )
43- echo " ${json_out} " >&2
44- echo " ${json_out} " | jq ' .processInfo[0].exitCode'
34+ if [[ -z " ${powershell_pid} " ]]; then
35+ echo " Provide PID was blank: '${powershell_pid} " >&2
36+ else
37+ echo " Getting exit code for '${powershell_pid} '" >&2
38+ # -X blocks until the guest process exits
39+ json_out=$(
40+ govc guest.ps \
41+ -vm.ipath=" ${vm_ipath} " \
42+ -l=" ${vm_username} :${vm_password} " \
43+ -X -json \
44+ -p=" ${powershell_pid} "
45+ )
46+ echo " JSON response for 'guest.ps': ${json_out} " >&2
47+ echo " ${json_out} " | jq ' .processInfo[0].exitCode'
48+ fi
4549}
4650
4751function download_remote_file() {
@@ -113,6 +117,13 @@ run_powershell_command_with_logging 'Install-Module -Name PSWindowsUpdate -Minim
113117updates_remaining=$( get_windows_updates_remaining)
114118echo " Initial Windows Updates to install: ${updates_remaining} " >&2
115119
120+ # TODO: rewrite as a single loop:
121+ # install updates
122+ # wait for VM to reboot
123+ # wait for vmware tools to be available
124+ # (re)get updates-remaining
125+ # => if remaining == 0; break
126+
116127while [[ ${updates_remaining} -ne 0 ]]; do
117128 set +e # ignore unreachable agent if the vm just went down for reboot
118129 run_powershell_command_with_logging " Install-WindowsUpdate -AcceptAll -AutoReboot"
0 commit comments