[24797] | 1 | #!/bin/bash |
---|
| 2 | # |
---|
| 3 | # This is designed to be called from cron |
---|
| 4 | |
---|
| 5 | debug() { |
---|
| 6 | [ $DEBUG -eq 1 ] && echo "DEBUG: $*" |
---|
| 7 | } |
---|
| 8 | |
---|
| 9 | complain() { |
---|
| 10 | if [ $DEBUG -eq 1 ]; then |
---|
| 11 | echo "ERROR: $*" |
---|
| 12 | else |
---|
| 13 | logger -t "athena-auto-upgrade" -p user.notice "$*" |
---|
| 14 | fi |
---|
| 15 | } |
---|
| 16 | |
---|
[24811] | 17 | # Redirect output to a log file |
---|
| 18 | exec >>/var/log/athena-upgrade 2>&1 |
---|
[24812] | 19 | echo "Starting upgrade at $(date)" |
---|
[24811] | 20 | |
---|
[24797] | 21 | DEBUG=0 |
---|
| 22 | MAYBE="" |
---|
| 23 | if [ "$1" = "--debug" ]; then |
---|
| 24 | DEBUG=1 |
---|
| 25 | MAYBE=echo |
---|
| 26 | fi |
---|
| 27 | |
---|
[24804] | 28 | UPGRADE_TO_TESTING=no |
---|
| 29 | UPGRADE_ANYWAY=no |
---|
| 30 | [ -f /etc/default/debathena-auto-update ] && . /etc/default/debathena-auto-update |
---|
[24797] | 31 | |
---|
| 32 | if [ $DEBUG -eq 1 ]; then |
---|
[24804] | 33 | UPGRADE_TO_TESTING=yes |
---|
| 34 | UPGRADE_ANYWAY=yes |
---|
[24797] | 35 | fi |
---|
| 36 | |
---|
| 37 | # Not supported on Debian |
---|
[24806] | 38 | if [ "$(lsb_release -si)" != "Ubuntu" ]; then |
---|
[24811] | 39 | debug "Only supported on Ubuntu.". |
---|
[24797] | 40 | exit 0 |
---|
| 41 | fi |
---|
| 42 | |
---|
| 43 | # Skip other sanity checks in debug mode |
---|
| 44 | if [ $DEBUG -ne 1 ]; then |
---|
| 45 | # Only run this on cluster |
---|
[24806] | 46 | if [ "$(machtype -L)" != "debathena-cluster" ] && \ |
---|
[24805] | 47 | [ "$UPGRADE_ANYWAY" != "yes" ]; then |
---|
[24811] | 48 | debug "Not a cluster machine and UPGRADE_ANYWAY != yes.". |
---|
[24797] | 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 |
---|
[24811] | 58 | debug "Users logged in, won't continue." |
---|
| 59 | debug "PIDs: $pids" |
---|
[24797] | 60 | exit 0 |
---|
| 61 | fi |
---|
| 62 | done |
---|
| 63 | # screen processes count as logins. |
---|
| 64 | if pgrep '^screen' > /dev/null; then |
---|
[24811] | 65 | debug "Screen processes found, won't continue." |
---|
[24797] | 66 | exit 0 |
---|
| 67 | fi |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | CLUSTERINFO=`getcluster -b $(lsb_release -sr)` |
---|
| 71 | [ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1 |
---|
| 72 | eval $CLUSTERINFO |
---|
| 73 | if [ ! -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 |
---|
[24812] | 78 | elif [ ! -z "$NEW_TESTING_RELEASE" ] && \ |
---|
| 79 | [ "$UPGRADE_TO_TESTING" = "yes" ]; then |
---|
[24797] | 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 |
---|
[24812] | 84 | else |
---|
[24797] | 85 | debug "No new releases." |
---|
| 86 | exit 0 |
---|
| 87 | fi |
---|
[24806] | 88 | if [ "$(lsb_release -sc)" = "$UBUNTU_RELEASE" ]; then |
---|
[24797] | 89 | complain "Tried to upgrade to already running release; shouldn't happen" |
---|
| 90 | exit 1 |
---|
| 91 | fi |
---|
| 92 | debug "OK, trying to upgrade to $UBUNTU_RELEASE" |
---|
| 93 | |
---|
| 94 | # That's a space and then a tab inside the brackets |
---|
| 95 | if egrep -q '^flags[ ].* lm( |$)' /proc/cpuinfo; then |
---|
| 96 | arch=amd64 |
---|
| 97 | else |
---|
| 98 | arch=i386 |
---|
| 99 | fi |
---|
| 100 | debug "Arch: $arch" |
---|
| 101 | IPADDR=`ifconfig eth0 |perl -ne'/^\s+inet addr:([\d\.]+)/ && print $1'` |
---|
| 102 | if [ -z "$IPADDR" ]; then |
---|
| 103 | complain "Couldn't get IP address from ifconfig!" |
---|
| 104 | exit 0 |
---|
| 105 | fi |
---|
| 106 | debug "Using IPADDR=$IPADDR" |
---|
| 107 | $MAYBE mkdir /h |
---|
| 108 | $MAYBE cd /h |
---|
[24850] | 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 |
---|
[24797] | 111 | # This is just the guts of the hackboot script: |
---|
| 112 | dkargs="DEBCONF_DEBUG=5" |
---|
| 113 | kargs="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 --" |
---|
| 117 | debug "Would execute kexec with --append=\"$dkargs $kargs\"" |
---|
| 118 | if [ $DEBUG -eq 1 ]; then |
---|
| 119 | exit 0 |
---|
| 120 | fi |
---|
[24807] | 121 | /sbin/kexec -l linux --append="$dkargs $kargs" --initrd=initrd.gz \ |
---|
[24808] | 122 | && sleep 3 && chvt 1 && sleep 2 && /sbin/kexec -e |
---|
[24797] | 123 | complain "Failed to kexec." |
---|
| 124 | exit 1 |
---|