source: trunk/debathena/scripts/installer/pxe/lucid/debathena/installer.sh @ 25084

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