Commit 86f980c2 authored by Christopher Alfeld's avatar Christopher Alfeld

instimage - Utility to install images over tip lines

setupmachine.sh - Sets up a machine.  Needs to be run from this
directory.
parent 603b93fb
#!/usr/local/bin/expect
set RLT "\r\n"
set NetDisk "155.99.214.74:/q/testbed/images/netdisk"
set ImagePrefix "155.99.214.74:/q/testbed/images"
set TO 90
if {[llength $argv] != 4} {
puts stderr "Syntax: instimage <node> <image> <partition> <bootafter>"
exit 1
}
set node [lindex $argv 0]
set image [lindex $argv 1]
set partition [lindex $argv 2]
set bootafter [lindex $argv 3]
spawn ssh -t -a -x plastic tip $node
set timeout 15
expect {
"connected" {
set state "UNKNOWN"
}
timeout {
puts "Could not connect - Exiting"
exit 1
}
}
set timeout $TO
expect_after {
timeout {
if {[lindex [split $state _] 0] == "RECOVER"} {
puts "TIMEOUT on state $state - Exiting"
exit 2
} else {
puts "TIMEOUT on state $state - Recovering"
set state "RECOVER_$state"
set exitcode 1
}
}
}
proc doflush {} {
global spawn_id
expect -re {.*}
}
set exitcode 0
set goodcopy 0
while {$state != "EXIT"} {
puts ""
puts "\[STATE: $state\]"
switch $state {
"UNKNOWN" {
send "$RLT"
expect {
"login:" {
set state "LOGIN"
}
-re {# $} {
set state "SHELL"
}
"boot:" {
set state "LILO"
}
"NetBoot>" {
set state "NETBOOT"
}
"NetDisk>" {
set state "NETDISK"
}
}
}
"RECOVER_UNKNOWN" {
puts "Can not recover from state UNKNOWN - Exiting"
exit 2
}
"LOGIN" {
doflush
send "root$RLT"
expect {
"Password:" {
set state "PASSWORD"
}
}
}
"RECOVER_LOGIN" {
doflush
send "$RLT"
set state EXIT
}
"PASSWORD" {
send_user "Please enter Password: "
stty -echo
expect_user -re "(.*)\n"
stty echo
doflush
send "$expect_out(1,string)$RLT"
expect {
-re {login: $} {
puts "Login failed"
set state "LOGIN"
}
-re {# $} {
set state "SHELL"
}
}
}
"RECOVER_PASSWORD" {set state EXIT}
"SHELL" {
doflush
send "reboot$RLT"
expect {
"going down" {
set state "REBOOTING"
}
-re {# $} {
puts "Reboot failed - Exiting"
send "exit$RLT"
exit 1
}
}
}
"RECOVER_SHELL" {
send "exit$RLT"
set state EXIT
}
"REBOOTING" {
expect {
"boot:" {
set state "LILO"
}
"login:" {
puts "Missed LILO SHELL - Exiting"
exit 1
}
}
}
"RECOVER_REBOOTING" {set state EXIT}
"LILO" {
doflush
send "netboot$RLT"
expect {
"boot:" {
puts "Unable to netboot - Recovering"
set exitcode 1
set state "RECOVER_LILO"
}
"NetBoot>" {
set state "NETBOOT"
}
}
}
"NETBOOT" {
doflush
send "$NetDisk$RLT"
expect {
"NetDisk>" {
set state "NETDISK"
}
"NetBoot>" {
puts "Unable to boot NetDisk - Recovering"
set exitcode 1
set state "RECOVER_NETBOOT"
}
}
}
"NETDISK" {
doflush
send "$RLT"
set tries 0
set ok 0
expect {
"Bad command line" {
puts "NetDisk didn't like our command line - $ImagePrefix/$image $partition - Recovering"
set exitcode 1
set state "RECOVER_NETDISK"
}
"Can't get the disk image" {
puts "Couldn't find disk image - Recovering"
set exitcode 1
set state "RECOVER_NETDISK"
}
"netdisk: Partition range:" {
puts "Copying - This will take a while."
set timeout 900
set ok 1
exp_continue
}
"netdisk: Success!" {
puts "Copy finished"
set timeout $TO
set state "RECOVER_NETBOOT"
set goodcopy 1
}
"NetDisk>" {
# XXX - dirty hack Need to fix
if {$tries <= 5} {
incr tries
doflush
send "$ImagePrefix/$image wd0 $partition$RLT"
exp_continue
} else {
puts "Unknown error - Recovering"
set exitcode 1
set state "RECOVER_NETDISK"
}
}
}
}
"RECOVER_NETDISK" {
doflush
send "$RLT"
set tries 0
expect {
"NetBoot>" {
set state "RECOVER_NETBOOT"
}
-re {NetDisk> $} {
if {$tries == 0} {
incr tries
doflush
send "exit$RLT"
exp_continue
} else {
puts "Exit didn't work - Exiting - Machine in strange state"
exit 2
}
}
}
}
"RECOVER_NETBOOT" {
doflush
send "$RLT"
set tries 0
expect {
"boot:" {
set state "RECOVER_LILO"
}
"NetBoot>" {
if {$tries == 0} {
incr tries
doflush
send "exit$RLT"
exp_continue
} else {
puts "Exit didn't work - Exiting - Machine in strange state"
exit 2
}
}
}
}
"RECOVER_LILO" {
puts "Booting $bootafter"
send "$bootafter$RLT"
set state "EXIT"
}
}
}
puts ""
if {$goodcopy == 1} {
puts "COPY: SUCCESS"
} else {
puts "COPY: FAIL"
}
if {$exitcode != 2} {
puts "RECOVERY: PROBABLE SUCCESS"
} else {
puts "RECOVERY: FAIL - Machine in unknown state."
}
exit $exitcode
\ No newline at end of file
#!/bin/csh -x
sed -e s/NODE/tbpc$1/g setupmachine-client.tmpl >! /tmp/setupmachine-client.sh
scp /tmp/setupmachine-client.sh 155.99.214.1${1}:/tmp
ssh 155.99.214.1$1 /bin/csh -x /tmp/setupmachine-client.sh
rm -f /tmp/setupmachine-client.sh
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment