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

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