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.1_rsync
/
lcslis_dom0_update-4.1
< prev
next >
Wrap
Text File
|
2009-09-13
|
5KB
|
157 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
#
# 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)
#
#
# Various variables
#
LOCKFILE="/var/lock/lcslis_dom0_update-4.1"
LOGTAG="lcslis_dom0_update-4.1[$$]"
SCRIPT_STATUS_MSG="Script 'lcslis_dom0_update' version 4.1"
REBOOT_MANDATORY=0
# This is the maximum number of seconds you think
# a monitor must leave before suspecting it to be
# freezed.
[ "$SLIM_MAX_AGE" = "" ] && SLIM_MAX_AGE=36000
# This is the max number of time the script will try
# to relock when already locked
[ "$SLIM_RETRY_TIME" = "" ] && SLIM_RETRY_TIME=360
write_to_log()
{
logger -t "$LOGTAG" $*
}
send_to_slismaster()
{
echo "$*" | mail "$SLISMASTER" -s "`hostname` : Update: $LOGTAG"
}
exit_this_update()
{
write_to_log $*
send_to_slismaster $*
write_to_log "$SCRIPT_STATUS_MSG: failed."
exit 1
}
write_to_log `echo "[$PATH]"`
#
# Locking
#
LOCK_OUTPUT=`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
write_to_log "Error: Lock found: update already running!"
exit 1
fi
#
# If a very old lock file is found
#
if [ "`echo $LOCK_OUTPUT | grep -i "forcing lock"`" != "" ]; then
write_to_log "Warning: forcing lock and killing possibly sleeping processes."
# Perhaps some processes are freezed?
killall apt-get 2>/dev/null
sleep 1
killall dpkg-preconfigure 2>/dev/null
sleep 1
[ "`dpkg -C`" != "" ] && exit_this_update "Warning: Some packages not installed correctly";
# Then if the lock is older than 10 days, remove the lockfile and lock again.
LOCKFILE_OLD=`find $LOCKFILE -nowarn -ctime +10 -print`
if [ "$LOCKFILE_OLD" != "" ]; then
write_to_log "Info: Very old lock found (more than 10 days), removing it."
rm -f $LOCKFILE
fi
# Try to lock another time while waiting for the previous one to finish
lockfile -5 -r $SLIM_RETRY_TIME $LOCKFILE ; LOCK_RC=$?
if [ "$LOCK_RC" != "0" ]; then
MSG="Error: second try for locking failed"
exit_this_update $MSG
fi
fi
write_to_log "$SCRIPT_STATUS_MSG: starting..."
write_to_log "=== PLEASE WAIT. DO NOT USE SLIS WHILE UPDATING ==="
#
# Make updates
#
logger -t "$LOGTAG" "APT: Updating package index files from the dpkg sources..."
APT_RESULT=`apt-get -qq update 2>&1`
if [ $? != 0 ]; then
write_to_log "ERROR: apt-get update failed. See report below:"
write_to_log "`echo -n "$APT_RESULT"`"
else
#
# APT upgrade
#
# Ensure that no questions will be asked for
export DEBIAN_FRONTEND=noninteractive
DPKG_OPTS='-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold'
#
# APT dist-upgrade. Install also kernel-image updates, but if any wait nighttime to reboot.
#
# Get the list of dist-upgrade candidates
APT_RESULT=`apt-get -dsy dist-upgrade 2>&1`
CANDIDATES=`echo -n "$APT_RESULT" | grep Inst | awk '{print $2}' | tr '\n' ' '`
write_to_log "candidates : $CANDIDATES"
if [ "$CANDIDATES" == "" ] ; then
write_to_log "APT: Upgrading packages: none (system is up-to-date)."
else
write_to_log "APT: Upgrading packages: $CANDIDATES"
write_to_log "APT: Be patient, this may take a long time!..."
apt-get $DPKG_OPTS --force-yes -y -qq dist-upgrade 2>&1 | logger -t "$LOGTAG"
write_to_log "APT: Packages upgrading terminated."
NEW_KERNEL=`echo \"$CANDIDATES\" | grep linux-image `
if [ "$NEW_KERNEL" != "" ]; then
# A kernel update has been installed - Reboot now if it's nighttime or
# do it later.
write_to_log "APT : new kernel install . Reboot will be planned"
REBOOT_MANDATORY=1
else
write_to_log "APT : no new kernel."
fi
fi
fi
#
# Ending script
#
if [ "$REBOOT_MANDATORY" = "1" ]; then
echo 'shutdown -r +1'| at 4am tomorrow
write_to_log "$SCRIPT_STATUS_MSG: successed. Reboot planned tomorrow at 4am."
else
write_to_log "$SCRIPT_STATUS_MSG: successed"
fi
rm -f $LOCKFILE