home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ac-grenoble.fr
/
2015.02.ftp.ac-grenoble.fr.tar
/
ftp.ac-grenoble.fr
/
pub
/
slis
/
updates_4.0_rsync
/
lcslis_dom0_update-4.0
< prev
next >
Wrap
Text File
|
2007-06-20
|
6KB
|
182 lines
#!/bin/bash
# This script is part of the SLIS Project initiated by the CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
# Ce script fait partie du projet SLIS dΘmarrΘ par le CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
#
# SLIS : Serveur de communications Linux pour l'Internet Scolaire.
# Copyright (C) 1998-2003 Bruno Bzeznik
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program (For example ./COPYING);
# if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.
#
# Please send all comments and bug reports by electronic mail to:
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# or to <slis@ac-grenoble.fr>
#
# Envoyez vos suggestions et reports de bugs par e-mail α
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# ou α <slis@ac-grenoble.fr>
#
# Contact: Olivier.LeCam@crdp.ac-versailles.fr
#
# Comments:
# This script is run by the crontab once a night for upgrading the SLIS
# The SLIS admin can also run it at any moment it through the interface
# NB: The kernel upgrade can be done overnight only (bettween 0-6)
#
# Updates:
# olecam: Dec 13, 2005: script adapted to SLIS v4
# olecam: Jan 5, 2006: messages resulting of a failed apt-get are now logged to help debugging
# olecam: Jan 6, 2006: check against freezed updates (lock)
# olecam: Jan 6, 2005: get debconf less curious
#
# Various variables
#
LOCKFILE="/var/lock/lcslis_dom0_update-4.0"
LOGTAG="lcslis_dom0_update-4.0[$$]"
SCRIPT_STATUS_MSG="Script 'lcslis_dom0_update' version 4.0"
REBOOT_MANDOTORY=0
if [ "$SLIM_MAX_AGE" = "" ]
then
# This is the maximum number of seconds you think
# a monitor must leave before suspecting it to be
# freezed.
SLIM_MAX_AGE=36000
fi
if [ "$SLIM_RETRY_TIME" = "" ]
then
# This is the max number of time the script will try
# to relock when already locked
SLIM_RETRY_TIME=360
fi
/bin/echo "[$PATH]" |/usr/bin/logger -t "$LOGTAG"
#
# Locking
#
LOCK_OUTPUT=`/usr/bin/lockfile -1 -r 3 -l $SLIM_MAX_AGE -s 0 $LOCKFILE 2>&1`; LOCK_RC=$?
#
# If unable to lock (recent lock file found)
#
if [ "$LOCK_RC" != "0" ]
then
MSG="Error: Lock found: update already running!"
/usr/bin/logger -t "$LOGTAG" "$MSG"
/bin/echo "$MSG"
/usr/bin/logger -t "$LOGTAG" "$SCRIPT_STATUS_MSG: failed."
exit 1
fi
#
# If a very old lock file is found
#
if [ "`/bin/echo $LOCK_OUTPUT |/bin/grep -i "forcing lock"`" != "" ]
then
/usr/bin/logger -t "$LOGTAG" "Warning: forcing lock and killing possibly sleeping processes."
# Perhaps some processes are freezed?
/usr/bin/killall apt-get 2>/dev/null
/bin/sleep 1
/usr/bin/killall dpkg-preconfigure 2>/dev/null
/bin/sleep 1
# Try to lock another time while waiting for the previous one to finish
/usr/bin/lockfile -5 -r $SLIM_RETRY_TIME $LOCKFILE ; LOCK_RC=$?
if [ "$LOCK_RC" != "0" ]
then
MSG="Error: second try for locking failed"
/usr/bin/logger -t "$LOGTAG" "$MSG!"
/bin/echo "$LOGTAG" |/usr/bin/mail "$SLISMASTER" -s "Update: $MSG: $HOSTNAME"
/bin/echo "$MSG"
/usr/bin/logger -t "$LOGTAG" "$SCRIPT_STATUS_MSG: failed."
exit 1
fi
fi
/usr/bin/logger -t "$LOGTAG" "$SCRIPT_STATUS_MSG: starting..."
/usr/bin/logger -t "$LOGTAG" "=== PLEASE WAIT. DO NOT USE SLIS WHILE UPDATING ==="
#
# Make updates
#
/usr/bin/logger -t "$LOGTAG" "APT: Updating package index files from the dpkg sources..."
APT_RESULT=`/usr/bin/apt-get -qq update 2>&1`
if [ $? != 0 ]
then
/usr/bin/logger -t "$LOGTAG" "ERROR: apt-get update failed. See report below:"
/bin/echo -n "$APT_RESULT" |/usr/bin/logger -t "$LOGTAG"
else
#
# APT upgrade
#
# Ensure that we only are asked "critical" questions
export DEBIAN_PRIORITY=critical
export DEBIAN_FRONTEND=teletype
# To be even more nasty, use:
# DEBIAN_FRONTEND=noninteractive
# which should ask *no* question (at least not through debconf)
#
# APT dist-upgrade. Install also kernel-image updates, but if any wait nighttime to reboot.
#
# Get the list of dist-upgrade candidates
APT_RESULT=`/usr/bin/apt-get -dsy dist-upgrade 2>&1`
CANDIDATES=`/bin/echo -n "$APT_RESULT" |/bin/grep Inst |/usr/bin/awk '{print $2}' |/usr/bin/tr '\n' ' '`
if [ "$CANDIDATES" == "" ] ; then
/usr/bin/logger -t "$LOGTAG" "APT: Upgrading packages: none (system is up-to-date)."
else
/usr/bin/logger -t "$LOGTAG" "APT: Upgrading packages: $CANDIDATES"
/usr/bin/logger -t "$LOGTAG" "APT: Be patient, this may take a long time!..."
/usr/bin/apt-get --force-yes -y -qq dist-upgrade 2>&1 |/usr/bin/logger -t "$LOGTAG"
/usr/bin/logger -t "$LOGTAG" "APT: Packages upgrading terminated."
if [ "$(/bin/echo \"$CANDIDATES\" |/bin/grep \"kernel-image\")" != "" ]
then
# A kernel update has been installed - Reboot now if it's nighttime or
# do it later.
HOUR=`/bin/date +%k`
if [ $HOUR -lt 6 ]
then
/usr/bin/logger -t "$LOGTAG" "Kernel updated: a reboot is mandotory after the SLIS update..."
REBOOT_MANDOTORY=1
else
/usr/bin/logger -t "$LOGTAG" "Kernel updated: the SLIS will reboot tonight..."
/sbin/shutdown -r now |at 0100
fi
fi
fi
fi
#
# Ending script
#
if [ "$REBOOT_MANDATORY" = "1" ]
then
/sbin/shutdown -r +1
/usr/bin/logger -t "$LOGTAG" "$SCRIPT_STATUS_MSG: successed. Reboot planned in one minute."
else
/usr/bin/logger -t "$LOGTAG" "$SCRIPT_STATUS_MSG: successed"
fi
/bin/rm -f $LOCKFILE