source: trunk/debathena/config/auto-update/debian/athena-auto-update @ 24337

Revision 24337, 5.2 KB checked in by jdreed, 14 years ago (diff)
Run dpkg --configure -a each time (trac (#407)
Line 
1#!/bin/sh
2
3complain() {
4  logger -t "$(hostname --fqdn)" -p user.notice "update: $*"
5}
6
7maybe_reboot() {
8  if [ -f /var/run/reboot-required ]; then
9    # A package wants us to reboot the machine.  Do so if no one is
10    # logged in.  Be paranoid about stale utmp entries.
11    ttys=$(w -h -s | awk '{print $2}')
12    for tty in $ttys; do
13      pids=$(ps --no-heading -j -t "$tty" 2>/dev/null \
14             | awk '($1 == $3) {print $1}')
15      if [ -n "$pids" ]; then
16        return
17      fi
18    done
19    # screen processes count as logins.
20    if pgrep '^screen' > /dev/null; then
21      return
22    fi
23    reboot
24    exit
25  fi
26}
27
28if [ 0 != "$(id -u)" ]; then
29  echo "This script must be run as root." >&2
30  exit 1
31fi
32
33# Don't run updates during a cluster login.
34if [ -e /var/run/athena-login ]; then
35  exit 0
36fi
37
38# Avoid confusing the system by running two updates at once.
39pidfile=/var/run/athena-update.pid
40if [ -e $pidfile ]; then
41  if ! kill -0 "$(cat $pidfile)" 2>/dev/null; then
42    rm -f $pidfile
43  fi
44fi
45(set -o noclobber; echo $$ > $pidfile) 2>/dev/null || exit
46
47trap 'rm -f $pidfile' EXIT
48
49# Make sure nothing expects input on stdin.
50exec </dev/null
51
52# Redirect further output to a log file.
53exec >>/var/log/athena-update 2>&1
54
55# Write a log header now and a footer at exit.
56# Also write a target for cluster's /etc/nologin symlink.
57echo "-----"
58echo "** Beginning Athena auto-update at $(date)"
59
60cat > /var/run/athena-nologin << NOLOGIN
61This system is currently taking software updates.
62Please log in to a different system.
63NOLOGIN
64
65finish() {
66    echo "** Ending Athena auto-update at $(date)"
67    echo "-----"
68    echo
69    rm -f $pidfile
70    rm -f /var/run/athena-nologin
71    exit
72}
73trap finish EXIT
74
75v() {
76  echo "** Running:" "$@"
77  "$@"
78}
79
80
81# Allow hesiod cluster info to specify the debathena apt release.
82# (Will do nothing if debathena-clusterinfo isn't installed.)
83[ -x /usr/sbin/save-cluster-info ] && v /usr/sbin/save-cluster-info
84cinfo=/var/run/athena-clusterinfo.sh
85slist=/etc/apt/sources.list.d/debathena.clusterinfo.list
86if [ -r "$cinfo" ] && ( [ ! -e "$slist" ] || [ -w "$slist" ] ); then
87  echo "** Updating debathena.clusterinfo.list"
88  [ -e "$slist" ] && rm "$slist"
89  dsource="$(egrep -h '^deb(-src)? http://debathena\.mit\.edu/apt ' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null | sort -u)"
90  if [ -n "$dsource" ]; then
91    (. $cinfo
92     echo "# This file is automatically updated by debathena-auto-update"
93     echo "# based on your Hesiod cluster information. If you want to"
94     echo "# make changes, do so in another file."
95     echo
96     case $APT_RELEASE in
97       production)  ;;
98       proposed)    echo "$dsource" | awk '$3 !~ /-/ {$3 = $3 "-proposed"; print}' ;;
99       development) echo "$dsource" | awk '$3 != /-/ {$3 = $3 "-proposed"; print}'
100                    echo "$dsource" | awk '$3 != /-/ {$3 = $3 "-development"; print}' ;;
101     esac
102    ) > $slist
103  else
104    echo "Never mind, I can't figure out which sources.list line is Debathena's"
105  fi
106else
107  echo "** Skipping update of debathena.clusterinfo.list"
108fi
109
110# Tell apt not to expect user input during package installation.
111export DEBIAN_FRONTEND=noninteractive
112
113# Configure any unconfigured packages (Trac #407)
114if ! v dpkg --configure -a; then
115  complain "Failed to configure unconfigured packages."
116  exit
117fi 
118
119# A recently configured package may want a reboot
120maybe_reboot
121
122# Update the aptitude cache.
123if ! v aptitude --quiet --assume-yes update; then
124  complain "aptitude update failed"
125  exit
126fi
127
128# Exit quietly (except for perhaps rebooting) if there are no upgrades
129# to take.
130pattern='^0 packages upgraded, 0 newly installed, 0 to remove'
131if v aptitude --simulate --assume-yes full-upgrade | grep -q "$pattern"; then
132  echo "Nothing to do!"
133  maybe_reboot
134  exit
135fi
136
137# Download packages first.
138if ! v aptitude --quiet --assume-yes --download-only full-upgrade; then
139  complain "download failed"
140  exit
141fi
142
143# If the debathena-reactivate package is installed, call into the
144# login snapshot script to create a root snapshot for the next update.
145if [ -x /usr/sbin/athena-login-snapshot ]; then
146  echo "** Creating root snapshot"
147  /usr/sbin/athena-login-snapshot update-start
148fi
149
150# Perform the update.  In some corner cases, aptitude might decide
151# that the best course of action is to remove the Debathena
152# metapackage, so be paranoid about that.
153v aptitude --quiet --assume-yes keep-all
154v aptitude --quiet --assume-yes --download-only dist-upgrade
155if result=$(aptitude -F "%p" search '~i!~VTARGET(^debathena-cluster$ | ^debathena-workstation$ | ^debathena-login$ | ^debathena-standard$ | ^openafs-modules-~D^linux-image-)')
156  [ -n "$result" ]; then
157  echo "** metapackages would be removed by the update, aborting:" $result
158  v aptitude --quiet --assume-yes keep-all
159  complain "metapackages would be removed by update:" $result
160elif result=$(aptitude -F "%p" search '~b')
161  [ -n "$result" ]; then
162  echo "** packages would be broken by the update, aborting:" $result
163  v aptitude --quiet --assume-yes keep-all
164  complain "packages would be broken by update:" $result
165else
166  v aptitude --quiet --assume-yes install
167fi
168
169# Finally, update the apt-file cache
170v apt-file update
171
172if [ -x /usr/sbin/athena-login-snapshot ]; then
173  echo "** Cleaning up root snapshot"
174  /usr/sbin/athena-login-snapshot update-end
175fi
176
177maybe_reboot
178exit
Note: See TracBrowser for help on using the repository browser.