From 7710e230d1cab46609256bd9fbe0db5391df6832 Mon Sep 17 00:00:00 2001 From: Kees Jongenburger Date: Thu, 7 Jun 2012 15:30:46 +0200 Subject: [PATCH] Updates to the scripts. Adding setting of the password. --- projects/autoinstall/Makefile | 1 + .../post-install/01-reconfigure-net.expect | 2 +- .../autoinstall/post-install/02-setup.expect | 3 +- .../autoinstall/post-install/03-keesj.expect | 106 ++++++++++++++++++ 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100755 projects/autoinstall/post-install/03-keesj.expect diff --git a/projects/autoinstall/Makefile b/projects/autoinstall/Makefile index 717945f..d4b1275 100644 --- a/projects/autoinstall/Makefile +++ b/projects/autoinstall/Makefile @@ -22,5 +22,6 @@ minix.postinst.8g.img:minix.base.8g.img cp minix.base.8g.img minix.postinst.8g.tmp.img post-install/01-reconfigure-net.expect post-install/02-setup.expect + post-install/03-keesj.expect mv minix.postinst.8g.tmp.img minix.postinst.8g.img diff --git a/projects/autoinstall/post-install/01-reconfigure-net.expect b/projects/autoinstall/post-install/01-reconfigure-net.expect index c19b41f..5d0ccc8 100755 --- a/projects/autoinstall/post-install/01-reconfigure-net.expect +++ b/projects/autoinstall/post-install/01-reconfigure-net.expect @@ -53,7 +53,7 @@ for {} 1 {} { } "dirty, performing fsck" {puts "resetting timeout as the file system in dirty" } #Starting networking: dhcpd nonamed. - "nonamed." { + "nonamed" { #send a break signal sleep 1 send "\003" diff --git a/projects/autoinstall/post-install/02-setup.expect b/projects/autoinstall/post-install/02-setup.expect index 2ba4b15..d6ae737 100755 --- a/projects/autoinstall/post-install/02-setup.expect +++ b/projects/autoinstall/post-install/02-setup.expect @@ -1,6 +1,6 @@ #!/usr/bin/expect -f # -spawn qemu-system-i386 -m 512 -hda minix.postinst.8g..tmp.img -curses +spawn qemu-system-i386 -m 512 -hda minix.postinst.8g.tmp.img -curses set timeout 5 @@ -116,6 +116,7 @@ expect { exit 1 } } +set timeout 20 #shutdown send "shutdown\n" expect "Choose an option; RETURN for default; SPACE to stop countdown." diff --git a/projects/autoinstall/post-install/03-keesj.expect b/projects/autoinstall/post-install/03-keesj.expect new file mode 100755 index 0000000..6ff828a --- /dev/null +++ b/projects/autoinstall/post-install/03-keesj.expect @@ -0,0 +1,106 @@ +#!/usr/bin/expect -f +# +spawn qemu-system-i386 -m 512 -hda minix.postinst.8g.tmp.img -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" + exit 1 + } + } +} + +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" + interact + exit 1 + } + } +} +expect -re $ +set timeout 20 +#shutdown +send "shutdown\n" +expect "Choose an option; RETURN for default; SPACE to stop countdown."