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

Revision 25569, 15.6 KB checked in by jdreed, 12 years ago (diff)
Don't screw with networking/hostname if we passed the right stuff to the installer
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
[23946]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
[25437]16export DEBIAN_FRONTEND=noninteractive
[23946]17
[23093]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
[24912]31    [ Y = "$answer" ] && answer=y
32    [ N = "$answer" ] && answer=n
[23093]33    [ -z "$answer" ] && answer=$2
34  done
35  output ""
36}
37
38if [ `id -u` != "0" ]; then
[23492]39  error "You must run the Debathena installer as root."
[24010]40  if [ -x /usr/bin/sudo ]; then
[24009]41    error "Try running 'sudo $0'."
42  fi
[23492]43  exit 1
[23093]44fi
45
[25492]46pxetype=
47if test -f /root/pxe-install-flag ; then
48  pxetype=`head -1 /root/pxe-install-flag`
49fi
50
[25346]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
[25464]68  squeeze)
[25346]69    ;;
[25485]70  hardy|lucid|natty|oneiric)
[25346]71    ubuntu=yes
72    ;;
[25485]73  precise)
74    ubuntu=yes
[25492]75    output "The release you are running ($distro) is not fully supported"
[25485]76    output "and installing Debathena on it is probably a bad idea."
[25492]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
[25485]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    ;;
[25346]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
[25371]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
[23492]109echo "Welcome to the Debathena installer."
[23093]110echo ""
[23604]111echo "Please choose the category which best suits your needs.  Each category"
[23093]112echo "in this list includes the functionality of the previous ones.  See the"
[23957]113echo "documentation at http://debathena.mit.edu for more information."
[23093]114echo ""
[23967]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."
[23678]119echo "  login-graphical: Athena graphical login customizations"
[23967]120echo "                   Recommended for private multi-user desktops."
121echo "  workstation:     Graphical workstation with automatic updates"
[23969]122echo "                   Recommended for auto-managed cluster-like systems."
[23093]123echo ""
124
[25371]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
[23476]133category=""
[25492]134if [ cluster = "$pxetype" ] ; then
135  category=cluster ;
136  echo "PXE cluster install detected, so installing \"cluster\"."
[23476]137fi
[23135]138while [ standard != "$category" -a login != "$category" -a \
[23797]139        login-graphical != "$category" -a workstation != "$category" -a \
140        cluster != "$category" ]; do
[23093]141  output -n "Please choose a category or press control-C to abort: "
142  read category
143done
144mainpackage=debathena-$category
145
[23187]146csoft=no
[23460]147tsoft=no
[24786]148resolvconfhack=no
[23247]149echo "The extra-software package installs a standard set of software"
[23093]150echo "determined to be of interest to MIT users, such as LaTeX.  It is pretty"
[23247]151echo "big (several gigabytes, possibly more)."
[23093]152echo ""
[24937]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"
[23872]156echo ""
[24358]157if [ cluster = $category -o workstation = $category ] ; then
[24786]158  # See Trac #648 and LP:471975
159  resolvconfhack=yes
[24358]160  echo "The extra-software package is required for '$category' and will be installed."
[23187]161  csoft=yes
[23469]162  # Not setting tsoft=yes here; -cluster will pull it in anyway.
[23460]163else
164  ask "Do you want the extra-software package [y/N]? " n
165  if [ y = "$answer" ]; then
166    csoft=yes
[23492]167  fi
[23093]168fi
[23876]169if [ yes = "$csoft" ]; then
[23872]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
[23093]174
[25333]175if [ "$(cat /sys/class/dmi/id/product_name)" = "OptiPlex 790" ]; then
176    noacpi=y
177    if [ "$category" != "cluster" ]; then
[25337]178        echo
[25333]179        echo "The Dell 790 sometimes has problems rebooting.  The best way to"
[25345]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."
[25333]182        ask "Is it ok to do this now? [Y/n] " y
183        if [ y != "$answer" ]; then
184            noacpi=n
185        fi
186    fi
[25339]187    if [ "$noacpi" = "y" ] && ! grep -q "Added by install-debathena.sh to address reboot issues on the Dell 790" /etc/default/grub; then
[25337]188        cat >> /etc/default/grub << 'EOF'
189
190# Added by install-debathena.sh to address reboot issues on the Dell 790
[25340]191GRUB_CMDLINE_LINUX="reboot=pci $GRUB_CMDLINE_LINUX"
[25337]192EOF
193        update-grub
[25333]194    fi
195fi
196
[23093]197echo "A summary of your choices:"
[23187]198echo "  Category: $category"
[23247]199echo "  Extra-software package: $csoft"
[23460]200echo "  Third-party software package: $tsoft"
[23093]201echo ""
[25150]202if [ "$pxetype" = "cluster" ] ; then
203  if wget -q http://athena10.mit.edu/installer/installing.txt; then
204     cat installing.txt > /dev/tty6
[25245]205     date > /dev/tty6
[25150]206     chvt 6
207  fi
[24903]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
[23460]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
[23476]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.
[23093]236
[23479]237    # Configure network based on the preseed file settings, if present.
[25569]238    if test -f /root/debathena.preseed && ! grep -q netcfg/get_ipaddress /proc/cmdline; then
[23479]239      # Switch to canonical hostname.
240      ohostname=`cat /etc/hostname`
241      # Hack to avoid installing debconf-get for just this.
[23875]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/.* //'`
[23479]245
246      hostname=`host $ipaddr | \
[23476]247          sed 's#^.*domain name pointer \(.*\)$#\1#' | sed 's;\.*$;;' | \
248          tr '[A-Z]' '[a-z]'`
[23479]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
[23923]267        echo "  dns-nameservers 18.72.0.3 18.70.0.160 18.71.0.151" >> /etc/network/interfaces.new
[23479]268        mv -f /etc/network/interfaces.new /etc/network/interfaces
269      fi
270      hostname ${hostname%%.*}
[23476]271    fi
[23479]272
[23460]273  fi
274else
275  output "Press return to begin or control-C to abort"
276  read dummy
277fi
278
[24925]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
[24958]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."
[25160]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."
[24958]295        exit 1
296    fi
[24925]297fi
298
[24891]299if ! hash aptitude >/dev/null 2>&1; then
300  output "Installing Debathena installer dependency: aptitude"
301  apt-get -y install aptitude
302fi
303
[25346]304output "Installing Debathena installer dependencies: wget and dnsutils"
305aptitude -y install wget dnsutils
[24786]306if [ yes = "$resolvconfhack" ]; then
307  output "Installing resolvconf ahead of time"
308  aptitude -y install resolvconf
309fi
[23093]310
[25510]311# Only add our openafs component if DKMS isn't available
312openafs_component=""
[25106]313if aptitude show openafs-modules-dkms > /dev/null; then
[25510]314  modules="openafs-modules-dkms"
315else
[25106]316  openafs_component=" openafs"
317fi
318
[23492]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.)"
[24472]322sourceslist=/etc/apt/sources.list.d/debathena.list
[24791]323clustersourceslist=/etc/apt/sources.list.d/debathena.clusterinfo.list
324if [ -z "$hostname" ] ; then hostname=`hostname` ; fi
[25222]325
[25413]326if [ ! -e "$sourceslist" ] || ! grep -v ^# "$sourceslist" | grep -q debathena; then
[23093]327  if [ -e "$sourceslist" ]; then
328    echo "" >> $sourceslist
329  fi
[25106]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
[23093]332fi
333
[25235]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".)
[25238]338hescluster=$(dig +short +bufsize=2048 ${hostname}.cluster.ns.athena.mit.edu TXT) || hescluster=""
[24791]339
[25235]340aptexplained=false
341for hc in proposed development bleeding; do
[25238]342  if echo "$hescluster" | grep -Fxq "\"apt_release $hc\""; then
[25235]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
[24765]356
[23093]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
[23492]362output "Downloading the Debathena archive signing key"
[23831]363if ! wget -N http://debathena.mit.edu/apt/debathena-archive-keyring.asc ; then
[23492]364  error "Download failed; terminating."
[23093]365  exit 1
366fi
[24334]367echo "fa787714d1ea439c28458aab64962f755e2bdee7a3520919a72b641458757fa3586fd269cc1dae8d99047e00b3df88db0826f0c99a1f5a8771618b3c0be8e3bd  ./debathena-archive-keyring.asc" | \
368  sha512sum -c
[23500]369apt-key add debathena-archive-keyring.asc
370rm ./debathena-archive-keyring.asc
[23093]371
372apt-get update
373
[25106]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
[23093]382
383if [ -z "$modules" ]; then
384  error "An OpenAFS modules metapackage for your kernel is not available."
[23492]385  error "Please use the manual installation instructions at"
[23957]386  error "http://debathena.mit.edu/install"
[23492]387  error "You will need to compile your own AFS modules as described at:"
[23957]388  error "http://debathena.mit.edu/troubleshooting#openafs-custom"
[23492]389  exit 1
[23093]390fi
391
392output "Installing OpenAFS kernel metapackage"
393apt-get -y install $modules
394
[25336]395if [ "cluster" = "$category" ] || [ "workstation" = "$category" ] ; then
396    output "Installing debathena-license-config"
397    apt-get -y install debathena-license-config
398fi
399
[23187]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.
[23492]403output "Installing main Debathena metapackage $mainpackage"
[23460]404
[25437]405aptitude -y install "$mainpackage"
[23187]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
[23247]410  output "Installing debathena-extra-software"
411  DEBIAN_PRIORITY=critical aptitude -y install debathena-extra-software
[23187]412fi
[23460]413if [ yes = "$tsoft" ]; then
414  output "Installing debathena-thirdparty"
415  DEBIAN_PRIORITY=critical aptitude -y install debathena-thirdparty
416fi
[23910]417
418# Post-install cleanup for cluster systems.
[24903]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
[23910]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.