Multi check en cas d'erreur avec envoi de mail au bout d'un trop grand nombre d'erreur + Ajout de l'URL de download dans le mail
root

root commited on 2010-10-07 09:03:56
Showing 1 changed files, with 52 additions and 4 deletions.

... ...
@@ -1,18 +1,64 @@
1 1
 #!/bin/bash
2 2
 
3
+RC_HOME=/var/www/webmail/public_html
3 4
 MAIL=root
4
-TIME=7
5
+SEND_EVERY_NB_DAY=7
5 6
 CACHE=/var/www/webmail/.cache_check_upgrade
7
+CACHE_FAILED=$CACHE.failed
8
+MAX_CHECK=10
9
+MAX_FAILED=3
10
+SLEEP_ON_FAILED=10
11
+CHECK_URL=http://www.roundcube.net/download
6 12
 
7 13
 DEBUG=0
8 14
 [ "$1" == "-v" ] && DEBUG=1
9 15
 
10
-current=`egrep "define.*RCMAIL_VERSION" /var/www/webmail/public_html/program/include/iniset.php|sed "s/define('.*', '\([^']*\)'.*$/\1/"`
16
+current=`egrep "define.*RCMAIL_VERSION" $RC_HOME/program/include/iniset.php|sed "s/define('.*', '\([^']*\)'.*$/\1/"`
11 17
 [ $DEBUG -eq 1 ] && echo "Current : $current"
12 18
 
13
-newest=`wget -q http://www.roundcube.net/download -O - |grep Stable|sed 's/^.*Stable.*: \(.*\)<\/td>.*$/\1/'`
19
+for i in `seq 1 $MAX_CHECK`
20
+do
21
+	tmpfile=`mktemp`
22
+	wget -q $CHECK_URL -O $tmpfile
23
+	newest=`cat $tmpfile|grep Stable|sed 's/^.*Stable.*: \(.*\)<\/td>.*$/\1/'`
24
+	if [ -n "$newest" ]
25
+	then
14 26
 		[ $DEBUG -eq 1 ] && echo "Newest : $newest"
27
+		rm -f $CACHE_FAILED > /dev/null 2>&1
28
+
29
+		DOWNLOAD_URL=`cat $tmpfile|grep "$newest"|grep "tar.gz"|head -1|sed 's/.* href="\([^"]*\)" .*$/\1/'`
30
+		[ $DEBUG -eq 1 ] && echo "Download URL : $DOWNLOAD_URL"
31
+		[ ! -n "$DOWNLOAD_URL" ] && DOWNLOAD_URL="$CHECK_URL" && [ $DEBUG -eq 1 ] && echo "Use check URL as download URL : $DOWNLOAD_URL"
15 32
 
33
+		rm -f $tmpfile > /dev/null 2>&1
34
+		break;
35
+	elif [ $i -eq $MAX_CHECK ]
36
+	then
37
+		error="Site du projet injoignable (ou structure du site modifie !!) => Impossible de recuperer le numero de la version stable actuel."
38
+		[ $DEBUG -eq 1 ] && echo $error
39
+		if [ -f $CACHE_FAILED ]
40
+		then
41
+			NB=`cat $CACHE_FAILED`
42
+			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur existe : $NB echec. Max : $MAX_FAILED"
43
+			if [ $NB -lt $MAX_FAILED ]
44
+			then
45
+				let NNB=NB+1
46
+				[ $DEBUG -eq 1 ] && echo "Augmentation du nb d'erreur dans le fichier de cache d'erreur : $NB -> $NNB"
47
+				echo -n $NNB > $CACHE_FAILED
48
+			else
49
+				[ $DEBUG -eq 1 ] && echo "MAX_FAILED atteint : on envoi un mail"
50
+				echo $error|mail -s "New RoundCude release check : FAILED" $MAIL
51
+			fi
52
+		else
53
+			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur n'existe pas : on l'initialise à 1."
54
+			echo -n 1 > $CACHE_FAILED
55
+		fi
56
+		[ $DEBUG -eq 1 ] && echo "exit 1"
57
+		exit 1
58
+	fi
59
+	[ $DEBUG -eq 1 ] && echo "Check failed ($i/$MAX_CHECK) : Sleep $SLEEP_ON_FAILED second before try again ..."
60
+	sleep $SLEEP_ON_FAILED
61
+done
16 62
 
17 63
 if [ "$newest" != "$current" ]
18 64
 then
... ...
@@ -21,11 +67,13 @@ then
21 67
 	echo "=====================" >> $tmp
22 68
 	echo "Current : $current" >> $tmp
23 69
 	echo "Newest : $newest" >> $tmp
70
+	echo >> $tmp
71
+	echo "Download URL : $DOWNLOAD_URL" >> $tmp
24 72
 	
25 73
 	M=0
26 74
 	if [ -f $CACHE ]
27 75
 	then
28
-		if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$TIME | wc -l` -eq 1 ]
76
+		if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
29 77
 		then
30 78
 			[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
31 79
 			M=1
32 80