Skip to content

Commit 3a71c82

Browse files
committed
Merge branch 'xp-password'
2 parents d19600f + 0c7e394 commit 3a71c82

File tree

1 file changed

+71
-38
lines changed

1 file changed

+71
-38
lines changed

ievms.sh

+71-38
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@ reuse_xp=${REUSE_XP:-"yes"}
2121
reuse_win7=${REUSE_WIN7:-"yes"}
2222

2323
# Timeout interval to wait between checks for various states.
24-
sleep_wait="10"
24+
sleep_wait="5"
2525

2626
# Store the original `cwd`.
2727
orig_cwd=`pwd`
2828

29+
# The VM user to use for guest control.
30+
guest_user="IEUser"
31+
32+
# The VM user password to use for guest control.
33+
guest_pass="Passw0rd!"
34+
2935
# ## Utilities
3036

3137
# Print a message to the console.
32-
log() { printf "$*\n" ; return $? ; }
38+
log() { printf "$*\n" ; return $? ; }
3339

3440
# Print an error message to the console and bail out of the script.
3541
fail() { log "\nERROR: $*\n" ; exit 1 ; }
@@ -142,24 +148,20 @@ check_unar() {
142148

143149
# Pause execution until the virtual machine with a given name shuts down.
144150
wait_for_shutdown() {
145-
local x="0" ; until [ "${x}" != "0" ] ; do
151+
while true ; do
146152
log "Waiting for ${1} to shutdown..."
147153
sleep "${sleep_wait}"
148-
VBoxManage list runningvms | grep "${1}" >/dev/null && x=$? || x=$?
154+
VBoxManage showvminfo "${1}" | grep "State:" | grep -q "powered off" && return 0 || true
149155
done
150-
sleep "${sleep_wait}" # Extra sleep for good measure.
151156
}
152157

153158
# Pause execution until guest control is available for a virtual machine.
154159
wait_for_guestcontrol() {
155-
local pass=${2:-""}
156-
x="1" ; until [ "${x}" == "0" ] ; do
160+
while true ; do
157161
log "Waiting for ${1} to be available for guestcontrol..."
158162
sleep "${sleep_wait}"
159-
VBoxManage guestcontrol "${1}" cp "/etc/passwd" "/" --username IEUser \
160-
--password "${pass}" --dryrun && x=$? || x=$?
163+
VBoxManage showvminfo "${1}" | grep 'Additions run level:' | grep -q "3" && return 0 || true
161164
done
162-
sleep "${sleep_wait}" # Extra sleep for good measure.
163165
}
164166

165167
# Find or download the ievms control ISO.
@@ -221,56 +223,83 @@ start_vm() {
221223
# Copy a file to the virtual machine. An optional password will be used
222224
# if given.
223225
copy_to_vm() {
224-
local pass=${4:-""}
225226
log "Copying ${2} to ${3}"
226227
VBoxManage guestcontrol "${1}" cp "${ievms_home}/${2}" "${3}" \
227-
--username IEUser --password "${pass}"
228+
--username "${guest_user}" --password "${guest_pass}"
229+
}
230+
231+
# Execute a command with arguments on a virtual machine.
232+
guest_control_exec() {
233+
local vm="${1}"
234+
local image="${2}"
235+
shift; shift
236+
VBoxManage guestcontrol "${vm}" exec --image "${image}" \
237+
--username "${guest_user}" --password "${guest_pass}" \
238+
--wait-exit -- "$@"
239+
}
240+
241+
# Start an XP virtual machine and set the password for the guest user.
242+
set_xp_password() {
243+
start_vm "${1}"
244+
wait_for_guestcontrol "${1}"
245+
246+
log "Setting ${guest_user} password"
247+
VBoxManage guestcontrol "${1}" exec --image "net.exe" --username \
248+
Administrator --password "${guest_pass}" --wait-exit -- \
249+
user "${guest_user}" "${guest_pass}"
250+
251+
log "Setting auto logon password"
252+
VBoxManage guestcontrol "${1}" exec --image "reg.exe" --username \
253+
Administrator --password "${guest_pass}" --wait-exit -- add \
254+
"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" \
255+
/f /v DefaultPassword /t REG_SZ /d "${guest_pass}"
256+
257+
log "Enabling auto admin logon"
258+
VBoxManage guestcontrol "${1}" exec --image "reg.exe" --username \
259+
Administrator --password "${guest_pass}" --wait-exit -- add \
260+
"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" \
261+
/f /v AutoAdminLogon /t REG_SZ /d 1
262+
}
263+
264+
# Shutdown an XP virtual machine and wait for it to power off.
265+
shutdown_xp() {
266+
log "Shutting down ${1}"
267+
guest_control_exec "${1}" "shutdown.exe" /s /f /t 0
268+
wait_for_shutdown "${1}"
228269
}
229270

230271
# Install an alternative version of IE in an XP virtual machine. Downloads the
231272
# installer, copies it to the vm, then runs it before shutting down.
232273
install_ie_xp() { # vm url
233274
local src=`basename "${2}"`
234-
local dest="/Documents and Settings/IEUser/Desktop/${src}"
275+
local dest="/Documents and Settings/${guest_user}/Desktop/${src}"
235276

236277
download "${src}" "${2}" "${src}"
237-
start_vm "${1}"
238-
wait_for_guestcontrol "${1}"
239278
copy_to_vm "${1}" "${src}" "${dest}"
240279

241280
log "Installing IE" # Always "fails"
242-
VBoxManage guestcontrol "${1}" exec --image "${dest}" \
243-
--username IEUser --wait-exit -- /passive /norestart || true
244-
245-
log "Shutting down ${1}"
246-
VBoxManage guestcontrol "${1}" exec --image "shutdown.exe" \
247-
--username IEUser --wait-exit -- /s /f /t 0
281+
guest_control_exec "${1}" "${dest}" /passive /norestart || true
248282

249-
wait_for_shutdown "${1}"
283+
shutdown_xp "${1}"
250284
}
251285

252286
# Install an alternative version of IE in a Win7 virtual machine. Downloads the
253287
# installer, copies it to the vm, then runs it before shutting down.
254288
install_ie_win7() { # vm url
255289
local src=`basename "${2}"`
256-
local dest="/Users/IEUser/Desktop/${src}"
257-
local pass='Passw0rd!'
290+
local dest="/Users/${guest_user}/Desktop/${src}"
258291

259292
download "${src}" "${2}" "${src}"
260293
start_vm "${1}"
261-
wait_for_guestcontrol "${1}" "${pass}"
262-
copy_to_vm "${1}" "${src}" "${dest}" "${pass}"
294+
wait_for_guestcontrol "${1}"
295+
copy_to_vm "${1}" "${src}" "${dest}"
263296

264297
log "Installing IE"
265-
VBoxManage guestcontrol "${1}" exec --image "cmd.exe" \
266-
--username IEUser --password "${pass}" --wait-exit -- \
267-
/c "echo ${dest} /passive /norestart >C:\\Users\\IEUser\\ievms.bat"
268-
VBoxManage guestcontrol "${1}" exec --image "cmd.exe" \
269-
--username IEUser --password "${pass}" --wait-exit -- \
270-
/c "echo shutdown.exe /s /f /t 0 >>C:\\Users\\IEUser\\ievms.bat"
271-
VBoxManage guestcontrol "${1}" exec --image "schtasks.exe" \
272-
--username IEUser --password "${pass}" --wait-exit -- \
273-
/run /tn ievms
298+
guest_control_exec "${1}" "cmd.exe" /c \
299+
"echo ${dest} /passive /norestart >C:\\Users\\${guest_user}\\ievms.bat"
300+
guest_control_exec "${1}" "cmd.exe" /c \
301+
"echo shutdown.exe /s /f /t 0 >>C:\\Users\\${guest_user}\\ievms.bat"
302+
guest_control_exec "${1}" "schtasks.exe" /run /tn ievms
274303

275304
wait_for_shutdown "${1}"
276305
}
@@ -331,6 +360,9 @@ build_ievm() {
331360

332361
log "Building ${vm} VM"
333362
declare -F "build_ievm_ie${1}" && "build_ievm_ie${1}"
363+
364+
log "Tagging VM with ievms version"
365+
VBoxManage setextradata "${vm}" "ievms" "{\"version\":\"${ievms_version}\"}"
334366

335367
log "Creating clean snapshot"
336368
VBoxManage snapshot "${vm}" take clean --description "The initial VM state"
@@ -339,7 +371,8 @@ build_ievm() {
339371

340372
# Build the IE6 virtual machine.
341373
build_ievm_ie6() {
342-
boot_ievms "IE6 - WinXP"
374+
set_xp_password "IE6 - WinXP"
375+
shutdown_xp "IE6 - WinXP"
343376
}
344377

345378
# Build the IE7 virtual machine, reusing the XP VM if requested (the default).
@@ -348,7 +381,7 @@ build_ievm_ie7() {
348381
then
349382
boot_auto_ga "IE7 - Vista"
350383
else
351-
boot_ievms "IE7 - WinXP"
384+
set_xp_password "IE7 - WinXP"
352385
install_ie_xp "IE7 - WinXP" "http://download.microsoft.com/download/3/8/8/38889dc1-848c-4bf2-8335-86c573ad86d9/IE7-WindowsXP-x86-enu.exe"
353386
fi
354387
}
@@ -359,7 +392,7 @@ build_ievm_ie8() {
359392
then
360393
boot_auto_ga "IE8 - Win7"
361394
else
362-
boot_ievms "IE8 - WinXP"
395+
set_xp_password "IE8 - WinXP"
363396
install_ie_xp "IE8 - WinXP" "http://download.microsoft.com/download/C/C/0/CC0BD555-33DD-411E-936B-73AC6F95AE11/IE8-WindowsXP-x86-ENU.exe"
364397
fi
365398
}

0 commit comments

Comments
 (0)