App-FuguVM
view release on metacpan or search on metacpan
share/fuguvm/expect/install.exp view on Meta::CPAN
sleep 0.5
send -- "$response\r"
}
# Connect to console
spawn telnet $host $port
# Wait for the console connection. telnet prints "Connected to <host>"
# on success. Match on the host-independent prefix, because the host
# can be an IP address. An eof means telnet could not connect at all,
# because the console port does not listen. Fail fast rather than hang
# to the full timeout.
expect {
"Connected to" {
# Send an empty line to trigger the prompt if the console
# already shows the installer
sleep 0.5
send "\r"
}
"Escape character" {
sleep 0.5
send "\r"
}
eof {
send_user "\n==> ERROR: telnet could not connect to the VM console\n"
exit 1
}
timeout {
send_user "\n==> ERROR: Failed to connect to VM console\n"
exit 1
}
}
sleep 0.5
expect {
"(I)nstall" {
send "i\r"
}
"Welcome to the OpenBSD" {
# Wait a bit more for the menu to appear
exp_continue
}
"boot>" {
# The arm64 machine has no display adapter, so its loader
# already writes to the serial port. The amd64 machine has
# one, so its loader must move the console to com0 before it
# boots the kernel.
if {$arch eq "amd64"} {
send "stty com0 115200\r"
expect "boot>"
send "set tty com0\r"
expect "boot>"
send "boot\r"
} else {
send "\r"
}
exp_continue
}
timeout {
send_user "\n==> ERROR: Timeout waiting for installer\n"
exit 1
}
}
# Start installation
sleep 0.5
# Terminal type
expect "Terminal type?" { respond "" }
# System hostname
expect "System hostname?" { respond "openbsd-test" }
# Network interface
expect "Network interface to configure?" { respond "" }
# IPv4 address
expect "IPv4 address" { respond "dhcp" }
# IPv6 address
expect "IPv6 address" { respond "none" }
# Done with network interfaces
expect "Network interface to configure?" { respond "done" }
# Password for root. Wait for the actual prompt.
expect "Password for root account?"
sleep 0.5
send -- "$root_password\r"
expect "Password for root account? (again)"
sleep 0.5
send -- "$root_password\r"
# Start sshd
expect "Start sshd(8)" { respond "yes" }
# Only the amd64 machine has a display adapter, so only its installer
# asks about X. The guest is headless, so xenodm stays off. The
# installer then offers to keep the console on com0. Accept it, and
# accept the default speed.
if {$arch eq "amd64"} {
expect "started by xenodm" { respond "no" }
expect "Change the default console to com0?" { respond "yes" }
expect "Which speed should com0 use?" { respond "" }
}
# Setup a user
expect "Setup a user?" { respond "no" }
# Allow root ssh login
expect "Allow root ssh login?" { respond "yes" }
# Timezone. The installer asks here only when its geolocation lookup
# gave a hint. Without one, it asks after the sets are installed. One
# block accepts both orders: answer the timezone when it arrives, and
# move on at the root-disk prompt.
expect {
"What timezone are you in?" {
respond "UTC"
share/fuguvm/expect/install.exp view on Meta::CPAN
set whole_disk "w"
}
expect {
"Use (W)hole disk" { respond $whole_disk }
"whole disk" { respond $whole_disk }
}
# Auto layout
expect {
"Use (A)uto layout" { respond "a" }
"Auto layout" { respond "a" }
}
# Additional disks to initialize: none
expect "Which disk do you wish to initialize?" { respond "done" }
# Location of sets
expect "Location of sets?" { respond "http" }
# HTTP proxy
expect "HTTP proxy URL?" { respond $proxy_url }
# HTTP server
expect "HTTP Server?" { respond "cdn.openbsd.org" }
# Server directory: accept the default
expect "Server directory?" { respond "" }
# Select the sets. Skip games and X.
expect "Set name(s)?" {
sleep 0.5
send -- "-game* -x*\r"
}
# Confirm selection
expect "Set name(s)?" { respond "done" }
# Wait for the sets to install. Then answer the prompt for more sets.
#
# The installer of a numbered release carries the release key in
# bsd.rd, and the mirror serves SHA256.sig beside the sets, so the
# installer verifies each set by itself. The verification prompt is
# therefore a report of a broken mirror. With verify yes the script
# must not answer it for the operator, and it stops. With verify no
# the script answers yes and says that the guest installs unverified
# sets.
set timeout [env_timeout 900]
expect {
"Continue without verification?" {
if {$verify eq "yes"} {
send_user "\n==> ERROR: The installer asked \"Continue without verification?\"\n"
send_user "==> The sets from cdn.openbsd.org did not verify in the guest\n"
exit 1
}
send_user "\n==> WARNING: The guest installs unverified sets\n"
respond "yes"
exp_continue
}
"Location of sets?" { respond "done" }
timeout {
send_user "\n==> ERROR: Timeout during set installation\n"
exit 1
}
}
# The installer asks the timezone here when its geolocation lookup
# gave no hint before the disk setup. It can also ask to correct the
# clock before it finishes. Answer both if they arrive. The (R)eboot?
# prompt marks the end of the install. Choose halt instead of reboot.
# Then fuguvm can restart from the installed disk without the
# miniroot attached. A single expect block matches every prompt. Thus
# a missing prompt never stalls to the timeout.
set timeout [env_timeout 900]
expect {
"What timezone are you in?" {
respond "UTC"
exp_continue
}
"Time appears wrong" {
respond "yes"
exp_continue
}
"(R)eboot?" {
respond "h"
}
timeout {
send_user "\n==> ERROR: Timeout waiting for install to finish\n"
exit 1
}
}
# The install is complete once the system halts. Do NOT wait for eof.
# OpenBSD's halt stops at the "press any key to reboot" prompt and
# does not close the console. Thus telnet stays connected and no eof
# ever arrives. fuguvm stops QEMU through QMP once this script returns.
# Then fuguvm restarts from the installed disk.
set timeout [env_timeout 120]
expect {
"The operating system has halted" { exit 0 }
"press any key to reboot" { exit 0 }
timeout {
send_user "\n==> ERROR: Timeout waiting for system halt\n"
exit 1
}
}
( run in 1.178 second using v1.01-cache-2.11-cpan-85d3896f969 )