bfc9ce7f7f4653635f4a499501793d9025592515
bn8 Import initial

bn8 authored 14 years ago

1) #!/bin/bash
2) 
Benjamin Renard Ajout d'un paramètre NAME p...

Benjamin Renard authored 13 years ago

3) #NAME="My Roundcube"
root Multi check en cas d'erreur...

root authored 13 years ago

4) RC_HOME=/var/www/webmail/public_html
bn8 Import initial

bn8 authored 14 years ago

5) MAIL=root
root Multi check en cas d'erreur...

root authored 13 years ago

6) SEND_EVERY_NB_DAY=7
root Ajout de l'inclusion d'un f...

root authored 13 years ago

7) CACHE=$RC_HOME/../.cache_check_upgrade
root Multi check en cas d'erreur...

root authored 13 years ago

8) CACHE_FAILED=$CACHE.failed
9) MAX_CHECK=10
10) MAX_FAILED=3
11) SLEEP_ON_FAILED=10
12) CHECK_URL=http://www.roundcube.net/download
bn8 Import initial

bn8 authored 14 years ago

13) 
14) DEBUG=0
15) [ "$1" == "-v" ] && DEBUG=1
16) 
root Ajout de l'inclusion d'un f...

root authored 13 years ago

17) [ -f "$0.local" ] && source "$0.local" && [ $DEBUG -eq 1 ] && echo "Import local config file : $0.local"
18) 
root Multi check en cas d'erreur...

root authored 13 years ago

19) current=`egrep "define.*RCMAIL_VERSION" $RC_HOME/program/include/iniset.php|sed "s/define('.*', '\([^']*\)'.*$/\1/"`
root Added regex to remove -rc s...

root authored 13 years ago

20) current="`echo $current|sed 's/-rc$//'`"
bn8 Import initial

bn8 authored 14 years ago

21) [ $DEBUG -eq 1 ] && echo "Current : $current"
22) 
root Multi check en cas d'erreur...

root authored 13 years ago

23) for i in `seq 1 $MAX_CHECK`
24) do
25) 	tmpfile=`mktemp`
26) 	wget -q $CHECK_URL -O $tmpfile
27) 	newest=`cat $tmpfile|grep Stable|sed 's/^.*Stable.*: \(.*\)<\/td>.*$/\1/'`
28) 	if [ -n "$newest" ]
29) 	then
30) 		[ $DEBUG -eq 1 ] && echo "Newest : $newest"
31) 		rm -f $CACHE_FAILED > /dev/null 2>&1
32) 
33) 		DOWNLOAD_URL=`cat $tmpfile|grep "$newest"|grep "tar.gz"|head -1|sed 's/.* href="\([^"]*\)" .*$/\1/'`
34) 		[ $DEBUG -eq 1 ] && echo "Download URL : $DOWNLOAD_URL"
35) 		[ ! -n "$DOWNLOAD_URL" ] && DOWNLOAD_URL="$CHECK_URL" && [ $DEBUG -eq 1 ] && echo "Use check URL as download URL : $DOWNLOAD_URL"
bn8 Import initial

bn8 authored 14 years ago

36) 
root Multi check en cas d'erreur...

root authored 13 years ago

37) 		rm -f $tmpfile > /dev/null 2>&1
38) 		break;
39) 	elif [ $i -eq $MAX_CHECK ]
40) 	then
41) 		error="Site du projet injoignable (ou structure du site modifie !!) => Impossible de recuperer le numero de la version stable actuel."
42) 		[ $DEBUG -eq 1 ] && echo $error
43) 		if [ -f $CACHE_FAILED ]
44) 		then
45) 			NB=`cat $CACHE_FAILED`
46) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur existe : $NB echec. Max : $MAX_FAILED"
47) 			if [ $NB -lt $MAX_FAILED ]
48) 			then
49) 				let NNB=NB+1
50) 				[ $DEBUG -eq 1 ] && echo "Augmentation du nb d'erreur dans le fichier de cache d'erreur : $NB -> $NNB"
51) 				echo -n $NNB > $CACHE_FAILED
52) 			else
53) 				[ $DEBUG -eq 1 ] && echo "MAX_FAILED atteint : on envoi un mail"
54) 				echo $error|mail -s "New RoundCude release check : FAILED" $MAIL
55) 			fi
56) 		else
57) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur n'existe pas : on l'initialise à 1."
58) 			echo -n 1 > $CACHE_FAILED
59) 		fi
60) 		[ $DEBUG -eq 1 ] && echo "exit 1"
61) 		exit 1
62) 	fi
63) 	[ $DEBUG -eq 1 ] && echo "Check failed ($i/$MAX_CHECK) : Sleep $SLEEP_ON_FAILED second before try again ..."
64) 	sleep $SLEEP_ON_FAILED
65) done
bn8 Import initial

bn8 authored 14 years ago

66) 
67) if [ "$newest" != "$current" ]
68) then
69) 	tmp=`mktemp`
70) 	echo "New RoundCude release" > $tmp
71) 	echo "=====================" >> $tmp
72) 	echo "Current : $current" >> $tmp
73) 	echo "Newest : $newest" >> $tmp
root Multi check en cas d'erreur...

root authored 13 years ago

74) 	echo >> $tmp
75) 	echo "Download URL : $DOWNLOAD_URL" >> $tmp
bn8 Import initial

bn8 authored 14 years ago

76) 	
77) 	M=0
78) 	if [ -f $CACHE ]
79) 	then
root Multi check en cas d'erreur...

root authored 13 years ago

80) 		if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
bn8 Import initial

bn8 authored 14 years ago

81) 		then
82) 			[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
83) 			M=1
84) 		else
85) 			[ $DEBUG -eq 1 ] && echo "Pas de modif et cache trop recent : pas d'envoi"
86) 		fi
87) 	else
88) 		[ $DEBUG -eq 1 ] && echo "Pas encore de cache => On envoi"
89) 		M=1
90) 	fi
Benjamin Renard Desactivation de l'envoi de...

Benjamin Renard authored 13 years ago

91) 	if [ $DEBUG -eq 1 -a $M -eq 1 ]
92) 	then
93) 		echo "Mode debug : Pas d'envoi de mail"
94) 	fi
95) 	if [ $M -eq 1 -a $DEBUG -ne 1 ]
bn8 Import initial

bn8 authored 14 years ago

96) 	then
97) 		cat $tmp > $CACHE
root Fixed bug in NAME test

root authored 13 years ago

98) 		if [ -n "$NAME" ]
Benjamin Renard Desactivation de l'envoi de...

Benjamin Renard authored 13 years ago

99) 		then
100) 			S="[$NAME] New RoundCude release"
101) 		else
102) 			S="New RoundCude release"
103) 		fi
Benjamin Renard Ajout d'un paramètre NAME p...

Benjamin Renard authored 13 years ago

104) 		cat $tmp | mail -s "$S : $newest" $MAIL