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

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