source: trunk/debathena/scripts/installer/install-debathena.beta.sh @ 25371

Revision 25371, 14.9 KB checked in by jdreed, 13 years ago (diff)
Attmpet to detect laptops (Trac: #613)
Line 
1#!/bin/sh
2# Athena installer script.
3# Maintainer: debathena@mit.edu
4# Based on original Debathena installer script by: Tim Abbott <tabbott@mit.edu>
5
6# Download this to a Debian or Ubuntu machine and run it as root.  It can
7# be downloaded with:
8#   wget -N http://debathena.mit.edu/install-debathena.sh
9
10set -e
11
12# If we run with the noninteractive frontend, mark Debconf questions as
13# seen, so you don't see all the suppressed questions next time you
14# upgrade that package, or worse, upgrade releases.
15export DEBCONF_NONINTERACTIVE_SEEN=true
16
17output() {
18  printf '\033[38m'; echo "$@"; printf '\033[0m'
19}
20
21error() {
22  printf '\033[31m'; echo "$@"; printf '\033[0m'
23}
24
25ask() {
26  answer=''
27  while [ y != "$answer" -a n != "$answer" ]; do
28    printf '\033[38m'; echo -n "$1"; printf '\033[0m'
29    read answer
30    [ Y = "$answer" ] && answer=y
31    [ N = "$answer" ] && answer=n
32    [ -z "$answer" ] && answer=$2
33  done
34  output ""
35}
36
37if [ `id -u` != "0" ]; then
38  error "You must run the Debathena installer as root."
39  if [ -x /usr/bin/sudo ]; then
40    error "Try running 'sudo $0'."
41  fi
42  exit 1
43fi
44
45have_lsbrelease="$(dpkg-query -W -f '${Status}' lsb-release 2>/dev/null)"
46if [ "$have_lsbrelease" != "install ok installed" ]; then
47  echo "The installer requires the 'lsb-release' package to determine"
48  echo "whether or not installation can proceed."
49  ask "Is it ok to install this package now? [Y/n] " y
50  if [ y = "$answer" ]; then
51    if ! apt-get -qq update && apt-get -qqy install lsb-release; then
52        error "Could not install lsb-release.  Try installing it manually."
53        exit 1
54    fi
55  else
56    error "Sorry, lsb-release is required.  Cannot continue."
57    exit 1
58  fi
59fi
60distro=`lsb_release -cs`
61case $distro in
62  lenny|squeeze)
63    ;;
64  hardy|intrepid|jaunty|karmic|lucid|maverick|natty)
65    ubuntu=yes
66    ;;
67  *)
68    error "Unsupported release codename: $distro"
69    error "Sorry, Debathena does not support installation on this release at this time."
70    error "(New releases may not be supported immediately after their release)."
71    error "If you believe you are running a supported release or have questions,"
72    error "please contact debathena@mit.edu"
73    exit 1
74    ;;
75esac
76
77laptop=no
78wifi=no
79if [ -x /usr/sbin/laptop-detect ] && /usr/sbin/laptop-detect 2>/dev/null; then
80    laptop=yes
81fi
82
83if [ -x /usr/bin/nmcli ] && /usr/bin/nmcli dev status 2>/dev/null | awk '{print $2}' | grep -q 802-11-wireless; then
84    wifi=yes
85fi
86
87echo "Welcome to the Debathena installer."
88echo ""
89echo "Please choose the category which best suits your needs.  Each category"
90echo "in this list includes the functionality of the previous ones.  See the"
91echo "documentation at http://debathena.mit.edu for more information."
92echo ""
93echo "  standard:        Athena client software and customizations"
94echo "                   Recommended for laptops and single-user computers."
95echo "  login:           Allow Athena accounts to log into your machine"
96echo "                   Recommended for private remote-access servers."
97echo "  login-graphical: Athena graphical login customizations"
98echo "                   Recommended for private multi-user desktops."
99echo "  workstation:     Graphical workstation with automatic updates"
100echo "                   Recommended for auto-managed cluster-like systems."
101echo ""
102
103if [ "$laptop" = "yes" ] || [ "$wifi" = "yes" ]; then
104    cat <<EOF
105This machine appears to be a laptop or has at least one wireless
106network device.  You probably want to choose "standard" unless this
107device will have an uninterrupted network connection.
108EOF
109fi
110
111category=""
112if test -f /root/pxe-install-flag ; then
113  pxetype=`head -1 /root/pxe-install-flag`
114  if [ cluster = "$pxetype" ] ; then
115    category=cluster ;
116    echo "PXE cluster install detected, so installing \"cluster\"."
117  fi
118fi
119while [ standard != "$category" -a login != "$category" -a \
120        login-graphical != "$category" -a workstation != "$category" -a \
121        cluster != "$category" ]; do
122  output -n "Please choose a category or press control-C to abort: "
123  read category
124done
125mainpackage=debathena-$category
126
127csoft=no
128tsoft=no
129resolvconfhack=no
130echo "The extra-software package installs a standard set of software"
131echo "determined to be of interest to MIT users, such as LaTeX.  It is pretty"
132echo "big (several gigabytes, possibly more)."
133echo ""
134echo "Note: This package may include software with additional license terms."
135echo "      By installing it, you are agreeing to the terms of these licenses."
136echo "      For more information, please see http://debathena.mit.edu/licensing"
137echo ""
138if [ cluster = $category -o workstation = $category ] ; then
139  # See Trac #648 and LP:471975
140  resolvconfhack=yes
141  echo "The extra-software package is required for '$category' and will be installed."
142  csoft=yes
143  # Not setting tsoft=yes here; -cluster will pull it in anyway.
144else
145  ask "Do you want the extra-software package [y/N]? " n
146  if [ y = "$answer" ]; then
147    csoft=yes
148  fi
149fi
150if [ yes = "$csoft" ]; then
151    # Preseed an answer to the java license query, which license was already accepted
152    # at install time:
153    echo "sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true" |debconf-set-selections
154fi
155
156if [ "$(cat /sys/class/dmi/id/product_name)" = "OptiPlex 790" ]; then
157    noacpi=y
158    if [ "$category" != "cluster" ]; then
159        echo
160        echo "The Dell 790 sometimes has problems rebooting.  The best way to"
161        echo "work around this is to pass 'reboot=pci' at boot time."
162        echo "This change will be made in your GRUB (bootloader) configuration."
163        ask "Is it ok to do this now? [Y/n] " y
164        if [ y != "$answer" ]; then
165            noacpi=n
166        fi
167    fi
168    if [ "$noacpi" = "y" ] && ! grep -q "Added by install-debathena.sh to address reboot issues on the Dell 790" /etc/default/grub; then
169        cat >> /etc/default/grub << 'EOF'
170
171# Added by install-debathena.sh to address reboot issues on the Dell 790
172GRUB_CMDLINE_LINUX="reboot=pci $GRUB_CMDLINE_LINUX"
173EOF
174        update-grub
175    fi
176fi
177
178echo "A summary of your choices:"
179echo "  Category: $category"
180echo "  Extra-software package: $csoft"
181echo "  Third-party software package: $tsoft"
182echo ""
183if [ "$pxetype" = "cluster" ] ; then
184  if wget -q http://athena10.mit.edu/installer/installing.txt; then
185     cat installing.txt > /dev/tty6
186     date > /dev/tty6
187     chvt 6
188  fi
189  # Divert the default background and install our own so that failed machines
190  # are more conspicuous
191  echo "Diverting default background..."
192  bgimage=/usr/share/backgrounds/warty-final-ubuntu.png
193  divertedbg=no
194  if dpkg-divert --divert ${bgimage}.debathena --rename $bgimage; then
195      divertedbg=yes
196      if ! wget -N -O $bgimage http://debathena.mit.edu/error-background.png; then
197          echo "Hrm, that didn't work.  Oh well..."
198          dpkg-divert --rename --remove $bgimage
199          divertedbg=no
200      fi
201  fi
202
203  # Setup for package installs in a chrooted immediately-postinstall environment.
204  echo "Setting locale."
205  export LANG
206  . /etc/default/locale
207  echo "LANG set to $LANG."
208  echo "Mounting /proc."
209  mount /proc 2> /dev/null || :
210  # Clear toxic environment settings inherited from the installer.
211  unset DEBCONF_REDIR
212  unset DEBIAN_HAS_FRONTEND
213  if [ cluster = "$pxetype" ] ; then
214    # Network, LVM, and display config that's specific to PXE cluster installs.
215    # If someone is installing -cluster on an already-installed machine, it's
216    # assumed that this config has already happened and shouldn't be stomped on.
217
218    # Configure network based on the preseed file settings, if present.
219    if test -f /root/debathena.preseed ; then
220      # Switch to canonical hostname.
221      ohostname=`cat /etc/hostname`
222      # Hack to avoid installing debconf-get for just this.
223      ipaddr=`grep netcfg/get_ipaddress /root/debathena.preseed|sed -e 's/.* //'`
224      netmask=`grep netcfg/get_netmask /root/debathena.preseed|sed -e 's/.* //'`
225      gateway=`grep netcfg/get_gateway /root/debathena.preseed|sed -e 's/.* //'`
226
227      hostname=`host $ipaddr | \
228          sed 's#^.*domain name pointer \(.*\)$#\1#' | sed 's;\.*$;;' | \
229          tr '[A-Z]' '[a-z]'`
230      if echo $hostname|grep -q "not found" ; then
231        hostname=""
232        printf "\a"; sleep 1 ; printf "\a"; sleep 1 ;printf "\a"
233        echo "The IP address you selected, $ipaddr, does not have an associated"
234        echo "hostname.  Please confirm that you're using the correct address."
235        while [ -z "$hostname" ] ; do
236          echo -n "Enter fully qualified hostname [no default]: "
237          read hostname
238        done
239      fi
240      echo ${hostname%%.*} > /etc/hostname
241      sed -e 's/\(127\.0\.1\.1[         ]*\).*/\1'"$hostname ${hostname%%.*}/" < /etc/hosts > /etc/hosts.new
242      mv -f /etc/hosts.new /etc/hosts
243      if grep -q dhcp /etc/network/interfaces ; then
244        sed -e s/dhcp/static/ < /etc/network/interfaces > /etc/network/interfaces.new
245        echo "  address $ipaddr" >> /etc/network/interfaces.new
246        echo "  netmask $netmask" >> /etc/network/interfaces.new
247        echo "  gateway $gateway" >> /etc/network/interfaces.new
248        echo "  dns-nameservers 18.72.0.3 18.70.0.160 18.71.0.151" >> /etc/network/interfaces.new
249        mv -f /etc/network/interfaces.new /etc/network/interfaces
250      fi
251      hostname ${hostname%%.*}
252    fi
253
254  fi
255else
256  output "Press return to begin or control-C to abort"
257  read dummy
258fi
259
260apt-get update
261
262output "Verifying machine is up to date..."
263pattern='^0 upgraded, 0 newly installed, 0 to remove'
264if ! apt-get --simulate --assume-yes dist-upgrade | grep -q "$pattern"; then
265    if [ -n "$pxetype" ] ; then
266        output "Forcing an upgrade"
267        apt-get --assume-yes dist-upgrade
268    else
269        error "Your system is not up to date.  Proceeding with an install at"
270        error "this time could render your system unusable."
271        error "Please run 'apt-get dist-upgrade' as root or use the GUI update"
272        error "manager to ensure your system is up to date before continuing."
273        error "NOTE: You do NOT need to upgrade to a newer release of Ubuntu",
274        error "you merely need to ensure you have the latest software updates"
275        error "for the current version."
276        exit 1
277    fi
278fi
279
280if ! hash aptitude >/dev/null 2>&1; then
281  output "Installing Debathena installer dependency: aptitude"
282  apt-get -y install aptitude
283fi
284
285output "Installing Debathena installer dependencies: wget and dnsutils"
286aptitude -y install wget dnsutils
287if [ yes = "$resolvconfhack" ]; then
288  output "Installing resolvconf ahead of time"
289  aptitude -y install resolvconf
290fi
291
292if aptitude show openafs-modules-dkms > /dev/null; then
293  openafs_component=" openafs"
294  modules="openafs-modules-dkms"
295fi
296
297output "Adding the Debathena repository to the apt sources"
298output "(This may cause the update manager to claim new upgrades are available."
299output "Ignore them until this script is complete.)"
300sourceslist=/etc/apt/sources.list.d/debathena.list
301clustersourceslist=/etc/apt/sources.list.d/debathena.clusterinfo.list
302if [ -z "$hostname" ] ; then hostname=`hostname` ; fi
303
304if [ ! -e "$sourceslist" ] || ! grep -q debathena "$sourceslist"; then
305  if [ -e "$sourceslist" ]; then
306    echo "" >> $sourceslist
307  fi
308  echo "deb http://debathena.mit.edu/apt $distro debathena debathena-config debathena-system$openafs_component" >> $sourceslist
309  echo "deb-src http://debathena.mit.edu/apt $distro debathena debathena-config debathena-system$openafs_component" >> $sourceslist
310fi
311
312# Note that hesiod may contain multiple apt_release tokens.  We want to
313# include known repositories but make no assumptions about wanting
314# others.  (For instances, "development" does @i{not} automatically
315# infer "proposed".)
316hescluster=$(dig +short +bufsize=2048 ${hostname}.cluster.ns.athena.mit.edu TXT) || hescluster=""
317
318aptexplained=false
319for hc in proposed development bleeding; do
320  if echo "$hescluster" | grep -Fxq "\"apt_release $hc\""; then
321    echo "Adding $distro-$hc apt repository."
322    if [ "${aptexplained}" = false ] ; then
323      echo "" >> $clustersourceslist
324      echo "# This file is automatically updated by debathena-auto-update" >> $clustersourceslist
325      echo "# based on your Hesiod cluster information. If you want to" >> $clustersourceslist
326      echo "# make changes, do so in another file." >> $clustersourceslist
327      aptexplained=true
328    fi
329    echo "" >> $clustersourceslist
330    echo "deb http://debathena.mit.edu/apt $distro-${hc} debathena debathena-config debathena-system$openafs_component" >> $clustersourceslist
331    echo "deb-src http://debathena.mit.edu/apt $distro-${hc} debathena debathena-config debathena-system$openafs_component" >> $clustersourceslist
332  fi
333done
334
335if [ "$ubuntu" = "yes" ]; then
336  output "Making sure the universe repository is enabled"
337  sed -i 's,^# \(deb\(\-src\)* http://archive.ubuntu.com/ubuntu [[:alnum:]]* universe\)$,\1,' /etc/apt/sources.list
338fi
339
340output "Downloading the Debathena archive signing key"
341if ! wget -N http://debathena.mit.edu/apt/debathena-archive-keyring.asc ; then
342  error "Download failed; terminating."
343  exit 1
344fi
345echo "fa787714d1ea439c28458aab64962f755e2bdee7a3520919a72b641458757fa3586fd269cc1dae8d99047e00b3df88db0826f0c99a1f5a8771618b3c0be8e3bd  ./debathena-archive-keyring.asc" | \
346  sha512sum -c
347apt-key add debathena-archive-keyring.asc
348rm ./debathena-archive-keyring.asc
349
350apt-get update
351
352if [ -z "$modules" ]; then
353  modules_want=$(dpkg-query -W -f '${Source}\t${Package}\n' 'linux-image-*' | \
354   sed -nre 's/^linux-(meta|latest[^\t]*)\tlinux-image-(.*)$/openafs-modules-\2/p')
355  modules=
356  for m in $modules_want; do
357    aptitude show $m > /dev/null && modules="$modules $m"
358  done
359fi
360
361if [ -z "$modules" ]; then
362  error "An OpenAFS modules metapackage for your kernel is not available."
363  error "Please use the manual installation instructions at"
364  error "http://debathena.mit.edu/install"
365  error "You will need to compile your own AFS modules as described at:"
366  error "http://debathena.mit.edu/troubleshooting#openafs-custom"
367  exit 1
368fi
369
370output "Installing OpenAFS kernel metapackage"
371apt-get -y install $modules
372
373if [ "cluster" = "$category" ] || [ "workstation" = "$category" ] ; then
374    output "Installing debathena-license-config"
375    apt-get -y install debathena-license-config
376fi
377
378# Use the noninteractive frontend to install the main package.  This
379# is so that AFS and Zephyr don't ask questions of the user which
380# debathena packages will later stomp on anyway.
381output "Installing main Debathena metapackage $mainpackage"
382
383DEBIAN_FRONTEND=noninteractive aptitude -y install "$mainpackage"
384
385# Use the default front end and allow questions to be asked; otherwise
386# Java will fail to install since it has to present its license.
387if [ yes = "$csoft" ]; then
388  output "Installing debathena-extra-software"
389  DEBIAN_PRIORITY=critical aptitude -y install debathena-extra-software
390fi
391if [ yes = "$tsoft" ]; then
392  output "Installing debathena-thirdparty"
393  DEBIAN_PRIORITY=critical aptitude -y install debathena-thirdparty
394fi
395
396# Post-install cleanup for cluster systems.
397if [ "$divertedbg" = "yes" ]; then
398    rm -f $bgimage
399    if ! dpkg-divert --rename --remove $bgimage; then
400        echo "Failed to remove diversion of background.  You probably don't care."
401    fi
402fi
403
404if [ cluster = "$category" ] ; then
405  # Force an /etc/adjtime entry so there's no confusion about whether the
406  # hardware clock is UTC or local.
407  echo "Setting hardware clock to UTC."
408  hwclock --systohc --utc
409fi
Note: See TracBrowser for help on using the repository browser.