[BACK]Return to networkupdate.sh CVS log [TXT][DIR] Up to [local] / mss / netupdate

File: [local] / mss / netupdate / networkupdate.sh (download)

Revision 1.15, Fri Jul 19 13:40:18 2013 UTC (9 years ago) by kirby
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +1 -1 lines

correct Id

#!/usr/local/bin/bash
# $Id: networkupdate.sh,v 1.15 2013/07/19 13:40:18 kirby Exp $

# Use config file instead of editing script itself
source /var/lib/mss/netupdate.conf

# Add version file if it's missing (useful on clean systems)
if [ ! -e /var/lib/mss/version ]; then
	echo "0.0" > /var/lib/mss/version
fi

# Set some variables
LOCK=/var/run/mssupdate.lock
LOCALVERSION=`cat /var/lib/mss/version`
DATE=`date '+%F %H:%M'`

# Get apropriate programm version and full path to it from fileserver
VERSION=`ssh $USER@$SERVER grep $MYNAME $HOSTLIST |awk '{print $2}'`
UPDATEDIR=`ssh $USER@$SERVER grep $MYNAME $HOSTLIST |awk '{print $3}'`

# Check whether we have latest version
if [ -n "$VERSION" ] && [ -n "$UPDATEDIR" ] && [ "$(echo "$LOCALVERSION < $VERSION" |bc -l )" -eq 1 ] && [ ! -e $LOCK ]; then
	echo "Starting update..."
	ssh $USER@$SERVER "echo "$DATE INFO: $MYNAME started update from $UPDATEDIR $LOCALVERSION '-\>' $VERSION" >> $UPDATEDIR/update.log"
	touch $LOCK
	rsync -Havx --ignore-existing --exclude-from=/var/lib/mss/rsync-exclude $USER@$SERVER:$UPDATEDIR/music /var/lib/mss/
	rsync -Hacvx --exclude-from=/var/lib/mss/rsync-exclude $USER@$SERVER:$UPDATEDIR/$VERSION/ /var/lib/mss
   if [ $? -eq 0 ]; then
	echo "Updated from $LOCALVERSION to $VERSION"
	echo $VERSION > /var/lib/mss/version
	ssh $USER@$SERVER "echo "$DATE SUCCESS: $MYNAME was updated from $UPDATEDIR $LOCALVERSION '-\>' $VERSION" >> $UPDATEDIR/update.log"
	rm -f $LOCK
   else
	echo "Update failed"
	ssh $USER@$SERVER "echo "$DATE ERROR: $MYNAME update from $UPDATEDIR $LOCALVERSION '-\>' $VERSION failed" >> $UPDATEDIR/update.log"
   fi
elif [ -n "$VERSION" ] && [ -n "$UPDATEDIR" ] && [ "$(echo "$LOCALVERSION < $VERSION" |bc -l )" -eq 1 ] && [ -e $LOCK ]; then
	echo "Update is running..."
	ssh $USER@$SERVER "echo "$DATE WARNING: $MYNAME is still running update from $LOCALVERSION to $VERSION" >> $UPDATEDIR/update.log"
elif [ -z "$VERSION" ] && [ -z "$UPDATEDIR" ]; then
	echo "Can't find myself in $HOSTLIST"
else
	echo "Version $LOCALVERSION is already installed"
fi





# Debug
echo $USER $SERVER $MYNAME $UPDATEDIR $VERSION $LOCALVERSION $HOSTLIST