@@ -21,15 +21,21 @@ reuse_xp=${REUSE_XP:-"yes"}
21
21
reuse_win7=${REUSE_WIN7:- " yes" }
22
22
23
23
# Timeout interval to wait between checks for various states.
24
- sleep_wait=" 10 "
24
+ sleep_wait=" 5 "
25
25
26
26
# Store the original `cwd`.
27
27
orig_cwd=` pwd`
28
28
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
+
29
35
# ## Utilities
30
36
31
37
# Print a message to the console.
32
- log () { printf " $* \n" ; return $? ; }
38
+ log () { printf " $* \n" ; return $? ; }
33
39
34
40
# Print an error message to the console and bail out of the script.
35
41
fail () { log " \nERROR: $* \n" ; exit 1 ; }
@@ -142,24 +148,20 @@ check_unar() {
142
148
143
149
# Pause execution until the virtual machine with a given name shuts down.
144
150
wait_for_shutdown () {
145
- local x= " 0 " ; until [ " ${x} " != " 0 " ] ; do
151
+ while true ; do
146
152
log " Waiting for ${1} to shutdown..."
147
153
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
149
155
done
150
- sleep " ${sleep_wait} " # Extra sleep for good measure.
151
156
}
152
157
153
158
# Pause execution until guest control is available for a virtual machine.
154
159
wait_for_guestcontrol () {
155
- local pass=${2:- " " }
156
- x=" 1" ; until [ " ${x} " == " 0" ] ; do
160
+ while true ; do
157
161
log " Waiting for ${1} to be available for guestcontrol..."
158
162
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
161
164
done
162
- sleep " ${sleep_wait} " # Extra sleep for good measure.
163
165
}
164
166
165
167
# Find or download the ievms control ISO.
@@ -221,56 +223,83 @@ start_vm() {
221
223
# Copy a file to the virtual machine. An optional password will be used
222
224
# if given.
223
225
copy_to_vm () {
224
- local pass=${4:- " " }
225
226
log " Copying ${2} to ${3} "
226
227
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} "
228
269
}
229
270
230
271
# Install an alternative version of IE in an XP virtual machine. Downloads the
231
272
# installer, copies it to the vm, then runs it before shutting down.
232
273
install_ie_xp () { # vm url
233
274
local src=` basename " ${2} " `
234
- local dest=" /Documents and Settings/IEUser /Desktop/${src} "
275
+ local dest=" /Documents and Settings/${guest_user} /Desktop/${src} "
235
276
236
277
download " ${src} " " ${2} " " ${src} "
237
- start_vm " ${1} "
238
- wait_for_guestcontrol " ${1} "
239
278
copy_to_vm " ${1} " " ${src} " " ${dest} "
240
279
241
280
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
248
282
249
- wait_for_shutdown " ${1} "
283
+ shutdown_xp " ${1} "
250
284
}
251
285
252
286
# Install an alternative version of IE in a Win7 virtual machine. Downloads the
253
287
# installer, copies it to the vm, then runs it before shutting down.
254
288
install_ie_win7 () { # vm url
255
289
local src=` basename " ${2} " `
256
- local dest=" /Users/IEUser/Desktop/${src} "
257
- local pass=' Passw0rd!'
290
+ local dest=" /Users/${guest_user} /Desktop/${src} "
258
291
259
292
download " ${src} " " ${2} " " ${src} "
260
293
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} "
263
296
264
297
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
274
303
275
304
wait_for_shutdown " ${1} "
276
305
}
@@ -331,6 +360,9 @@ build_ievm() {
331
360
332
361
log " Building ${vm} VM"
333
362
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} \" }"
334
366
335
367
log " Creating clean snapshot"
336
368
VBoxManage snapshot " ${vm} " take clean --description " The initial VM state"
@@ -339,7 +371,8 @@ build_ievm() {
339
371
340
372
# Build the IE6 virtual machine.
341
373
build_ievm_ie6 () {
342
- boot_ievms " IE6 - WinXP"
374
+ set_xp_password " IE6 - WinXP"
375
+ shutdown_xp " IE6 - WinXP"
343
376
}
344
377
345
378
# Build the IE7 virtual machine, reusing the XP VM if requested (the default).
@@ -348,7 +381,7 @@ build_ievm_ie7() {
348
381
then
349
382
boot_auto_ga " IE7 - Vista"
350
383
else
351
- boot_ievms " IE7 - WinXP"
384
+ set_xp_password " IE7 - WinXP"
352
385
install_ie_xp " IE7 - WinXP" " http://download.microsoft.com/download/3/8/8/38889dc1-848c-4bf2-8335-86c573ad86d9/IE7-WindowsXP-x86-enu.exe"
353
386
fi
354
387
}
@@ -359,7 +392,7 @@ build_ievm_ie8() {
359
392
then
360
393
boot_auto_ga " IE8 - Win7"
361
394
else
362
- boot_ievms " IE8 - WinXP"
395
+ set_xp_password " IE8 - WinXP"
363
396
install_ie_xp " IE8 - WinXP" " http://download.microsoft.com/download/C/C/0/CC0BD555-33DD-411E-936B-73AC6F95AE11/IE8-WindowsXP-x86-ENU.exe"
364
397
fi
365
398
}
0 commit comments