|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2014 The Go Authors. All rights reserved. |
| 3 | +# Use of this source code is governed by a BSD-style |
| 4 | +# license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# Download kernel, sets, etc. from ftp.usa.openbsd.org |
| 9 | +if ! [ -e install56.iso ]; then |
| 10 | + curl -O ftp://ftp.usa.openbsd.org/pub/OpenBSD/5.6/amd64/install56.iso |
| 11 | +fi |
| 12 | + |
| 13 | +# XXX: Download and save bash, curl, and their dependencies too? |
| 14 | +# Currently we download them from the network during the install process. |
| 15 | + |
| 16 | +# Create custom site56.tgz set. |
| 17 | +mkdir -p etc |
| 18 | +cat >install.site <<EOF |
| 19 | +#!/bin/sh |
| 20 | +env PKG_PATH=ftp://ftp.usa.openbsd.org/pub/OpenBSD/5.6/packages/amd64 pkg_add -iv bash curl |
| 21 | +
|
| 22 | +# See https://code.google.com/p/google-compute-engine/issues/detail?id=77 |
| 23 | +echo "ignore classless-static-routes;" >> /etc/dhclient.conf |
| 24 | +EOF |
| 25 | +cat >etc/rc.local <<EOF |
| 26 | +( |
| 27 | + set -x |
| 28 | + echo "starting buildlet script" |
| 29 | + netstat -rn |
| 30 | + cat /etc/resolv.conf |
| 31 | + dig metadata.google.internal |
| 32 | + ( |
| 33 | + set -e |
| 34 | + export PATH="\$PATH:/usr/local/bin" |
| 35 | + /usr/local/bin/curl -o /buildlet \$(/usr/local/bin/curl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/buildlet-binary-url) |
| 36 | + chmod +x /buildlet |
| 37 | + exec /buildlet |
| 38 | + ) |
| 39 | + echo "giving up" |
| 40 | + sleep 10 |
| 41 | + halt -p |
| 42 | +) |
| 43 | +EOF |
| 44 | +chmod +x install.site |
| 45 | +tar -zcvf site56.tgz install.site etc/rc.local |
| 46 | + |
| 47 | +# Hack install CD a bit. |
| 48 | +echo 'set tty com0' > boot.conf |
| 49 | +dd if=/dev/urandom of=random.seed bs=4096 count=1 |
| 50 | +cp install56.iso install56-patched.iso |
| 51 | +growisofs -M install56-patched.iso -l -R -graft-points \ |
| 52 | + /5.6/amd64/site56.tgz=site56.tgz \ |
| 53 | + /etc/boot.conf=boot.conf \ |
| 54 | + /etc/random.seed=random.seed |
| 55 | + |
| 56 | +# Initialize disk image. |
| 57 | +rm -f disk.raw |
| 58 | +qemu-img create -f raw disk.raw 10G |
| 59 | + |
| 60 | +# Run the installer to create the disk image. |
| 61 | +expect <<EOF |
| 62 | +spawn qemu-system-x86_64 -nographic -smp 2 -drive if=virtio,file=disk.raw -cdrom install56-patched.iso -net nic,model=virtio -net user -boot once=d |
| 63 | +
|
| 64 | +expect "boot>" |
| 65 | +send "\n" |
| 66 | +
|
| 67 | +# Need to wait for the kernel to boot. |
| 68 | +expect -timeout 600 "\(I\)nstall, \(U\)pgrade, \(A\)utoinstall or \(S\)hell\?" |
| 69 | +send "i\n" |
| 70 | +
|
| 71 | +expect "Terminal type\?" |
| 72 | +send "vt220\n" |
| 73 | +
|
| 74 | +expect "System hostname\?" |
| 75 | +send "buildlet\n" |
| 76 | +
|
| 77 | +expect "Which network interface do you wish to configure\?" |
| 78 | +send "vio0\n" |
| 79 | +
|
| 80 | +expect "IPv4 address for vio0\?" |
| 81 | +send "dhcp\n" |
| 82 | +
|
| 83 | +expect "IPv6 address for vio0\?" |
| 84 | +send "none\n" |
| 85 | +
|
| 86 | +expect "Which network interface do you wish to configure\?" |
| 87 | +send "done\n" |
| 88 | +
|
| 89 | +expect "Password for root account\?" |
| 90 | +send "root\n" |
| 91 | +
|
| 92 | +expect "Password for root account\?" |
| 93 | +send "root\n" |
| 94 | +
|
| 95 | +expect "Start sshd\(8\) by default\?" |
| 96 | +send "yes\n" |
| 97 | +
|
| 98 | +expect "Start ntpd\(8\) by default\?" |
| 99 | +send "no\n" |
| 100 | +
|
| 101 | +expect "Do you expect to run the X Window System\?" |
| 102 | +send "no\n" |
| 103 | +
|
| 104 | +expect "Do you want the X Window System to be started by xdm\(1\)\?" |
| 105 | +send "no\n" |
| 106 | +
|
| 107 | +expect "Do you want to suspend on lid close\?" |
| 108 | +send "no\n" |
| 109 | +
|
| 110 | +expect "Change the default console to com0\?" |
| 111 | +send "yes\n" |
| 112 | +
|
| 113 | +expect "Which speed should com0 use\?" |
| 114 | +send "115200\n" |
| 115 | +
|
| 116 | +expect "Setup a user\?" |
| 117 | +send "gopher\n" |
| 118 | +
|
| 119 | +expect "Full name for user gopher\?" |
| 120 | +send "Gopher Gopherson\n" |
| 121 | +
|
| 122 | +expect "Password for user gopher\?" |
| 123 | +send "gopher\n" |
| 124 | +
|
| 125 | +expect "Password for user gopher\?" |
| 126 | +send "gopher\n" |
| 127 | +
|
| 128 | +expect "Since you set up a user, disable sshd\(8\) logins to root\?" |
| 129 | +send "yes\n" |
| 130 | +
|
| 131 | +expect "What timezone are you in\?" |
| 132 | +send "US/Pacific\n" |
| 133 | +
|
| 134 | +expect "Which disk is the root disk\?" |
| 135 | +send "sd0\n" |
| 136 | +
|
| 137 | +expect "Use DUIDs rather than device names in fstab\?" |
| 138 | +send "yes\n" |
| 139 | +
|
| 140 | +expect "Use \(W\)hole disk or \(E\)dit the MBR\?" |
| 141 | +send "whole\n" |
| 142 | +
|
| 143 | +expect "Use \(A\)uto layout, \(E\)dit auto layout, or create \(C\)ustom layout\?" |
| 144 | +send "custom\n" |
| 145 | +
|
| 146 | +expect "> " |
| 147 | +send "z\n" |
| 148 | +
|
| 149 | +expect "> " |
| 150 | +send "a b\n" |
| 151 | +expect "offset: " |
| 152 | +send "\n" |
| 153 | +expect "size: " |
| 154 | +send "1G\n" |
| 155 | +expect "FS type: " |
| 156 | +send "swap\n" |
| 157 | +
|
| 158 | +expect "> " |
| 159 | +send "a a\n" |
| 160 | +expect "offset: " |
| 161 | +send "\n" |
| 162 | +expect "size: " |
| 163 | +send "\n" |
| 164 | +expect "FS type: " |
| 165 | +send "4.2BSD\n" |
| 166 | +expect "mount point: " |
| 167 | +send "/\n" |
| 168 | +
|
| 169 | +expect "> " |
| 170 | +send "w\n" |
| 171 | +expect "> " |
| 172 | +send "q\n" |
| 173 | +
|
| 174 | +expect "Location of sets\?" |
| 175 | +send "cd\n" |
| 176 | +
|
| 177 | +expect "Which CD-ROM contains the install media\?" |
| 178 | +send "cd0\n" |
| 179 | +
|
| 180 | +expect "Pathname to the sets\?" |
| 181 | +send "5.6/amd64\n" |
| 182 | +
|
| 183 | +expect "Set name\(s\)\?" |
| 184 | +send "+*\n" |
| 185 | +
|
| 186 | +expect "Set name\(s\)\?" |
| 187 | +send " -x*\n" |
| 188 | +
|
| 189 | +expect "Set name\(s\)\?" |
| 190 | +send " -game*\n" |
| 191 | +
|
| 192 | +expect "Set name\(s\)\?" |
| 193 | +send " -man*\n" |
| 194 | +
|
| 195 | +expect "Set name\(s\)\?" |
| 196 | +send "done\n" |
| 197 | +
|
| 198 | +expect "Directory does not contain SHA256\.sig\. Continue without verification\?" |
| 199 | +send "yes\n" |
| 200 | +
|
| 201 | +# Need to wait for previous sets to unpack. |
| 202 | +expect -timeout 600 "Location of sets\?" |
| 203 | +send "done\n" |
| 204 | +
|
| 205 | +# Need to wait for install.site to install curl. |
| 206 | +expect -timeout 600 "CONGRATULATIONS!" |
| 207 | +
|
| 208 | +expect "# " |
| 209 | +send "halt\n" |
| 210 | +
|
| 211 | +expect "Please press any key to reboot.\n" |
| 212 | +send "\n" |
| 213 | +
|
| 214 | +expect "boot>" |
| 215 | +send "\n" |
| 216 | +
|
| 217 | +expect -timeout 600 eof |
| 218 | +EOF |
| 219 | + |
| 220 | +# Create Compute Engine disk image. |
| 221 | +echo "Zipping disk.raw... (this may take a while)" |
| 222 | +tar -Szcf openbsd-amd64-gce.tar.gz disk.raw |
| 223 | + |
| 224 | +echo "Done. GCE image is openbsd-amd64-gce.tar.gz." |
0 commit comments