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

Revision 25967, 19.5 KB checked in by jdreed, 8 years ago (diff)
Support wheezy, because apparently we didn't Note that jessie is unsupported Move the "unsupported" warning outside the case block
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# The user's umask will sometimes carry over; don't let that happen.
13umask 022
14
15output() {
16  printf '\033[38m'; echo "$@"; printf '\033[0m'
17}
18
19error() {
20  printf '\033[31m'; echo "$@"; printf '\033[0m'
21}
22
23ask() {
24  answer=''
25  while [ y != "$answer" -a n != "$answer" ]; do
26    printf '\033[38m'; echo -n "$1"; printf '\033[0m'
27    read answer
28    [ Y = "$answer" ] && answer=y
29    [ N = "$answer" ] && answer=n
30    [ -z "$answer" ] && answer=$2
31  done
32  output ""
33}
34
35if [ `id -u` != "0" ]; then
36  error "You must run the Debathena installer as root."
37  if [ -x /usr/bin/sudo ]; then
38    error "Try running 'sudo $0'."
39  fi
40  exit 1
41fi
42
43pxetype=
44if test -f /root/pxe-install-flag ; then
45  pxetype=`head -1 /root/pxe-install-flag`
46fi
47
48have_lsbrelease="$(dpkg-query -W -f '${Status}' lsb-release 2>/dev/null)"
49if [ "$have_lsbrelease" != "install ok installed" ]; then
50  echo "The installer requires the 'lsb-release' package to determine"
51  echo "whether or not installation can proceed."
52  ask "Is it ok to install this package now? [Y/n] " y
53  if [ y = "$answer" ]; then
54    if ! apt-get -qq update && apt-get -qqy install lsb-release; then
55        error "Could not install lsb-release.  Try installing it manually."
56        exit 1
57    fi
58  else
59    error "Sorry, lsb-release is required.  Cannot continue."
60    exit 1
61  fi
62fi
63distro=`lsb_release -cs`
64aptitude=aptitude
65prerelease=no
66case $distro in
67  squeeze|wheezy)
68    ;;
69  jessie)
70    prerelease=yes
71    ;;
72  lucid)
73    ubuntu=yes
74    ;;
75  precise|quantal|raring)
76    ubuntu=yes
77    aptitude=apt-get
78    ;;
79  saucy)
80    ubuntu=yes
81    aptitude=apt-get
82    prerelease=yes
83    ;;
84  lenny|hardy|intrepid|jaunty|karmic|maverick|natty|oneiric)
85    error "The release you are running ($distro) is no longer supported."
86    error "Generally, Debathena de-supports releases when they are no longer"
87    error "supported by upstream.  If you believe you received this message"
88    error "in error, please contact debathena@mit.edu."
89    exit 1
90    ;;
91  *)
92    error "Unsupported release codename: $distro"
93    error "Sorry, Debathena does not support installation on this release at this time."
94    error "(New releases may not be supported immediately after their release)."
95    error "If you believe you are running a supported release or have questions,"
96    error "please contact debathena@mit.edu"
97    exit 1
98    ;;
99esac
100
101if [ "$prerelease" = "yes" ]; then
102    output "The release you are running ($distro) is not yet supported"
103    output "and installing Debathena on it is probably a bad idea,"
104    output "particularly for any purpose other than beta testing."
105    output ""
106    output "(New releases are generally supported a couple of weeks"
107    output "after the official release date.  We strongly encourage you"
108    output "to check http://debathena.mit.edu for support information"
109    output "and try again later, or install the previous version of"
110    output "the operating system.)"
111    if ! test -f /root/pxe-install-flag; then
112        ask "Are you sure you want to proceed? [y/N] " n
113        [ y != "$answer" ] && exit 1
114    fi
115fi
116
117laptop=no
118wifi=no
119if [ -x /usr/sbin/laptop-detect ] && /usr/sbin/laptop-detect 2>/dev/null; then
120    laptop=yes
121fi
122
123if [ -x /usr/bin/nmcli ] && /usr/bin/nmcli dev status 2>/dev/null | awk '{print $2}' | grep -q 802-11-wireless; then
124    wifi=yes
125fi
126
127echo "Welcome to the Debathena installer."
128echo ""
129echo "Please choose the category which best suits your needs.  Each category"
130echo "in this list includes the functionality of the previous ones.  See the"
131echo "documentation at http://debathena.mit.edu for more information."
132echo ""
133echo "  standard:        Athena client software and customizations"
134echo "                   Recommended for laptops and single-user computers."
135echo "  login:           Allow Athena accounts to log into your machine"
136echo "                   Recommended for private remote-access servers."
137echo "  login-graphical: Athena graphical login customizations"
138echo "                   Recommended for private multi-user desktops."
139echo "  workstation:     Graphical workstation with automatic updates"
140echo "                   Recommended for auto-managed cluster-like systems."
141echo ""
142
143if [ "$laptop" = "yes" ] || [ "$wifi" = "yes" ]; then
144    cat <<EOF
145This machine appears to be a laptop or has at least one wireless
146network device.  You probably want to choose "standard" unless this
147device will have an uninterrupted network connection.
148EOF
149fi
150
151category=""
152if [ cluster = "$pxetype" ] ; then
153  category=cluster ;
154  echo "PXE cluster install detected, so installing \"cluster\"."
155fi
156while [ standard != "$category" -a login != "$category" -a \
157        login-graphical != "$category" -a workstation != "$category" -a \
158        cluster != "$category" ]; do
159  output -n "Please choose a category or press control-C to abort: "
160  read category
161done
162
163# We need noninteractive for PXE installs because you're not supposed
164# to be interactive in a late_command, and nothing works (like
165# debconf, for example).  Until #702 is fixed.
166if [ cluster = "$category" ] || test -f /root/pxe-install-flag; then
167  # We still want these set for cluster installs, which should be truly
168  # noninteractive
169  export DEBCONF_NONINTERACTIVE_SEEN=true
170  export DEBIAN_FRONTEND=noninteractive
171fi
172
173mainpackage=debathena-$category
174
175csoft=no
176tsoft=no
177resolvconfhack=no
178echo "The extra-software package installs a standard set of software"
179echo "determined to be of interest to MIT users, such as LaTeX.  It is pretty"
180echo "big (several gigabytes, possibly more)."
181echo ""
182echo "Note: This package may include software with additional license terms."
183echo "      By installing it, you are agreeing to the terms of these licenses."
184echo "      For more information, please see http://debathena.mit.edu/licensing"
185echo ""
186if [ cluster = $category -o workstation = $category ] ; then
187  # See Trac #648 and LP:471975
188  resolvconfhack=yes
189  echo "The extra-software package is required for '$category' and will be installed."
190  csoft=yes
191  # Not setting tsoft=yes here; -cluster will pull it in anyway.
192else
193  ask "Do you want the extra-software package [y/N]? " n
194  if [ y = "$answer" ]; then
195    csoft=yes
196  fi
197fi
198if [ yes = "$csoft" ]; then
199    # Preseed an answer to the java license query, which license was already accepted
200    # at install time:
201    echo "sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true" |debconf-set-selections
202fi
203
204if [ "$(cat /sys/class/dmi/id/product_name)" = "OptiPlex 790" ] && \
205    dpkg --compare-versions "$(uname -r)" lt 3.2~; then
206    noacpi=y
207    if [ "$category" != "cluster" ]; then
208        echo
209        echo "The Dell 790 sometimes has problems rebooting.  The best way to"
210        echo "work around this is to pass 'reboot=pci' at boot time."
211        echo "This change will be made in your GRUB (bootloader) configuration."
212        ask "Is it ok to do this now? [Y/n] " y
213        if [ y != "$answer" ]; then
214            noacpi=n
215        fi
216    fi
217    if [ "$noacpi" = "y" ] && ! grep -q "Added by install-debathena.sh to address reboot issues on the Dell 790" /etc/default/grub; then
218        cat >> /etc/default/grub << 'EOF'
219
220# Added by install-debathena.sh to address reboot issues on the Dell 790
221GRUB_CMDLINE_LINUX="reboot=pci $GRUB_CMDLINE_LINUX"
222EOF
223        update-grub
224    fi
225fi
226
227echo "A summary of your choices:"
228echo "  Category: $category"
229echo "  Extra-software package: $csoft"
230echo "  Third-party software package: $tsoft"
231echo ""
232if [ "$pxetype" = "cluster" ] ; then
233  if wget -q http://athena10.mit.edu/installer/installing.txt; then
234     cat installing.txt > /dev/tty6
235     date > /dev/tty6
236     chvt 6
237     rm installing.txt
238  fi
239  # Divert the default background and install our own so that failed machines
240  # are more conspicuous
241  echo "Diverting default background..."
242  bgimage=/usr/share/backgrounds/warty-final-ubuntu.png
243  divertedbg=no
244  if dpkg-divert --divert ${bgimage}.debathena --rename $bgimage; then
245      divertedbg=yes
246      if ! wget -N -O $bgimage http://debathena.mit.edu/error-background.png; then
247          echo "Hrm, that didn't work.  Oh well..."
248          dpkg-divert --rename --remove $bgimage
249          divertedbg=no
250      fi
251  fi
252
253  # Setup for package installs in a chrooted immediately-postinstall environment.
254  echo "Setting locale."
255  export LANG
256  . /etc/default/locale
257  echo "LANG set to $LANG."
258  echo "Mounting /proc."
259  mount /proc 2> /dev/null || :
260  # Clear toxic environment settings inherited from the installer.
261  unset DEBCONF_REDIR
262  unset DEBIAN_HAS_FRONTEND
263  if [ cluster = "$pxetype" ] ; then
264    # Network, LVM, and display config that's specific to PXE cluster installs.
265    # If someone is installing -cluster on an already-installed machine, it's
266    # assumed that this config has already happened and shouldn't be stomped on.
267
268    # Configure network based on the preseed file settings, if present.
269    if test -f /root/debathena.preseed && ! grep -q netcfg/get_ipaddress /proc/cmdline; then
270      # Switch to canonical hostname.
271      ohostname=`cat /etc/hostname`
272      # Hack to avoid installing debconf-get for just this.
273      ipaddr=`grep netcfg/get_ipaddress /root/debathena.preseed|sed -e 's/.* //'`
274      netmask=`grep netcfg/get_netmask /root/debathena.preseed|sed -e 's/.* //'`
275      gateway=`grep netcfg/get_gateway /root/debathena.preseed|sed -e 's/.* //'`
276
277      hostname=`host $ipaddr | \
278          sed 's#^.*domain name pointer \(.*\)$#\1#' | sed 's;\.*$;;' | \
279          tr '[A-Z]' '[a-z]'`
280      if echo $hostname|grep -q "not found" ; then
281        hostname=""
282        printf "\a"; sleep 1 ; printf "\a"; sleep 1 ;printf "\a"
283        echo "The IP address you selected, $ipaddr, does not have an associated"
284        echo "hostname.  Please confirm that you're using the correct address."
285        while [ -z "$hostname" ] ; do
286          echo -n "Enter fully qualified hostname [no default]: "
287          read hostname
288        done
289      fi
290      echo ${hostname%%.*} > /etc/hostname
291      sed -e 's/\(127\.0\.1\.1[         ]*\).*/\1'"$hostname ${hostname%%.*}/" < /etc/hosts > /etc/hosts.new
292      mv -f /etc/hosts.new /etc/hosts
293      if grep -q dhcp /etc/network/interfaces ; then
294        sed -e s/dhcp/static/ < /etc/network/interfaces > /etc/network/interfaces.new
295        echo "  address $ipaddr" >> /etc/network/interfaces.new
296        echo "  netmask $netmask" >> /etc/network/interfaces.new
297        echo "  gateway $gateway" >> /etc/network/interfaces.new
298        echo "  dns-nameservers 18.72.0.3 18.70.0.160 18.71.0.151" >> /etc/network/interfaces.new
299        mv -f /etc/network/interfaces.new /etc/network/interfaces
300      fi
301      hostname ${hostname%%.*}
302    fi
303
304  fi
305else
306  output "Press return to begin or control-C to abort"
307  read dummy
308fi
309
310# Set the "seen" flag for all debconf questions that we configure
311# cluster is still non-interactive, see above.
312# Except you can't set the "seen" flag for something that isn't installed
313# so also set some sane defaults
314cat <<EOF | debconf-set-selections
315# Set sane defaults
316openafs-client  openafs-client/thiscell string grand.central.org
317openafs-client  openafs-client/cachesize string 150000
318cyrus-common    cyrus-common/removespools       boolean false
319# A null value is fine as of krb5 1.6.dfsg.3-1
320krb5-config     krb5-config/default_realm string
321# No value means use Hesiod
322zephyr-clients  zephyr-clients/servers string
323# These are also questions asked by default, but
324# the user should probably see them anyway.
325#gdm     shared/default-x-display-manager seen true
326#hddtemp hddtemp/daemon seen true
327EOF
328
329apt-get update
330
331output "Verifying machine is up to date..."
332pattern='^0 upgraded, 0 newly installed, 0 to remove'
333if ! apt-get --simulate --assume-yes dist-upgrade | grep -q "$pattern"; then
334    if [ -n "$pxetype" ] ; then
335        output "Forcing an upgrade"
336        apt-get --assume-yes dist-upgrade
337    else
338        error "Your system is not up to date.  Proceeding with an install at"
339        error "this time could render your system unusable."
340        error "Please run 'apt-get dist-upgrade' as root or use the GUI update"
341        error "manager to ensure your system is up to date before continuing."
342        error "NOTE: You do NOT need to upgrade to a newer release of Ubuntu",
343        error "you merely need to ensure you have the latest software updates"
344        error "for the current version."
345        exit 1
346    fi
347fi
348
349if ! hash aptitude >/dev/null 2>&1; then
350  output "Installing Debathena installer dependency: aptitude"
351  apt-get -y install aptitude
352fi
353
354output "Installing Debathena installer dependencies: wget and dnsutils"
355apt-get -y install wget dnsutils
356if [ yes = "$resolvconfhack" ]; then
357  output "Installing resolvconf ahead of time"
358  apt-get -y install resolvconf
359fi
360
361# Only add our openafs component if DKMS isn't available
362openafs_component=""
363if aptitude show openafs-modules-dkms > /dev/null; then
364  modules="openafs-modules-dkms"
365else
366  openafs_component=" openafs"
367fi
368
369# Select the correct headers package
370kernel_hdr_meta_pkgs=
371if [ "$ubuntu" = "yes" ]; then
372    # Ubuntu kernel metapackages have a source of 'linux-meta'
373    # Find all of them and replace "-image-" with "-headers-".
374    # Except the source _starts with_ linux-meta because of HWE
375    # stacks (e.g. linux-meta-lts-quantal.  I hate you all.
376    kernel_hdr_meta_pkgs=$(dpkg-query -W -f '${Source}\t${Package}\n' 'linux-image-*' | awk '$1 ~ /^linux-meta/ { sub(/-image-/, "-headers-", $2); print $2 }')
377else
378    # Debian.  "Yay".  Old squeeze has linux-latest-2.6 as the
379    # metapackage.  squeeze-backpors and newer have linux-latest as
380    # the metpackage.  For bonus points, wheezy can have two packages
381    # installed with linux-latest as the metapackage, because one of
382    # those is itself a metapckage.
383    kernel_hdr_meta_pkgs=$(dpkg-query -W -f '${Source}::${Package}\n' 'linux-image-*' | awk -F:: '$1~/^linux-latest/ { sub(/-image-/, "-headers-", $2); print $2 }')
384fi
385pkgs_to_install=
386for p in $kernel_hdr_meta_pkgs; do
387    # Only install real packages
388    if apt-cache show $p | grep -q '^Source: '; then
389        pkgs_to_install=" $p"
390    fi
391done
392if [ -z "$pkgs_to_install" ]; then
393    output "We cannot find a kernel header metapackage for your kernel."
394    output "You will need one in order for DKMS to build the openafs"
395    output "kernel module.  You should probably stop here and figure out"
396    output "what kernel metapackage you're running, and install the"
397    output "corresponding kernel headers package."
398    ask "Do you want to continue anyway? [y/N] " n
399    if [ y != "$answer" ]; then
400        exit 0
401    fi
402else
403    output "Installing header packages: $pkgs_to_install"
404    apt-get -y install $pkgs_to_install
405fi
406
407output "Adding the Debathena repository to the apt sources"
408output "(This may cause the update manager to claim new upgrades are available."
409output "Ignore them until this script is complete.)"
410sourceslist=/etc/apt/sources.list.d/debathena.list
411clustersourceslist=/etc/apt/sources.list.d/debathena.clusterinfo.list
412if [ -z "$hostname" ] ; then hostname=`hostname` ; fi
413
414if [ ! -e "$sourceslist" ] || ! grep -v ^# "$sourceslist" | grep -q debathena; then
415  if [ -e "$sourceslist" ]; then
416    echo "" >> $sourceslist
417  fi
418  echo "deb http://debathena.mit.edu/apt $distro debathena debathena-config debathena-system$openafs_component" >> $sourceslist
419  echo "deb-src http://debathena.mit.edu/apt $distro debathena debathena-config debathena-system$openafs_component" >> $sourceslist
420fi
421
422# As of 6 March 2013, Hesiod no longer contains multiple unversioned
423# apt_release tokens (Trac: #1036).  development implies proposed.
424# bleeding implies development, and the transitive property applies.
425# It's possible we should have this be configurable via a URL
426# rather than hardcoded.
427apt_release=$(dig +short +bufsize=2048 ${hostname}.cluster.ns.athena.mit.edu TXT | tr -d '"' | awk '$1=="apt_release" { print $2 }')
428
429if [ -n "$apt_release" ]; then
430  extra_repos=
431  case "$apt_release" in
432    development)
433      extra_repos="development proposed" ;;
434    proposed)
435      extra_repos="proposed" ;;
436    bleeding)
437      extra_repos="bleeding development proposed" ;;
438    *)
439      output "NOTE: Ignoring unknown apt_release value: \"$apt_release\"" ;;
440  esac
441  aptexplained=false
442  for hc in $extra_repos; do
443    echo "Adding $distro-$hc apt repository."
444    if [ "${aptexplained}" = false ] ; then
445      echo "" >> $clustersourceslist
446      echo "# This file is automatically updated by debathena-auto-update" >> $clustersourceslist
447      echo "# based on your Hesiod cluster information. If you want to" >> $clustersourceslist
448      echo "# make changes, do so in another file." >> $clustersourceslist
449      aptexplained=true
450    fi
451    echo "" >> $clustersourceslist
452    echo "deb http://debathena.mit.edu/apt $distro-${hc} debathena debathena-config debathena-system$openafs_component" >> $clustersourceslist
453    echo "deb-src http://debathena.mit.edu/apt $distro-${hc} debathena debathena-config debathena-system$openafs_component" >> $clustersourceslist
454  done
455fi
456
457if [ "$ubuntu" = "yes" ]; then
458  output "Making sure the universe repository is enabled"
459  sed -i 's,^# \(deb\(\-src\)* http://archive.ubuntu.com/ubuntu [[:alnum:]]* universe\)$,\1,' /etc/apt/sources.list
460fi
461
462output "Downloading the Debathena archive signing key"
463if ! wget -N http://debathena.mit.edu/apt/debathena-archive-keyring.asc ; then
464  error "Download failed; terminating."
465  exit 1
466fi
467echo "fa787714d1ea439c28458aab64962f755e2bdee7a3520919a72b641458757fa3586fd269cc1dae8d99047e00b3df88db0826f0c99a1f5a8771618b3c0be8e3bd  ./debathena-archive-keyring.asc" | \
468  sha512sum -c
469apt-key add debathena-archive-keyring.asc
470rm ./debathena-archive-keyring.asc
471
472$aptitude update
473
474if [ -z "$modules" ]; then
475  modules_want=$(dpkg-query -W -f '${Source}\t${Package}\n' 'linux-image-*' | \
476   sed -nre 's/^linux-(meta|latest[^\t]*)\tlinux-image-(.*)$/openafs-modules-\2/p')
477  modules=
478  for m in $modules_want; do
479    aptitude show $m > /dev/null && modules="$modules $m"
480  done
481fi
482
483if [ -z "$modules" ]; then
484  error "An OpenAFS modules metapackage for your kernel is not available."
485  error "Please use the manual installation instructions at"
486  error "http://debathena.mit.edu/install"
487  error "You will need to compile your own AFS modules as described at:"
488  error "http://debathena.mit.edu/troubleshooting#openafs-custom"
489  exit 1
490fi
491
492output "Installing OpenAFS kernel metapackage"
493apt-get -y install $modules
494
495if [ "cluster" = "$category" ] || [ "workstation" = "$category" ] ; then
496    output "Installing debathena-license-config"
497    apt-get -y install debathena-license-config
498fi
499
500# Use the noninteractive frontend to install the main package.  This
501# is so that AFS and Zephyr don't ask questions of the user which
502# debathena packages will later stomp on anyway.
503output "Installing main Debathena metapackage $mainpackage"
504
505$aptitude -y install "$mainpackage"
506
507# Use the default front end and allow questions to be asked; otherwise
508# Java will fail to install since it has to present its license.
509if [ yes = "$csoft" ]; then
510  output "Installing debathena-extra-software"
511  DEBIAN_PRIORITY=critical $aptitude -y install debathena-extra-software
512fi
513if [ yes = "$tsoft" ]; then
514  output "Installing debathena-thirdparty"
515  DEBIAN_PRIORITY=critical $aptitude -y install debathena-thirdparty
516fi
517
518# Post-install cleanup for cluster systems.
519if [ "$divertedbg" = "yes" ]; then
520    rm -f $bgimage
521    if ! dpkg-divert --rename --remove $bgimage; then
522        echo "Failed to remove diversion of background.  You probably don't care."
523    fi
524fi
525
526if [ cluster = "$category" ] ; then
527  # Force an /etc/adjtime entry so there's no confusion about whether the
528  # hardware clock is UTC or local.
529  echo "Setting hardware clock to UTC."
530  hwclock --systohc --utc
531fi
532
533# Remove the pxe install flag
534rm -f /root/pxe-install-flag
535   
Note: See TracBrowser for help on using the repository browser.