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

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