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

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