1 | #!/bin/sh |
---|
2 | |
---|
3 | dnscgi="http://18.9.60.73/website/dns.cgi" |
---|
4 | |
---|
5 | test= |
---|
6 | if [ "$1" = "--test" ]; then |
---|
7 | test="test" |
---|
8 | echo "** TESTING MODE" |
---|
9 | fi |
---|
10 | |
---|
11 | if [ "$test" != "test" ]; then |
---|
12 | cd /debathena |
---|
13 | fi |
---|
14 | |
---|
15 | debug () { |
---|
16 | if [ "$test" != "test" ]; then |
---|
17 | logger -t install.debug "$@" |
---|
18 | else |
---|
19 | echo "DEBUG: $@" |
---|
20 | fi |
---|
21 | } |
---|
22 | |
---|
23 | pxetype="" |
---|
24 | |
---|
25 | netconfig () { |
---|
26 | echo "Configuring network..." |
---|
27 | mp=/debathena |
---|
28 | if [ "$test" = "test" ]; then |
---|
29 | mp="`dirname $0`" |
---|
30 | fi |
---|
31 | export IPADDR NETMASK GATEWAY SYSTEM CONTROL HOSTNAME |
---|
32 | # This will fail if dhreg addresses ever stop being able to reach net 18 |
---|
33 | # First make sure we're talking to who we think we are |
---|
34 | havedns=n |
---|
35 | ipprompt="Enter IP address:" |
---|
36 | if [ "$(wget -qO - "$dnscgi/q")" = "Debathena DNS-CGI" ]; then |
---|
37 | havedns=y |
---|
38 | ipprompt="Enter IP address or hostname:" |
---|
39 | fi |
---|
40 | |
---|
41 | while [ -z "$IPADDR" ] ; do |
---|
42 | HOSTNAME= |
---|
43 | echo -n "$ipprompt " |
---|
44 | read IPADDR |
---|
45 | debug "In netconfig, user entered '$IPADDR'" |
---|
46 | # RFC1123 does permit hostnames to start with digits, moira doesn't |
---|
47 | # If you do that, suck it up and type the IP |
---|
48 | if echo "$IPADDR" | grep -q '[a-zA-Z]'; then |
---|
49 | HOSTNAME="$IPADDR" |
---|
50 | IPADDR= |
---|
51 | if [ "$havedns" != "y" ]; then |
---|
52 | echo "Enter a valid IP address. (DNS not available)". |
---|
53 | continue |
---|
54 | fi |
---|
55 | echo "Looking up IP for $HOSTNAME..." |
---|
56 | dig="$(wget -qO - "$dnscgi/a/$HOSTNAME")" |
---|
57 | if echo "$dig" | grep -q '^OK:'; then |
---|
58 | IPADDR="$(echo "$dig" | sed 's/^OK: //')" |
---|
59 | echo "Found $IPADDR..." |
---|
60 | else |
---|
61 | echo "$dig" |
---|
62 | echo "Could not look up IP address for $HOSTNAME. Try again." |
---|
63 | fi |
---|
64 | fi |
---|
65 | done |
---|
66 | |
---|
67 | if [ -z "$HOSTNAME" ] && [ "$havedns" = "y" ]; then |
---|
68 | dig="$(wget -qO - "$dnscgi/ptr/$IPADDR")" |
---|
69 | if echo "$dig" | grep -q '^OK:'; then |
---|
70 | HOSTNAME="$(echo "$dig" | sed 's/^OK: //')" |
---|
71 | echo "$IPADDR reverse-resolves to $HOSTNAME..." |
---|
72 | else |
---|
73 | echo "$dig" |
---|
74 | echo "Could not look up hostname for $IPADDR." |
---|
75 | echo "Cannot continue without a valid hostname." |
---|
76 | echo "Please note that if this address was newly requested," |
---|
77 | echo "or its hostname was changed, it can take up to 2 business days" |
---|
78 | echo "before DNS information is correct." |
---|
79 | echo |
---|
80 | echo "Please try again once DNS has been updated or use a different" |
---|
81 | echo "IP address. You may now restart or shut down this workstation." |
---|
82 | while true; do |
---|
83 | read foo |
---|
84 | if [ "$foo" = "xyzzy" ]; then |
---|
85 | break |
---|
86 | fi |
---|
87 | done |
---|
88 | fi |
---|
89 | fi |
---|
90 | if [ -z "$HOSTNAME" ]; then |
---|
91 | HOSTNAME=install-target-host |
---|
92 | fi |
---|
93 | |
---|
94 | HOSTNAME="$(echo "$HOSTNAME" | tr A-Z a-z | sed 's/\.mit\.edu$//')" |
---|
95 | |
---|
96 | NETMASK=`$mp/athena/netparams -f $mp/athena/masks "$IPADDR"|cut -d\ -f 1` |
---|
97 | net=`$mp/athena/netparams -f $mp/athena/masks "$IPADDR"|cut -d\ -f 2` |
---|
98 | bc=`$mp/athena/netparams -f $mp/athena/masks "$IPADDR"|cut -d\ -f 3` |
---|
99 | GATEWAY=`$mp/athena/netparams -f $mp/athena/masks "$IPADDR"|cut -d\ -f 4` |
---|
100 | maskbits=`$mp/athena/netparams -f $mp/athena/masks "$IPADDR"|cut -d\ -f 5` |
---|
101 | |
---|
102 | echo "Address: $IPADDR" |
---|
103 | echo |
---|
104 | echo "Autoconfigured settings:" |
---|
105 | echo " Netmask bits: $maskbits" |
---|
106 | echo " Broadcast: $bc" |
---|
107 | echo " Gateway: $GATEWAY" |
---|
108 | |
---|
109 | debug "Calculated values: $HOSTNAME $NETMASK $GATEWAY $bc" |
---|
110 | |
---|
111 | if [ "$pxetype" != cluster ] ; then |
---|
112 | echo -n "Are these OK? [Y/n]: "; read response |
---|
113 | case $response in |
---|
114 | y|Y|"") ;; |
---|
115 | *) |
---|
116 | echo -n "Netmask bits [$maskbits]: "; read r; if [ -n "$r" ] ; then maskbits=$r ; fi |
---|
117 | echo -n "Broadcast [$bc]: "; read r; if [ -n "$r" ] ; then bc=$r ; fi |
---|
118 | echo -n "Gateway [$GATEWAY]: "; read r; if [ -n "$r" ] ; then GATEWAY=$r ; fi |
---|
119 | esac |
---|
120 | fi |
---|
121 | |
---|
122 | if [ "$test" != "test" ]; then |
---|
123 | # We can not set the hostname here; running "debconf-set netcfg/get_hostname" |
---|
124 | # causes fatal reentry problems. Setting values directly with preseeding |
---|
125 | # also fails, as the DHCP values override it. |
---|
126 | echo "Killing dhcp client." |
---|
127 | killall dhclient |
---|
128 | echo -n "Determining which interface to use... " |
---|
129 | ETH0="$(ip -o link show | grep -v loopback | cut -d: -f 2 | tr -d ' ' | head -1)" |
---|
130 | echo "$ETH0" |
---|
131 | echo "Running: ip addr flush dev $ETH0" |
---|
132 | ip addr flush dev $ETH0 |
---|
133 | echo "Running: ip addr add $IPADDR/$maskbits broadcast $bc dev $ETH0" |
---|
134 | ip addr add "$IPADDR/$maskbits" broadcast "$bc" dev $ETH0 |
---|
135 | echo "Flushing old default route." |
---|
136 | route delete default 2> /dev/null |
---|
137 | echo "Running: route add default gw $GATEWAY" |
---|
138 | route add default gw "$GATEWAY" |
---|
139 | echo "Replacing installer DHCP nameserver with MIT nameservers." |
---|
140 | sed -e '/nameserver/s/ .*/ 18.72.0.3/' < /etc/resolv.conf > /etc/resolv.conf.new |
---|
141 | echo "nameserver 18.70.0.160" >> /etc/resolv.conf.new |
---|
142 | echo "nameserver 18.71.0.151" >> /etc/resolv.conf.new |
---|
143 | mv -f /etc/resolv.conf.new /etc/resolv.conf |
---|
144 | fi |
---|
145 | } |
---|
146 | |
---|
147 | # Color strings. I'd like to use tput, but the installer doesn't have it. |
---|
148 | esc="" |
---|
149 | nnn="${esc}[m" # Normal |
---|
150 | ccc="${esc}[36m" # Cyan |
---|
151 | rrr="${esc}[1;31m" # Bold and red |
---|
152 | ddd="${esc}[1;31;47m" # Plus gray background |
---|
153 | ddb="${esc}[1;31;47;5m" # Plus blinking |
---|
154 | |
---|
155 | |
---|
156 | mirrorsite="mirrors.mit.edu" |
---|
157 | installertype="production" |
---|
158 | distro="precise" |
---|
159 | partitioning="auto" |
---|
160 | arch="i386" |
---|
161 | # That is a space and a tab |
---|
162 | if egrep -q '^flags[ ].* lm( |$)' /proc/cpuinfo; then |
---|
163 | arch="amd64" |
---|
164 | fi |
---|
165 | |
---|
166 | # Of course the installer doesn't have `date` |
---|
167 | # time.mit.edu/kerberos.mit.edu is 18.7.21.144 |
---|
168 | # This will probably break eventually |
---|
169 | debug "** Install begins at $(nc -w1 18.7.21.144 13)" |
---|
170 | |
---|
171 | if [ -f "/debathena/version" ]; then |
---|
172 | echo -n "SVN version: " && cat /debathena/version |
---|
173 | debug "SVN: " "$(cat /debathena/version)" |
---|
174 | fi |
---|
175 | |
---|
176 | debug "Mirror $mirrorsite Type $installertype Arch $arch" |
---|
177 | |
---|
178 | echo "Welcome to Athena, Stage 1 Installer" |
---|
179 | echo |
---|
180 | |
---|
181 | while [ -z "$pxetype" ] ; do |
---|
182 | echo |
---|
183 | echo "Will install ${ccc}$distro${nnn} ($arch) using $installertype installer" |
---|
184 | echo "from $mirrorsite using $partitioning partitioning" |
---|
185 | echo |
---|
186 | echo "Choose one:" |
---|
187 | echo |
---|
188 | echo " 1: Perform an unattended ${ccc}debathena-cluster${nnn} install, ${rrr}ERASING your" |
---|
189 | echo " ENTIRE DISK${nnn}. This option is only intended for people setting up" |
---|
190 | echo " public cluster machines maintained by IS&T/Athena. " |
---|
191 | echo |
---|
192 | echo " 2: Do a ${ccc}normal Debathena install${nnn}. You'll need to answer normal Ubuntu" |
---|
193 | echo " install prompts, and then the Athena-specific prompts, including" |
---|
194 | echo " choosing which flavor of Debathena you'd like (e.g., private workstation)." |
---|
195 | echo |
---|
196 | echo " 3: Punt to a completely ${ccc}vanilla install of Ubuntu${nnn}." |
---|
197 | echo " (Note: locale and keyboard have already been set.)" |
---|
198 | echo |
---|
199 | echo " 4: /bin/sh (for rescue purposes)" |
---|
200 | echo |
---|
201 | echo " Advanced users only:" |
---|
202 | echo " m: Select a different mirror. " |
---|
203 | echo " b: Toggle between beta and production installer. " |
---|
204 | echo " d: Change the distro (version)." |
---|
205 | echo " a: Change architecture." |
---|
206 | echo " p: Toggle between manual and auto partitioning. " |
---|
207 | echo |
---|
208 | echo -n "Choose: " |
---|
209 | read r |
---|
210 | case "$r" in |
---|
211 | 1) |
---|
212 | echo "Debathena CLUSTER it is."; pxetype=cluster ;; |
---|
213 | 2) |
---|
214 | echo "Normal Debathena install it is."; pxetype=choose ;; |
---|
215 | 3) |
---|
216 | echo "Vanilla Ubuntu it is."; pxetype=vanilla;; |
---|
217 | 4) |
---|
218 | echo "Here's a shell. You'll return to this prompt when done." |
---|
219 | echo |
---|
220 | echo "Note: This shell has no job control, and unless you know" |
---|
221 | echo "what you're doing, you almost certainly want to switch to" |
---|
222 | echo "VT2 (by pressing Ctrl-Alt-F2), and use the shell there." |
---|
223 | echo "You can return to this screen (VT5) by pressing Ctrl-Alt-F5." |
---|
224 | echo |
---|
225 | /bin/sh;; |
---|
226 | m|M) |
---|
227 | echo |
---|
228 | echo "NOTE: There is no data validation. Don't make a typo." |
---|
229 | echo -n "Enter a new mirror hostname: " |
---|
230 | read mirrorsite |
---|
231 | ;; |
---|
232 | d|D) |
---|
233 | echo |
---|
234 | echo "NOTE: There is no data validation. Don't make a typo." |
---|
235 | echo -n "Enter a new distro: " |
---|
236 | read distro |
---|
237 | ;; |
---|
238 | b|B) |
---|
239 | if [ "$installertype" = "production" ]; then |
---|
240 | echo "Switching to beta installer." |
---|
241 | installertype="beta" |
---|
242 | else |
---|
243 | echo "Switching to production installer." |
---|
244 | installertype="production" |
---|
245 | fi |
---|
246 | ;; |
---|
247 | p|P) |
---|
248 | if [ "$partitioning" = "auto" ]; then |
---|
249 | echo "Switching to manual partitioning." |
---|
250 | echo "Your disk will (probably) not be erased." |
---|
251 | partitioning="manual" |
---|
252 | echo "Normally, cluster machines get:" |
---|
253 | echo " - a 200MB ext3 /boot partition" |
---|
254 | echo " - an LVM volume group named 'athena', containing" |
---|
255 | echo " - a (3x system RAM)-sized swap LV (at least 512 MB)" |
---|
256 | echo " - a root LV taking up half the remaining space (at least 10 GB)" |
---|
257 | echo |
---|
258 | echo "You probably want to set up something similar." |
---|
259 | echo |
---|
260 | echo "Backups are ALWAYS a good idea. Stop and make one now." |
---|
261 | echo "Press Enter to continue." |
---|
262 | read dummy |
---|
263 | else |
---|
264 | echo "Switching to auto partitioning." |
---|
265 | partitioning="auto" |
---|
266 | fi |
---|
267 | ;; |
---|
268 | a|A) |
---|
269 | echo |
---|
270 | oldarch="$arch" |
---|
271 | echo -n "Enter a new arch (acceptable values: i386, amd64): " |
---|
272 | read arch |
---|
273 | if [ "$arch" != "i386" ] && [ "$arch" != "amd64" ]; then |
---|
274 | echo "Invalid value. Reverting to $arch." |
---|
275 | arch="$oldarch" |
---|
276 | fi |
---|
277 | unset oldarch |
---|
278 | ;; |
---|
279 | *) |
---|
280 | echo "Choose one of the above, please.";; |
---|
281 | esac |
---|
282 | done |
---|
283 | |
---|
284 | debug "*** Main menu complete" |
---|
285 | debug "Mirror: $mirrorsite Type: $installertype Part: $partitioning" |
---|
286 | debug "Arch: $arch Distro: $distro Pxetype: $pxetype" |
---|
287 | debug "$ETH0:" |
---|
288 | debug "$(ip address show $ETH0)" |
---|
289 | debug "routing:" |
---|
290 | debug "$(route)" |
---|
291 | debug "resolv.conf:" |
---|
292 | debug "$(cat /etc/resolv.conf)" |
---|
293 | |
---|
294 | ############################################################################## |
---|
295 | |
---|
296 | |
---|
297 | # Consider setting a static IP address, especially if we can't reach the mirror. |
---|
298 | if [ cluster != "$pxetype" ]; then |
---|
299 | # We're at a point in the install process where we can be fairly sure |
---|
300 | # that nothing else is happening, so "killall wget" should be safe. |
---|
301 | (sleep 5; killall wget >/dev/null 2>&1) & |
---|
302 | if wget -s http://$mirrorsite/ubuntu ; then |
---|
303 | if ip address show to 18.0.0.0/8 | grep -q . && ! ip address show to 18.2.0.0/16 | grep -q . ; then |
---|
304 | echo "Your computer seems to be registered on MITnet." |
---|
305 | else |
---|
306 | echo "Your computer seems not to be registered on MITnet, but the mirror" |
---|
307 | echo "site $mirrorsite is accessible." |
---|
308 | fi |
---|
309 | echo |
---|
310 | echo "${ccc}You can continue the install using your existing dynamic address.${nnn}" |
---|
311 | echo -n "Configure a static address anyway? [y/N]: " |
---|
312 | while : ; do |
---|
313 | read r |
---|
314 | case "$r" in |
---|
315 | N*|n*|"") break;; |
---|
316 | y*|Y*) netconfig; break;; |
---|
317 | esac |
---|
318 | echo -n "Choose: [y/N]: " |
---|
319 | done |
---|
320 | else |
---|
321 | echo "The mirror site $mirrorsite is NOT accessible in your current" |
---|
322 | echo "dynamic configuration." |
---|
323 | echo |
---|
324 | echo "${rrr}You must specify a static address for the installation.${nnn}" |
---|
325 | netconfig |
---|
326 | fi |
---|
327 | else |
---|
328 | netconfig |
---|
329 | fi |
---|
330 | |
---|
331 | extra_kargs="" |
---|
332 | if [ "$installertype" = "beta" ]; then |
---|
333 | echo "Any extra kernel arguments to pass to kexec?" |
---|
334 | echo "(I hope you know what you're doing. Press Enter for none.)" |
---|
335 | read extra_kargs |
---|
336 | fi |
---|
337 | |
---|
338 | if [ "$pxetype" = "cluster" ] && [ "$partitioning" = "auto" ]; then |
---|
339 | cat << EOF |
---|
340 | ************************************************************ |
---|
341 | ${ddb}DESTROYS${nnn} |
---|
342 | ${rrr}THIS PROCEDURE ${ddd}DESTROYS${nnn}${rrr} THE CONTENTS OF THE HARD DISK.${nnn} |
---|
343 | ${ddb}DESTROYS${nnn} |
---|
344 | |
---|
345 | IF YOU DO NOT WISH TO CONTINUE, REBOOT NOW. |
---|
346 | |
---|
347 | ************************************************************ |
---|
348 | EOF |
---|
349 | fi |
---|
350 | echo |
---|
351 | echo "Installer configuration complete. Press Enter to begin" |
---|
352 | echo "or reboot your workstation now to abort installation." |
---|
353 | read r |
---|
354 | |
---|
355 | # Fetch secondary (real) installer, invoking as specified above: |
---|
356 | |
---|
357 | echo "Fetching next installer phase..." |
---|
358 | # Network config now done above. |
---|
359 | if [ "$test" != "test" ]; then |
---|
360 | mkdir /h; cd /h |
---|
361 | wget "http://debathena.mit.edu/net-install/kexec" |
---|
362 | wget "http://debathena.mit.edu/net-install/${distro}/${arch}/initrd.gz" |
---|
363 | wget "http://debathena.mit.edu/net-install/${distro}/${arch}/linux" |
---|
364 | chmod 755 kexec |
---|
365 | fi |
---|
366 | dkargs="DEBCONF_DEBUG=5" |
---|
367 | |
---|
368 | nodhcp="netcfg/disable_dhcp=true" |
---|
369 | case "$distro" in |
---|
370 | oneiric|precise|quantal|raring) |
---|
371 | kbdcode="keyboard-configuration/layoutcode=us" |
---|
372 | # "Yay" |
---|
373 | nodhcp="netcfg/disable_autoconfig=true" |
---|
374 | ;; |
---|
375 | natty) |
---|
376 | # Sigh |
---|
377 | kbdcode="keyboard-configuration/layoutcode=us" |
---|
378 | ;; |
---|
379 | *) |
---|
380 | kbdcode="console-setup/layoutcode=us" |
---|
381 | ;; |
---|
382 | esac |
---|
383 | |
---|
384 | hname="$HOSTNAME" |
---|
385 | if [ "$IPADDR" = dhcp ] ; then |
---|
386 | knetinfo="netcfg/get_hostname=$hname " |
---|
387 | else |
---|
388 | # There's no good way to get a hostname here, but the postinstall will deal. |
---|
389 | # True, but thanks to wget, there's a bad way to get a hostname |
---|
390 | knetinfo="$nodhcp \ |
---|
391 | netcfg/get_domain=mit.edu \ |
---|
392 | netcfg/get_hostname=$hname \ |
---|
393 | netcfg/get_nameservers=\"18.72.0.3 18.70.0.160 18.71.0.151\" \ |
---|
394 | netcfg/get_ipaddress=$IPADDR \ |
---|
395 | netcfg/get_netmask=$NETMASK \ |
---|
396 | netcfg/get_gateway=$GATEWAY \ |
---|
397 | netcfg/confirm_static=true" |
---|
398 | fi |
---|
399 | |
---|
400 | # SIGH See LP #818933 |
---|
401 | # This is fixed in Oneiric's kernel, but the PXE server is still serving |
---|
402 | # natty (and will continue to do so until we have hardware that fails) |
---|
403 | acpi="" |
---|
404 | if [ "$(cat /sys/class/dmi/id/product_name)" = "OptiPlex 790" ]; then |
---|
405 | acpi="reboot=pci" |
---|
406 | fi |
---|
407 | |
---|
408 | # TODO: Pass the actual interface we're using, not "auto" |
---|
409 | # Or decide that we only support the first interface, and determine |
---|
410 | # the name of it using the same method in stage2 |
---|
411 | kargs="$knetinfo $kbdcode $acpi locale=en_US interface=auto \ |
---|
412 | url=http://18.9.60.73/installer/$distro/debathena.preseed \ |
---|
413 | da/pxe=$pxetype da/i=$installertype da/m=$mirrorsite \ |
---|
414 | da/part=$partitioning $extra_kargs --" |
---|
415 | |
---|
416 | echo "Continuing in five seconds..." |
---|
417 | if [ "$test" = "test" ]; then |
---|
418 | echo "Would run kexec with these args:" |
---|
419 | echo "$dkargs $kargs" |
---|
420 | exit 0 |
---|
421 | fi |
---|
422 | |
---|
423 | if hash wc > /dev/null 2>&1; then |
---|
424 | if [ $(echo "$dkargs $kargs" | wc -c) -gt 512 ]; then |
---|
425 | echo "Kernel arguments exceed 512 bytes. This will probably" |
---|
426 | echo "end badly. If this install fails, be sure to mention" |
---|
427 | echo "this specific message in your bug report." |
---|
428 | fi |
---|
429 | fi |
---|
430 | |
---|
431 | debug "About to run kexec with these args: $dkargs $kargs" |
---|
432 | ./kexec -l linux --append="$dkargs $kargs" --initrd=initrd.gz \ |
---|
433 | && sleep 3 && chvt 1 && sleep 2 && ./kexec -e |
---|
434 | curaddr="$(ip address show $ETH0 | grep inet | sed -e 's/^[ ]*inet //' | cut -d/ -f 1)" |
---|
435 | echo "Secondary installed failed; please contact release-team@mit.edu" |
---|
436 | echo "with the circumstances of your install attempt. Here's a shell for debugging." |
---|
437 | echo "You can type 'httpd' to start an HTTP server which will make" |
---|
438 | echo "the system log available if you connect to http://$curaddr" |
---|
439 | # We don't want to let this fall through to an actual install of whatever |
---|
440 | # kernel we're using. |
---|
441 | while : ; do /bin/sh ; done |
---|
442 | exit 0 |
---|