source: trunk/debathena/scripts/installer/pxe/jaunty/debathena-jaunty/installer.sh @ 24855

Revision 24855, 9.9 KB checked in by amb, 14 years ago (diff)
Use our known static address after kexec instead of using DHCP again.
Line 
1#!/bin/sh
2
3cd /debathena-jaunty
4
5touch preseed
6
7pxetype=""
8
9# Using debconf here will hang, so parse the command line manually.
10clusterforce=`sed -e 's/ /\n/g' < /proc/cmdline | grep debathena/clusterforce | sed -e 's/.*=//'`
11clusteraddr=`sed -e 's/ /\n/g' < /proc/cmdline | grep debathena/clusteraddr | sed -e 's/.*=//'`
12
13if [ "$clusteraddr" ] ; then IPADDR=$clusteraddr ; fi
14
15if [ "$clusteraddr" -a "$clusterforce" = yes ] ; then pxetype=cluster ; fi
16
17netconfig () {
18  echo "Configuring network..."
19  mp=/debathena-jaunty
20  export IPADDR NETMASK GATEWAY SYSTEM CONTROL
21  while [ -z "$IPADDR" ] ; do
22    echo -n "Enter IP address: "
23    read IPADDR
24  done
25  NETMASK=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\  -f 1`
26  net=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\  -f 2`
27  bc=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\  -f 3`
28  GATEWAY=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\  -f 4`
29  maskbits=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\  -f 5`
30
31  echo "Address: $IPADDR"
32  echo
33  echo "Autoconfigured settings:"
34  echo "  Netmask bits: $maskbits"
35  echo "  Broadcast: $bc"
36  echo "  Gateway: $GATEWAY"
37
38  if [ "$clusterforce" != yes ] ; then
39    echo -n "Are these OK? [Y/n]: "; read response
40    case $response in
41      y|Y|"") ;;
42      *)
43      echo -n "Netmask bits [$maskbits]: "; read r; if [ "$r" ] ; then maskbits=$r ; fi
44      echo -n "Broadcast [$bc]: "; read r; if [ "$r" ] ; then bc=$r ; fi
45      echo -n "Gateway [$GATEWAY]: "; read r; if [ "$r" ] ; then GATEWAY=$r ; fi
46    esac
47  fi
48
49  # We can not set the hostname here; running "debconf-set netcfg/get_hostname"
50  # causes fatal reentry problems.  Setting values directly with preseeding
51  # also fails, as the DHCP values override it.
52  echo "Killing dhcp client."
53  killall dhclient
54  echo "Running: ip addr flush dev eth0"
55  ip addr flush dev eth0
56  echo "Running: ip addr add $IPADDR/$maskbits broadcast $bc dev eth0"
57  ip addr add $IPADDR/$maskbits broadcast $bc dev eth0
58  echo "Flushing old default route."
59  route delete default 2> /dev/null
60  echo "Running: route add default gw $GATEWAY"
61  route add default gw $GATEWAY
62  echo "Replacing installer DHCP nameserver with MIT nameservers."
63  sed -e '/nameserver/s/ .*/ 18.72.0.3/' < /etc/resolv.conf > /etc/resolv.conf.new
64  echo "nameserver      18.70.0.160" >> /etc/resolv.conf.new
65  echo "nameserver      18.71.0.151" >> /etc/resolv.conf.new
66  mv -f /etc/resolv.conf.new /etc/resolv.conf
67}
68
69# Color strings. I'd like to use tput, but the installer doesn't have it.
70esc=""
71nnn="${esc}[m"          # Normal
72ccc="${esc}[36m"        # Cyan
73rrr="${esc}[1;31m"      # Bold and red
74ddd="${esc}[1;31;47m"   # Plus gray background
75ddb="${esc}[1;31;47;5m" # Plus blinking
76
77
78echo "Welcome to Athena."
79echo
80
81while [ -z "$pxetype" ] ; do
82  echo "Choose one:"
83  echo
84  echo "  1: Perform an unattended ${ccc}debathena-cluster${nnn} install, ${rrr}ERASING your"
85  echo "     ENTIRE DISK${nnn}. This option is only intended for people setting up"
86  echo "     public cluster machines maintained by IS&T/Athena. If you select"
87  echo "     this option, you hereby agree with the license terms at:"
88  echo "     <http://dlc.sun.com/dlj/DLJ-v1.1.txt>,"
89  echo "     Sun's Operating System Distributor License for Java version 1.1."
90  echo
91  echo "  2: Do a ${ccc}normal Debathena install${nnn}.  You'll need to answer normal Ubuntu"
92  echo "     install prompts, and then the Athena-specific prompts, including"
93  echo "     choosing which flavor of Debathena you'd like (e.g., private workstation)."
94  echo
95  echo "  3: Punt to a completely ${ccc}vanilla install of Ubuntu 9.04${nnn} (Jaunty Jackalope)."
96  echo "     (Note: locale and keyboard have already been set.)"
97  echo
98  echo "  4: /bin/sh (for rescue purposes)"
99  echo
100  echo -n "Choose: "
101  read r
102  case "$r" in
103    1)
104      echo "Debathena CLUSTER it is."; pxetype=cluster ;;
105    1a)
106      # Yes, this is undocumented.
107      echo "Debathena CLUSTER it is."; pxetype=cluster
108      echo -n "...but choose a preferred mirror hostname, too: "
109      read mirrorsite
110      echo "Using mirror site $mirrorsite";;
111    1b)
112      # This too.
113      echo "Debathena CLUSTER it is."; pxetype=cluster
114      echo "...but you get to partition by hand. Your hard disk"
115      echo "will not be automatically reformatted."; destroys=notreally
116      echo
117      echo "The default cluster installer sets up:"
118      echo " - a 200MB ext3 /boot partition"
119      echo " - an LVM volume group named 'athena', containing"
120      echo "   - a (3x system RAM)-sized swap LV (at least 512 MB)"
121      echo "   - a root LV taking up half the remaining space (at least 10 GB)"
122      echo
123      echo "You probably want to set up something similar."
124      echo "Press enter to continue."
125      read r;;
126    2)
127      echo "Normal Debathena install it is."; pxetype=choose ;;
128    2a)
129      echo "Normal Debathena install it is."; pxetype=choose
130      echo -n "...but choose a preferred mirror hostname, too: "
131      read mirrorsite
132      echo "Using mirror site $mirrorsite";;
133    3)
134      echo "Vanilla Ubuntu it is."; pxetype=vanilla;;
135    4)
136      echo "Here's a shell.  You'll return to this prompt when done."
137      /bin/sh;;
138     
139    9) # switch to Lucid with architecture autodetect
140      if egrep -q '^flags[      ].* lm( |$)' /proc/cpuinfo
141        then arch=amd64 ; else arch=i386 ; fi
142      echo "OK, configuring net and then switching to a lucid $arch cluster install."
143      netconfig
144      mkdir /h; cd /h
145      wget http://debathena.mit.edu/net-install/kexec
146      wget http://debathena.mit.edu/net-install/lucid/${arch}/initrd.gz
147      wget http://debathena.mit.edu/net-install/lucid/${arch}/linux
148      chmod 755 kexec
149      # This is just the guts of the hackboot script:
150      dkargs="DEBCONF_DEBUG=5"
151      if [ "$IPADDR" = dhcp ] ; then
152        knetinfo="netcfg/get_hostname= "
153      else
154        # There's no good way to get a hostname here, but the postinstall will deal.
155        hname=install-target-host
156        knetinfo="netcfg/disable_dhcp=true \
157          netcfg/get_domain=mit.edu \
158          netcfg/get_hostname=$hname \
159          netcfg/get_nameservers=18.72.0.3 \
160          netcfg/get_ipaddress=$IPADDR \
161          netcfg/get_netmask=$NETMASK \
162          netcfg/get_gateway=$GATEWAY \
163          netcfg/confirm_static=true"
164      fi
165      kargs="$knetinfo locale=en_US console-setup/layoutcode=us interface=auto \
166          url=http://18.9.60.73/installer/lucid/debathena.preseed \
167          debathena/clusterforce=yes debathena/clusteraddr=$IPADDR --"
168      echo "Restarting into installer in five seconds."
169      ./kexec -l linux --append="$dkargs $kargs" --initrd=initrd.gz \
170          && sleep 3 && chvt 1 && sleep 2 && ./kexec -e
171      echo "Well, that didn't work.  Here's a shell."
172      /bin/sh;;
173    *)
174      echo "Choose one of the above, please.";;
175  esac
176done
177
178##############################################################################
179
180if [ -z "$mirrorsite" ] ; then mirrorsite=ubuntu.media.mit.edu ; fi
181
182# Consider setting a static IP address, especially if we can't reach the mirror.
183if [ cluster != $pxetype ]; then
184  # We're at a point in the install process where we can be fairly sure
185  # that nothing else is happening, so "killall wget" should be safe.
186  (sleep 5; killall wget >/dev/null 2>&1) &
187  if wget -s http://$mirrorsite/ubuntu ; then
188    if ip address show to 18/8 | grep -q . && ! ip address show to 18.2/16 | grep -q . ; then
189      echo "Your computer seems to be registered on MITnet."
190    else
191      echo "Your computer seems not to be registered on MITnet, but the mirror"
192      echo "site $mirrorsite is accessible."
193    fi
194    echo
195    echo "${ccc}You can continue the install using your existing dynamic address.${nnn}"
196    echo -n "Configure a static address anyway?  [y/N]: "
197    while : ; do
198      read r
199      case "$r" in
200        N*|n*|"") break;;
201        y*|Y*) netconfig; break;;
202      esac
203      echo -n "Choose: [y/N]: "
204    done
205  else
206    echo "The mirror site $mirrorsite is NOT accessible in your current"
207    echo "dynamic configuration."
208    echo
209    echo "${rrr}You must specify a static address for the installation.${nnn}"
210    netconfig
211  fi
212else
213  netconfig
214fi
215
216if [ vanilla = $pxetype ] ; then
217  echo "Starting normal Ubuntu install in five seconds."
218  sleep 5
219  exit 0
220fi
221
222if [ cluster = "$pxetype" ]; then
223  if [ notreally != "$destroys" ]; then
224    cat << EOF
225************************************************************
226               ${ddb}DESTROYS${nnn}
227${rrr}THIS PROCEDURE ${ddd}DESTROYS${nnn}${rrr} THE CONTENTS OF THE HARD DISK.${nnn}
228               ${ddb}DESTROYS${nnn}
229
230IF YOU DO NOT WISH TO CONTINUE, REBOOT NOW.
231
232************************************************************
233
234EOF
235    echo "Installing autoinstall preseed file."
236    egrep -v '(^$|^#)' < preseed.autoinstall >> preseed
237  else
238    echo "Installing autoinstall preseed file without automated partitioning."
239    egrep -v '(^$|^#|partman)' < preseed.autoinstall >> preseed
240  fi
241fi
242
243# Shovel in the generically useful preseed stuff regardless.
244egrep -v '(^$|^#)' < preseed.common >> preseed
245
246if [ "$IPADDR" ] ; then
247  # ...and the specified network config.
248  cat >> preseed <<EOF
249d-i netcfg/get_nameservers string 18.72.0.3
250d-i netcfg/get_ipaddress string $IPADDR
251d-i netcfg/get_netmask string $NETMASK
252d-i netcfg/get_gateway string $GATEWAY
253d-i netcfg/confirm_static boolean true
254EOF
255fi
256
257# Perferred hostname of mirror site
258cat >> preseed <<EOF
259d-i apt-setup/hostname string $mirrorsite
260d-i mirror/http/hostname string $mirrorsite
261EOF
262
263# This is used by the final installer step.
264# A hardcoded number is used as DNS may still be iffy.
265echo "Fetching Debathena postinstaller."
266# 18.92.2.195 = OLD athena10.mit.edu
267# 18.9.60.73 = NEW athena10.mit.edu
268wget http://18.9.60.73/install-debathena.sh
269
270# Let the postinstall know what we are up to.
271echo "$pxetype" > $mp/pxe-install-flag
272
273echo "Initial Debathena installer complete; exiting preconfig to start main install."
274if ! [ "$clusteraddr" -a "$clusterforce" = yes ] ; then
275  echo "Hit return to continue."
276  read r
277fi
278exit 0
Note: See TracBrowser for help on using the repository browser.