150 lines
2.8 KiB
Plaintext
Executable File
150 lines
2.8 KiB
Plaintext
Executable File
#!/usr/bin/expect -f
|
|
#
|
|
|
|
|
|
#
|
|
# Parse arguments
|
|
#
|
|
set image minix.postinst.8g.tmp.img
|
|
if { $argc > 0 } {
|
|
puts "Parsing arguments"
|
|
set counter 0
|
|
while {$counter < $argc} {
|
|
if { [lindex $argv $counter] == "--image" } {
|
|
set counter [expr {$counter +1}]
|
|
set image [lindex $argv $counter]
|
|
|
|
}
|
|
set counter [expr {$counter +1}]
|
|
}
|
|
}
|
|
|
|
proc last_chance {} {
|
|
puts "\nLast chance\n"
|
|
interact
|
|
}
|
|
|
|
spawn qemu-system-i386 -m 512 -hda $image -curses
|
|
|
|
set timeout 5
|
|
|
|
puts "Performing post install"
|
|
#
|
|
#--- Welcome to MINIX 3. This is the boot monitor. ---
|
|
expect "\\-\\-\\- Welcome to MINIX 3. This is the boot monitor. \\-\\-\\-"
|
|
|
|
#
|
|
#Check we have a normal boot loader
|
|
#1. Start MINIX 3
|
|
expect "1. Start MINIX 3"
|
|
|
|
expect "Choose an option; RETURN for default; SPACE to stop countdown." {
|
|
send "\n"
|
|
}
|
|
|
|
|
|
# expect the boot to take very long as in the default image the network
|
|
# driver is not properly configured
|
|
set timeout 60
|
|
|
|
#
|
|
for {} 1 {} {
|
|
puts "Waiting for a prompt"
|
|
expect {
|
|
#minix login:
|
|
#but later if it worked ip-address login:
|
|
"login:" {
|
|
send "root\n"
|
|
break
|
|
}
|
|
"dirty, performing fsck" {puts "resetting timeout as the file system in dirty" }
|
|
timeout {
|
|
puts "Failed to catch login command"
|
|
last_chance
|
|
}
|
|
}
|
|
}
|
|
|
|
set timeout 5
|
|
expect "#"
|
|
expect -re $
|
|
|
|
|
|
#
|
|
# put a run command in /tmp that echoes RESULT-OK or RESULT-FAIL based on the
|
|
# return value of the command launched
|
|
#
|
|
set send_human {.1 .3 1 .05 2}
|
|
# the shell can't handle all this output at once so sending it as "human"
|
|
send -h "echo '#!/bin/sh' > /tmp/runcmd.sh ; echo 'if $* ; then echo RESULT-OK ; else echo RESULT-FAIL ; fi' >> /tmp/runcmd.sh ; chmod +x /tmp/runcmd.sh\n"
|
|
expect "#"
|
|
|
|
|
|
#read the full buffer so the next line does not match RESULT-FAIL
|
|
set timeout 60
|
|
expect -re $
|
|
send "/tmp/runcmd.sh pkgin update\n"
|
|
expect {
|
|
"RESULT-FAIL" {
|
|
puts "Failed to update package database"
|
|
interact
|
|
exit 1
|
|
}
|
|
"RESULT-OK" {
|
|
puts "Updated the package database"
|
|
}
|
|
timeout {
|
|
puts "Failed to update pkg database"
|
|
last_chance
|
|
}
|
|
}
|
|
|
|
set timeout 120
|
|
expect -re $
|
|
send "/tmp/runcmd.sh pkgin upgrade\n"
|
|
expect {
|
|
"RESULT-FAIL" {
|
|
puts "Failed to upgrade packages"
|
|
last_chance
|
|
}
|
|
"RESULT-OK" {
|
|
puts "Updated the package upgraded"
|
|
}
|
|
timeout {
|
|
puts "Failed to update pkg packages"
|
|
last_chance
|
|
}
|
|
}
|
|
|
|
#
|
|
# installing takes quite some time
|
|
#
|
|
set timeout 1000
|
|
expect -re $
|
|
send "/tmp/runcmd.sh pkgin -y install vim cscope openssh gcc44 scmgit\n"
|
|
expect {
|
|
"RESULT-FAIL" {
|
|
puts "Failed to install needed packages"
|
|
last_chance
|
|
}
|
|
"RESULT-OK" {
|
|
puts "Updated the needed packages"
|
|
}
|
|
timeout {
|
|
puts "Failed to install selected packages"
|
|
last_chance
|
|
}
|
|
}
|
|
set timeout 20
|
|
#shutdown
|
|
send "shutdown\n"
|
|
expect {
|
|
"Choose an option; RETURN for default; SPACE to stop countdown." {
|
|
puts "\nInstall worked\n"
|
|
}
|
|
"Press Ctrl-B to configure iPXE" {
|
|
puts "\nInstall worked\n"
|
|
|
|
}
|
|
}
|