Files
miscnix/projects/autoinstall/post-install/03-password.expect
Kees Jongenburger 10b3b42cd8 Refactored tcl code.
2012-06-22 10:17:02 +02:00

137 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 keesj"
#
#--- 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"
}
# when this script is stated the previous one probably has installed openssh
# and ssh keys will be generated
set timeout 120
#
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 "#"
#
# 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}
expect -re $
# 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 "#"
#
# Try and read password from a file called ~/bin/.minix.passwd
# if that is not present inform the user we are using a default
# password. (This becomes nasty when we have ssh installed)
#
set passwd "dev"
if { [file exists "~/bin/.minix.passwd" ] == 1} {
puts "**Reading password from file **"
set fd [open "~/bin/.minix.passwd" "r"]
set passwd [read $fd]
close $fd
} else {
puts "**WARNING using default password **"
}
#read the full buffer so the next line does not match RESULT-FAIL
set timeout 60
expect -re $
# passwd
#Changing local password for root.
#New password:
send -h "/tmp/runcmd.sh passwd\n"
for {} 1 {} {
puts "Passwd loop"
expect {
"New password:" {
send -h "$passwd\n"
}
"Retype new password:" {
send -h "$passwd\n"
}
"RESULT-OK" {
puts "Updated password"
break;
}
timeout {
puts "Failed to set password"
last_chance
}
}
}
expect -re $
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"
}
}