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)
RevLine 
[23093]1#!/bin/sh
[23946]2# Athena installer script.
[23476]3# Maintainer: debathena@mit.edu
[23492]4# Based on original Debathena installer script by: Tim Abbott <tabbott@mit.edu>
[23093]5
[23492]6# Download this to a Debian or Ubuntu machine and run it as root.  It can
[23093]7# be downloaded with:
[23831]8#   wget -N http://debathena.mit.edu/install-debathena.sh
[23093]9
10set -e
11
[25608]12# The user's umask will sometimes carry over; don't let that happen.
13umask 022
14
[23946]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
[25437]19export DEBIAN_FRONTEND=noninteractive
[23946]20
[23093]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
[24912]34    [ Y = "$answer" ] && answer=y
35    [ N = "$answer" ] && answer=n
[23093]36    [ -z "$answer" ] && answer=$2
37  done
38  output ""
39}
40
41if [ `id -u` != "0" ]; then
[23492]42  error "You must run the Debathena installer as root."
[24010]43  if [ -x /usr/bin/sudo ]; then
[24009]44    error "Try running 'sudo $0'."
45  fi
[23492]46  exit 1
[23093]47fi
48
[25492]49pxetype=
50if test -f /root/pxe-install-flag ; then
51  pxetype=`head -1 /root/pxe-install-flag`
52fi
53
[25346]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
[25464]71  squeeze)
[25346]72    ;;
[25485]73  hardy|lucid|natty|oneiric)
[25346]74    ubuntu=yes
75    ;;
[25485]76  precise)
77    ubuntu=yes
[25492]78    output "The release you are running ($distro) is not fully supported"
[25485]79    output "and installing Debathena on it is probably a bad idea."
[25492]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
[25485]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    ;;
[25346]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
[25371]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
[23492]112echo "Welcome to the Debathena installer."
[23093]113echo ""
[23604]114echo "Please choose the category which best suits your needs.  Each category"
[23093]115echo "in this list includes the functionality of the previous ones.  See the"
[23957]116echo "documentation at http://debathena.mit.edu for more information."
[23093]117echo ""
[23967]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."
[23678]122echo "  login-graphical: Athena graphical login customizations"
[23967]123echo "                   Recommended for private multi-user desktops."
124echo "  workstation:     Graphical workstation with automatic updates"
[23969]125echo "                   Recommended for auto-managed cluster-like systems."
[23093]126echo ""
127
[25371]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
[23476]136category=""
[25492]137if [ cluster = "$pxetype" ] ; then
138  category=cluster ;
139  echo "PXE cluster install detected, so installing \"cluster\"."
[23476]140fi
[23135]141while [ standard != "$category" -a login != "$category" -a \
[23797]142        login-graphical != "$category" -a workstation != "$category" -a \
143        cluster != "$category" ]; do
[23093]144  output -n "Please choose a category or press control-C to abort: "
145  read category
146done
147mainpackage=debathena-$category
148
[23187]149csoft=no
[23460]150tsoft=no
[24786]151resolvconfhack=no
[23247]152echo "The extra-software package installs a standard set of software"
[23093]153echo "determined to be of interest to MIT users, such as LaTeX.  It is pretty"
[23247]154echo "big (several gigabytes, possibly more)."
[23093]155echo ""
[24937]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"
[23872]159echo ""
[24358]160if [ cluster = $category -o workstation = $category ] ; then
[24786]161  # See Trac #648 and LP:471975
162  resolvconfhack=yes
[24358]163  echo "The extra-software package is required for '$category' and will be installed."
[23187]164  csoft=yes
[23469]165  # Not setting tsoft=yes here; -cluster will pull it in anyway.
[23460]166else
167  ask "Do you want the extra-software package [y/N]? " n
168  if [ y = "$answer" ]; then
169    csoft=yes
[23492]170  fi
[23093]171fi
[23876]172if [ yes = "$csoft" ]; then
[23872]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
[23093]177
[25333]178if [ "$(cat /sys/class/dmi/id/product_name)" = "OptiPlex 790" ]; then
179    noacpi=y
180    if [ "$category" != "cluster" ]; then
[25337]181        echo
[25333]182        echo "The Dell 790 sometimes has problems rebooting.  The best way to"
[25345]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."
[25333]185        ask "Is it ok to do this now? [Y/n] " y
186        if [ y != "$answer" ]; then
187            noacpi=n
188        fi
189    fi
[25339]190    if [ "$noacpi" = "y" ] && ! grep -q "Added by install-debathena.sh to address reboot issues on the Dell 790" /etc/default/grub; then
[25337]191        cat >> /etc/default/grub << 'EOF'
192
193# Added by install-debathena.sh to address reboot issues on the Dell 790
[25340]194GRUB_CMDLINE_LINUX="reboot=pci $GRUB_CMDLINE_LINUX"
[25337]195EOF
196        update-grub
[25333]197    fi
198fi
199
[23093]200echo "A summary of your choices:"
[23187]201echo "  Category: $category"
[23247]202echo "  Extra-software package: $csoft"
[23460]203echo "  Third-party software package: $tsoft"
[23093]204echo ""
[25150]205if [ "$pxetype" = "cluster" ] ; then
206  if wget -q http://athena10.mit.edu/installer/installing.txt; then
207     cat installing.txt > /dev/tty6
[25245]208     date > /dev/tty6
[25150]209     chvt 6
210  fi
[24903]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
[23460]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
[23476]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.
[23093]239
[23479]240    # Configure network based on the preseed file settings, if present.
[25569]241    if test -f /root/debathena.preseed && ! grep -q netcfg/get_ipaddress /proc/cmdline; then
[23479]242      # Switch to canonical hostname.
243      ohostname=`cat /etc/hostname`
244      # Hack to avoid installing debconf-get for just this.
[23875]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/.* //'`
[23479]248
249      hostname=`host $ipaddr | \
[23476]250          sed 's#^.*domain name pointer \(.*\)$#\1#' | sed 's;\.*$;;' | \
251          tr '[A-Z]' '[a-z]'`
[23479]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
[23923]270        echo "  dns-nameservers 18.72.0.3 18.70.0.160 18.71.0.151" >> /etc/network/interfaces.new
[23479]271        mv -f /etc/network/interfaces.new /etc/network/interfaces
272      fi
273      hostname ${hostname%%.*}
[23476]274    fi
[23479]275
[23460]276  fi
277else
278  output "Press return to begin or control-C to abort"
279  read dummy
280fi
281
[24925]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
[24958]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."
[25160]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."
[24958]298        exit 1
299    fi
[24925]300fi
301
[24891]302if ! hash aptitude >/dev/null 2>&1; then
303  output "Installing Debathena installer dependency: aptitude"
304  apt-get -y install aptitude
305fi
306
[25346]307output "Installing Debathena installer dependencies: wget and dnsutils"
308aptitude -y install wget dnsutils
[24786]309if [ yes = "$resolvconfhack" ]; then
310  output "Installing resolvconf ahead of time"
311  aptitude -y install resolvconf
312fi
[23093]313
[25510]314# Only add our openafs component if DKMS isn't available
315openafs_component=""
[25106]316if aptitude show openafs-modules-dkms > /dev/null; then
[25510]317  modules="openafs-modules-dkms"
318else
[25106]319  openafs_component=" openafs"
320fi
321
[23492]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.)"
[24472]325sourceslist=/etc/apt/sources.list.d/debathena.list
[24791]326clustersourceslist=/etc/apt/sources.list.d/debathena.clusterinfo.list
327if [ -z "$hostname" ] ; then hostname=`hostname` ; fi
[25222]328
[25413]329if [ ! -e "$sourceslist" ] || ! grep -v ^# "$sourceslist" | grep -q debathena; then
[23093]330  if [ -e "$sourceslist" ]; then
331    echo "" >> $sourceslist
332  fi
[25106]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
[23093]335fi
336
[25235]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".)
[25238]341hescluster=$(dig +short +bufsize=2048 ${hostname}.cluster.ns.athena.mit.edu TXT) || hescluster=""
[24791]342
[25235]343aptexplained=false
344for hc in proposed development bleeding; do
[25238]345  if echo "$hescluster" | grep -Fxq "\"apt_release $hc\""; then
[25235]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
[24765]359
[23093]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
[23492]365output "Downloading the Debathena archive signing key"
[23831]366if ! wget -N http://debathena.mit.edu/apt/debathena-archive-keyring.asc ; then
[23492]367  error "Download failed; terminating."
[23093]368  exit 1
369fi
[24334]370echo "fa787714d1ea439c28458aab64962f755e2bdee7a3520919a72b641458757fa3586fd269cc1dae8d99047e00b3df88db0826f0c99a1f5a8771618b3c0be8e3bd  ./debathena-archive-keyring.asc" | \
371  sha512sum -c
[23500]372apt-key add debathena-archive-keyring.asc
373rm ./debathena-archive-keyring.asc
[23093]374
375apt-get update
376
[25106]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
[23093]385
386if [ -z "$modules" ]; then
387  error "An OpenAFS modules metapackage for your kernel is not available."
[23492]388  error "Please use the manual installation instructions at"
[23957]389  error "http://debathena.mit.edu/install"
[23492]390  error "You will need to compile your own AFS modules as described at:"
[23957]391  error "http://debathena.mit.edu/troubleshooting#openafs-custom"
[23492]392  exit 1
[23093]393fi
394
395output "Installing OpenAFS kernel metapackage"
396apt-get -y install $modules
397
[25336]398if [ "cluster" = "$category" ] || [ "workstation" = "$category" ] ; then
399    output "Installing debathena-license-config"
400    apt-get -y install debathena-license-config
401fi
402
[23187]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.
[23492]406output "Installing main Debathena metapackage $mainpackage"
[23460]407
[25437]408aptitude -y install "$mainpackage"
[23187]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
[23247]413  output "Installing debathena-extra-software"
414  DEBIAN_PRIORITY=critical aptitude -y install debathena-extra-software
[23187]415fi
[23460]416if [ yes = "$tsoft" ]; then
417  output "Installing debathena-thirdparty"
418  DEBIAN_PRIORITY=critical aptitude -y install debathena-thirdparty
419fi
[23910]420
421# Post-install cleanup for cluster systems.
[24903]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
[23910]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.