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

Revision 24850, 3.5 KB checked in by jdreed, 14 years ago (diff)
In auto-update: * Use wget -N for completeness
Line 
1#!/bin/bash
2#
3# This is designed to be called from cron
4
5debug() {
6    [ $DEBUG -eq 1 ] && echo "DEBUG: $*"
7}
8
9complain() {
10    if [ $DEBUG -eq 1 ]; then
11        echo "ERROR: $*"
12    else
13        logger -t "athena-auto-upgrade" -p user.notice "$*"
14    fi
15}
16
17# Redirect output to a log file
18exec >>/var/log/athena-upgrade 2>&1
19echo "Starting upgrade at $(date)"
20
21DEBUG=0
22MAYBE=""
23if [ "$1" = "--debug" ]; then
24    DEBUG=1
25    MAYBE=echo
26fi
27
28UPGRADE_TO_TESTING=no
29UPGRADE_ANYWAY=no
30[ -f /etc/default/debathena-auto-update ] && . /etc/default/debathena-auto-update
31
32if [ $DEBUG -eq 1 ]; then
33    UPGRADE_TO_TESTING=yes
34    UPGRADE_ANYWAY=yes
35fi
36
37# Not supported on Debian
38if [ "$(lsb_release -si)" != "Ubuntu" ]; then
39    debug "Only supported on Ubuntu.".
40    exit 0
41fi
42
43# Skip other sanity checks in debug mode
44if [ $DEBUG -ne 1 ]; then
45    # Only run this on cluster
46    if [ "$(machtype -L)" != "debathena-cluster" ] && \
47       [ "$UPGRADE_ANYWAY" != "yes" ]; then
48        debug "Not a cluster machine and UPGRADE_ANYWAY != yes.".
49        exit 0
50    fi
51   
52    # Bail if someone is logged in (stolen from auto-update)
53    ttys=$(w -h -s | awk '{print $2}')
54    for tty in $ttys; do
55        pids=$(ps --no-heading -j -t "$tty" 2>/dev/null \
56            | awk '($1 == $3) {print $1}')
57        if [ -n "$pids" ]; then
58            debug "Users logged in, won't continue."
59            debug "PIDs: $pids"
60            exit 0
61        fi
62    done
63    # screen processes count as logins.
64    if pgrep '^screen' > /dev/null; then
65        debug "Screen processes found, won't continue."
66        exit 0
67    fi
68fi
69
70CLUSTERINFO=`getcluster -b $(lsb_release -sr)`
71[ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
72eval $CLUSTERINFO
73if [ ! -z "$NEW_PRODUCTION_RELEASE" ]; then
74    debug "Taking new production release: $NEW_PRODUCTION_RELEASE"
75    NEWCLUSTER=`getcluster -b $NEW_PRODUCTION_RELEASE`
76    [ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
77    eval $NEWCLUSTER
78elif [ ! -z "$NEW_TESTING_RELEASE" ] && \
79    [ "$UPGRADE_TO_TESTING" = "yes" ]; then
80    debug "Taking new testing release: $NEW_TESTING_RELEASE"
81    NEWCLUSTER=`getcluster -b $NEW_TESTING_RELEASE`
82    [ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
83    eval $NEWCLUSTER
84else
85    debug "No new releases."
86    exit 0
87fi
88if [ "$(lsb_release -sc)" = "$UBUNTU_RELEASE" ]; then
89    complain "Tried to upgrade to already running release; shouldn't happen"
90    exit 1
91fi
92debug "OK, trying to upgrade to $UBUNTU_RELEASE"
93
94# That's a space and then a tab inside the brackets
95if egrep -q '^flags[    ].* lm( |$)' /proc/cpuinfo; then
96    arch=amd64
97else
98    arch=i386
99fi
100debug "Arch: $arch"
101IPADDR=`ifconfig eth0 |perl -ne'/^\s+inet addr:([\d\.]+)/ && print $1'`
102if [ -z "$IPADDR" ]; then
103    complain "Couldn't get IP address from ifconfig!"
104    exit 0
105fi
106debug "Using IPADDR=$IPADDR"
107$MAYBE mkdir /h
108$MAYBE cd /h
109$MAYBE wget -N http://debathena.mit.edu/net-install/${UBUNTU_RELEASE}/${arch}/initrd.gz
110$MAYBE wget -N http://debathena.mit.edu/net-install/${UBUNTU_RELEASE}/${arch}/linux
111# This is just the guts of the hackboot script:
112dkargs="DEBCONF_DEBUG=5"
113kargs="netcfg/get_hostname= locale=en_US console-setup/layoutcode=us \
114       interface=auto \
115       url=http://18.9.60.73/installer/${UBUNTU_RELEASE}/debathena.preseed \
116       debathena/clusterforce=yes debathena/clusteraddr=$IPADDR --"
117debug "Would execute kexec with --append=\"$dkargs $kargs\""
118if [ $DEBUG -eq 1 ]; then
119    exit 0
120fi
121/sbin/kexec -l linux --append="$dkargs $kargs" --initrd=initrd.gz \
122    && sleep 3 && chvt 1 && sleep 2 && /sbin/kexec -e
123complain "Failed to kexec."
124exit 1
Note: See TracBrowser for help on using the repository browser.