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

Revision 25635, 15.8 KB checked in by jdreed, 12 years ago (diff)
* Cleanup installing.txt * Abuse dpkg --compare-versions to determine whether to add the reboot=pci hack or not
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)
74    ubuntu=yes
75    ;;
76  precise)
77    ubuntu=yes
78    output "The release you are running ($distro) is not fully 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 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)" ge 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  fi
212  # Divert the default background and install our own so that failed machines
213  # are more conspicuous
214  echo "Diverting default background..."
215  bgimage=/usr/share/backgrounds/warty-final-ubuntu.png
216  divertedbg=no
217  if dpkg-divert --divert ${bgimage}.debathena --rename $bgimage; then
218      divertedbg=yes
219      if ! wget -N -O $bgimage http://debathena.mit.edu/error-background.png; then
220          echo "Hrm, that didn't work.  Oh well..."
221          dpkg-divert --rename --remove $bgimage
222          divertedbg=no
223      fi
224  fi
225
226  # Setup for package installs in a chrooted immediately-postinstall environment.
227  echo "Setting locale."
228  export LANG
229  . /etc/default/locale
230  echo "LANG set to $LANG."
231  echo "Mounting /proc."
232  mount /proc 2> /dev/null || :
233  # Clear toxic environment settings inherited from the installer.
234  unset DEBCONF_REDIR
235  unset DEBIAN_HAS_FRONTEND
236  if [ cluster = "$pxetype" ] ; then
237    # Network, LVM, and display config that's specific to PXE cluster installs.
238    # If someone is installing -cluster on an already-installed machine, it's
239    # assumed that this config has already happened and shouldn't be stomped on.
240
241    # Configure network based on the preseed file settings, if present.
242    if test -f /root/debathena.preseed && ! grep -q netcfg/get_ipaddress /proc/cmdline; then
243      # Switch to canonical hostname.
244      ohostname=`cat /etc/hostname`
245      # Hack to avoid installing debconf-get for just this.
246      ipaddr=`grep netcfg/get_ipaddress /root/debathena.preseed|sed -e 's/.* //'`
247      netmask=`grep netcfg/get_netmask /root/debathena.preseed|sed -e 's/.* //'`
248      gateway=`grep netcfg/get_gateway /root/debathena.preseed|sed -e 's/.* //'`
249
250      hostname=`host $ipaddr | \
251          sed 's#^.*domain name pointer \(.*\)$#\1#' | sed 's;\.*$;;' | \
252          tr '[A-Z]' '[a-z]'`
253      if echo $hostname|grep -q "not found" ; then
254        hostname=""
255        printf "\a"; sleep 1 ; printf "\a"; sleep 1 ;printf "\a"
256        echo "The IP address you selected, $ipaddr, does not have an associated"
257        echo "hostname.  Please confirm that you're using the correct address."
258        while [ -z "$hostname" ] ; do
259          echo -n "Enter fully qualified hostname [no default]: "
260          read hostname
261        done
262      fi
263      echo ${hostname%%.*} > /etc/hostname
264      sed -e 's/\(127\.0\.1\.1[         ]*\).*/\1'"$hostname ${hostname%%.*}/" < /etc/hosts > /etc/hosts.new
265      mv -f /etc/hosts.new /etc/hosts
266      if grep -q dhcp /etc/network/interfaces ; then
267        sed -e s/dhcp/static/ < /etc/network/interfaces > /etc/network/interfaces.new
268        echo "  address $ipaddr" >> /etc/network/interfaces.new
269        echo "  netmask $netmask" >> /etc/network/interfaces.new
270        echo "  gateway $gateway" >> /etc/network/interfaces.new
271        echo "  dns-nameservers 18.72.0.3 18.70.0.160 18.71.0.151" >> /etc/network/interfaces.new
272        mv -f /etc/network/interfaces.new /etc/network/interfaces
273      fi
274      hostname ${hostname%%.*}
275    fi
276
277  fi
278else
279  output "Press return to begin or control-C to abort"
280  read dummy
281fi
282
283apt-get update
284
285output "Verifying machine is up to date..."
286pattern='^0 upgraded, 0 newly installed, 0 to remove'
287if ! apt-get --simulate --assume-yes dist-upgrade | grep -q "$pattern"; then
288    if [ -n "$pxetype" ] ; then
289        output "Forcing an upgrade"
290        apt-get --assume-yes dist-upgrade
291    else
292        error "Your system is not up to date.  Proceeding with an install at"
293        error "this time could render your system unusable."
294        error "Please run 'apt-get dist-upgrade' as root or use the GUI update"
295        error "manager to ensure your system is up to date before continuing."
296        error "NOTE: You do NOT need to upgrade to a newer release of Ubuntu",
297        error "you merely need to ensure you have the latest software updates"
298        error "for the current version."
299        exit 1
300    fi
301fi
302
303if ! hash aptitude >/dev/null 2>&1; then
304  output "Installing Debathena installer dependency: aptitude"
305  apt-get -y install aptitude
306fi
307
308output "Installing Debathena installer dependencies: wget and dnsutils"
309aptitude -y install wget dnsutils
310if [ yes = "$resolvconfhack" ]; then
311  output "Installing resolvconf ahead of time"
312  aptitude -y install resolvconf
313fi
314
315# Only add our openafs component if DKMS isn't available
316openafs_component=""
317if aptitude show openafs-modules-dkms > /dev/null; then
318  modules="openafs-modules-dkms"
319else
320  openafs_component=" openafs"
321fi
322
323output "Adding the Debathena repository to the apt sources"
324output "(This may cause the update manager to claim new upgrades are available."
325output "Ignore them until this script is complete.)"
326sourceslist=/etc/apt/sources.list.d/debathena.list
327clustersourceslist=/etc/apt/sources.list.d/debathena.clusterinfo.list
328if [ -z "$hostname" ] ; then hostname=`hostname` ; fi
329
330if [ ! -e "$sourceslist" ] || ! grep -v ^# "$sourceslist" | grep -q debathena; then
331  if [ -e "$sourceslist" ]; then
332    echo "" >> $sourceslist
333  fi
334  echo "deb http://debathena.mit.edu/apt $distro debathena debathena-config debathena-system$openafs_component" >> $sourceslist
335  echo "deb-src http://debathena.mit.edu/apt $distro debathena debathena-config debathena-system$openafs_component" >> $sourceslist
336fi
337
338# Note that hesiod may contain multiple apt_release tokens.  We want to
339# include known repositories but make no assumptions about wanting
340# others.  (For instances, "development" does @i{not} automatically
341# infer "proposed".)
342hescluster=$(dig +short +bufsize=2048 ${hostname}.cluster.ns.athena.mit.edu TXT) || hescluster=""
343
344aptexplained=false
345for hc in proposed development bleeding; do
346  if echo "$hescluster" | grep -Fxq "\"apt_release $hc\""; then
347    echo "Adding $distro-$hc apt repository."
348    if [ "${aptexplained}" = false ] ; then
349      echo "" >> $clustersourceslist
350      echo "# This file is automatically updated by debathena-auto-update" >> $clustersourceslist
351      echo "# based on your Hesiod cluster information. If you want to" >> $clustersourceslist
352      echo "# make changes, do so in another file." >> $clustersourceslist
353      aptexplained=true
354    fi
355    echo "" >> $clustersourceslist
356    echo "deb http://debathena.mit.edu/apt $distro-${hc} debathena debathena-config debathena-system$openafs_component" >> $clustersourceslist
357    echo "deb-src http://debathena.mit.edu/apt $distro-${hc} debathena debathena-config debathena-system$openafs_component" >> $clustersourceslist
358  fi
359done
360
361if [ "$ubuntu" = "yes" ]; then
362  output "Making sure the universe repository is enabled"
363  sed -i 's,^# \(deb\(\-src\)* http://archive.ubuntu.com/ubuntu [[:alnum:]]* universe\)$,\1,' /etc/apt/sources.list
364fi
365
366output "Downloading the Debathena archive signing key"
367if ! wget -N http://debathena.mit.edu/apt/debathena-archive-keyring.asc ; then
368  error "Download failed; terminating."
369  exit 1
370fi
371echo "fa787714d1ea439c28458aab64962f755e2bdee7a3520919a72b641458757fa3586fd269cc1dae8d99047e00b3df88db0826f0c99a1f5a8771618b3c0be8e3bd  ./debathena-archive-keyring.asc" | \
372  sha512sum -c
373apt-key add debathena-archive-keyring.asc
374rm ./debathena-archive-keyring.asc
375
376apt-get update
377
378if [ -z "$modules" ]; then
379  modules_want=$(dpkg-query -W -f '${Source}\t${Package}\n' 'linux-image-*' | \
380   sed -nre 's/^linux-(meta|latest[^\t]*)\tlinux-image-(.*)$/openafs-modules-\2/p')
381  modules=
382  for m in $modules_want; do
383    aptitude show $m > /dev/null && modules="$modules $m"
384  done
385fi
386
387if [ -z "$modules" ]; then
388  error "An OpenAFS modules metapackage for your kernel is not available."
389  error "Please use the manual installation instructions at"
390  error "http://debathena.mit.edu/install"
391  error "You will need to compile your own AFS modules as described at:"
392  error "http://debathena.mit.edu/troubleshooting#openafs-custom"
393  exit 1
394fi
395
396output "Installing OpenAFS kernel metapackage"
397apt-get -y install $modules
398
399if [ "cluster" = "$category" ] || [ "workstation" = "$category" ] ; then
400    output "Installing debathena-license-config"
401    apt-get -y install debathena-license-config
402fi
403
404# Use the noninteractive frontend to install the main package.  This
405# is so that AFS and Zephyr don't ask questions of the user which
406# debathena packages will later stomp on anyway.
407output "Installing main Debathena metapackage $mainpackage"
408
409aptitude -y install "$mainpackage"
410
411# Use the default front end and allow questions to be asked; otherwise
412# Java will fail to install since it has to present its license.
413if [ yes = "$csoft" ]; then
414  output "Installing debathena-extra-software"
415  DEBIAN_PRIORITY=critical aptitude -y install debathena-extra-software
416fi
417if [ yes = "$tsoft" ]; then
418  output "Installing debathena-thirdparty"
419  DEBIAN_PRIORITY=critical aptitude -y install debathena-thirdparty
420fi
421
422# Post-install cleanup for cluster systems.
423rm installing.txt
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.