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

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