56ba7022006403c341b186a6d0c0292fc321a932
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
root Change order for download f...

root authored 13 years ago

13) DOWNLOAD=0
root Used getopts and added down...

root authored 13 years ago

14) DOWNLOAD_DIR=$RC_HOME/../upstream
root Added upgrade feature

root authored 13 years ago

15) OWNER=root
16) GROUP=www-data
bn8 Import initial

bn8 authored 14 years ago

17) 
18) DEBUG=0
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

19) NAGIOS=0
root Added upgrade feature

root authored 13 years ago

20) UPGRADE=0
21) EXTRACT=0
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

22) JUST_DISP=0
root Used getopts and added down...

root authored 13 years ago

23) 
24) function usage() {
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

25) 	echo "Usage : $0 [-v] [-n] [-d] [-u]"
root Used getopts and added down...

root authored 13 years ago

26) 	echo "  -v   Verbose mode"
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

27) 	echo "  -n   Nagios mode"
root Used getopts and added down...

root authored 13 years ago

28) 	echo "  -d   Download new release"
root Added upgrade feature

root authored 13 years ago

29) 	echo "  -u   Upgrade installation"
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

30) 	echo "  -j   Just display current stable version"
root Used getopts and added down...

root authored 13 years ago

31) 	echo "  -h   Display this help"
32) }
33) 
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

34) while getopts ":dvnhuj" opt; do
root Used getopts and added down...

root authored 13 years ago

35) 	case $opt in
36) 		v)
37) 			DEBUG=1
38) 		;;
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

39) 		n)
40) 			NAGIOS=1
41) 		;;
root Used getopts and added down...

root authored 13 years ago

42) 		d)
43) 			DOWNLOAD=1
44) 		;;
root Added upgrade feature

root authored 13 years ago

45) 		u)
46) 			DOWNLOAD=1
47) 			UPGRADE=1
48) 			DEBUG=1
49) 			EXTRACT=1
50) 		;;
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

51) 		j)
52) 			JUST_DISP=1
53) 		;;
root Used getopts and added down...

root authored 13 years ago

54) 		h)
55) 			usage
56) 			exit 0
57) 		;;
58) 		\?)
59)                         echo "Invalid option: -$OPTARG" >&2
60) 			echo
61) 			usage
62) 			exit 1
63) 		;;
64) 		:)
65)                         echo "Option -$OPTARG requires an argument." >&2
66) 			echo
67) 			usage
68)                         exit 1
69)                 ;;
70) 
71) 	esac
72) done
bn8 Import initial

bn8 authored 14 years ago

73) 
root Ajout de l'inclusion d'un f...

root authored 13 years ago

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

root authored 13 years ago

76) for i in `seq 1 $MAX_CHECK`
77) do
78) 	tmpfile=`mktemp`
79) 	wget -q $CHECK_URL -O $tmpfile
Benjamin Renard Fixed after website structu...

Benjamin Renard authored 11 years ago

80) 	newest=`cat $tmpfile|grep dlversion|grep Complete|head -n 1|sed 's/^.*: \([0-9\.]*\).*$/\1/'`
root Multi check en cas d'erreur...

root authored 13 years ago

81) 	if [ -n "$newest" ]
82) 	then
83) 		[ $DEBUG -eq 1 ] && echo "Newest : $newest"
84) 		rm -f $CACHE_FAILED > /dev/null 2>&1
85) 
Benjamin Renard change regex to match downl...

Benjamin Renard authored 12 years ago

86) 		DOWNLOAD_URL=`cat $tmpfile|grep "$newest"|grep "tar.gz"|head -1|sed 's/.* href="[ \t]*\([^"]*\)[ \t]*" .*$/\1/'`
root Multi check en cas d'erreur...

root authored 13 years ago

87) 		[ $DEBUG -eq 1 ] && echo "Download URL : $DOWNLOAD_URL"
88) 		[ ! -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

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

root authored 13 years ago

90) 		rm -f $tmpfile > /dev/null 2>&1
91) 		break;
92) 	elif [ $i -eq $MAX_CHECK ]
93) 	then
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

94) 		[ $NAGIOS -eq 1 ] && echo "WARNING : Fail to retrieve current stable version" && exit 1
root Multi check en cas d'erreur...

root authored 13 years ago

95) 		error="Site du projet injoignable (ou structure du site modifie !!) => Impossible de recuperer le numero de la version stable actuel."
96) 		[ $DEBUG -eq 1 ] && echo $error
97) 		if [ -f $CACHE_FAILED ]
98) 		then
99) 			NB=`cat $CACHE_FAILED`
100) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur existe : $NB echec. Max : $MAX_FAILED"
101) 			if [ $NB -lt $MAX_FAILED ]
102) 			then
103) 				let NNB=NB+1
104) 				[ $DEBUG -eq 1 ] && echo "Augmentation du nb d'erreur dans le fichier de cache d'erreur : $NB -> $NNB"
105) 				echo -n $NNB > $CACHE_FAILED
106) 			else
107) 				[ $DEBUG -eq 1 ] && echo "MAX_FAILED atteint : on envoi un mail"
108) 				echo $error|mail -s "New RoundCude release check : FAILED" $MAIL
109) 			fi
110) 		else
111) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur n'existe pas : on l'initialise à 1."
112) 			echo -n 1 > $CACHE_FAILED
113) 		fi
114) 		[ $DEBUG -eq 1 ] && echo "exit 1"
115) 		exit 1
116) 	fi
117) 	[ $DEBUG -eq 1 ] && echo "Check failed ($i/$MAX_CHECK) : Sleep $SLEEP_ON_FAILED second before try again ..."
118) 	sleep $SLEEP_ON_FAILED
119) done
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

120) [ $JUST_DISP -eq 1 ] && echo -e "Current stable version : $newest\nDownload URL : $DOWNLOAD_URL" && exit 0
bn8 Import initial

bn8 authored 14 years ago

121) 
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

122) current=`egrep "define.*RCMAIL_VERSION" $RC_HOME/program/include/iniset.php|sed "s/define('.*', '\([^']*\)'.*$/\1/"`
123) current="`echo $current|sed 's/-rc$//'`"
124) current="`echo $current|sed 's/-beta$//'`"
125) 
126) [ $DEBUG -eq 1 ] && echo "Current : $current"
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

127) 
128) if [ -z "$current" ]
129) then
130) 	[ $NAGIOS -eq 1 ] && echo "UNKNOWN : Fail to retrieve current installed version" && exit 3
131) 	echo "ERROR : Fail to retrieve current version !"
132) 	exit 3
133) fi
134) 
bn8 Import initial

bn8 authored 14 years ago

135) if [ "$newest" != "$current" ]
136) then
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

137) 	if [ $NAGIOS -eq 1 ]
138) 	then
139) 		echo "CRITICAL : A newest version of Roundcube Webmail is available (newest : $newest / current : $current)"
140) 		exit 2
141) 	fi
root Used getopts and added down...

root authored 13 years ago

142) 
143) 	if [ $DOWNLOAD -eq 1 ]
144) 	then
145) 		if [ -d "$DOWNLOAD_DIR" ]
146) 		then
147) 			cd "$DOWNLOAD_DIR"
root Change order for download f...

root authored 13 years ago

148) 			DOWNLOAD_FILE="$( pwd )/roundcubemail-$newest.tar.gz"
149) 			[ $DEBUG -eq 1 ] && echo "Download new release in $DOWNLOAD_FILE"
root Fixed bug in last comit

root authored 13 years ago

150) 			wget -q -O "$DOWNLOAD_FILE" "$DOWNLOAD_URL"
root Added upgrade feature

root authored 13 years ago

151) 			if [ $EXTRACT -eq 1 ]
152) 			then
153) 				[ $DEBUG -eq 1 ] && echo "Extract new release"
154) 				tar xzf $DOWNLOAD_FILE
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

155) 				DOWNLOAD_FILE_DIR=$( tar tzf $DOWNLOAD_FILE 2> /dev/null|head -n1|cut -d'/' -f1 )
root Added upgrade feature

root authored 13 years ago

156) 			fi
root Used getopts and added down...

root authored 13 years ago

157) 		else
158) 			echo "[WARNING] Le dossier de telechargement n'existe pas ($DOWNLOAD_DIR)."
root Added upgrade feature

root authored 13 years ago

159) 			[ $UPGRADE -eq 1 ] && exit 1
root Used getopts and added down...

root authored 13 years ago

160) 		fi
161) 	fi
root Change order for download f...

root authored 13 years ago

162) 
root Added upgrade feature

root authored 13 years ago

163) 	if [ $UPGRADE -eq 1 ]
164) 	then
165) 		cd "$DOWNLOAD_DIR"
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

166) 		default_src="$( pwd )/$DOWNLOAD_FILE_DIR"
root Added upgrade feature

root authored 13 years ago

167) 		src=""
168) 		while [ ! -n "$src" ]
169) 		do 
170) 			echo -n "Source de la nouvelle version [$default_src] : "
171) 			read a
172) 			if [ -n "$a" ]
173) 			then
174) 				src="$a"
175) 			else
176) 				src="$default_src"
177) 			fi
178) 			if [ ! -d "$src" ]
179) 			then
180) 				echo -n "[WARNING] Le dossier $src n'existe pas."
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

181) 				src=""
root Added upgrade feature

root authored 13 years ago

182) 				[ ! -n "$a" ] && default_src=""
183) 			fi
Benjamin Renard Upgrade script to use bin/i...

Benjamin Renard authored 10 years ago

184) 			if [ ! -x "$src/bin/installto.sh" ]
185) 			then
186) 				echo -n "[WARNING] Le script bin/installto.sh n'est pas présent dans ce répertoire source."
187) 				src=""
188) 				[ ! -n "$a" ] && default_src=""
189) 			fi
root Added upgrade feature

root authored 13 years ago

190) 		done
191) 		echo "Source : $src"
192) 
193) 		cd "$RC_HOME/../"
194) 		from=""
195) 		while [ ! -n "$from" ]
196) 		do 
197) 			echo -n "Installation source [$RC_HOME] : "
198) 			read a
199) 			if [ -n "$a" ]
200) 			then
201) 				if [ -d "$a" ]
202) 				then
203) 					from="$a"
204) 				else
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

205) 					from=""
root Added upgrade feature

root authored 13 years ago

206) 					echo "[ERROR] $a n'est pas un dossier valide"
207) 				fi
208) 			else
209) 				from="$RC_HOME"
210) 			fi	
211) 		done
212) 		echo "From : $from"
213) 		default_to="$( pwd )/roundcubemail-$newest"
214) 		to=""
215) 		while [ ! -n "$to" ]
216) 		do
217) 			echo -n "Destination de la nouvelle installation [$default_to] : "
218) 			read a
219) 			if [ -n "$a" ]
220) 			then
221) 				to="$a"
222) 			else
223) 				to="$default_to"
224) 			fi
225) 			if [ -d "$to" ]
226) 			then
227) 				echo -n "[WARNING] Le dossier $to existe deja. Celui-ci va etre deplace dans $to.old. Confirmez-vous votre choix [Y/n] ? "
228) 				read b
229) 				if [ "$b" == "n" -o "$b" == "N" ]
230) 				then
231) 					to=""
232) 					[ ! -n "$a" ] && default_to=""
233) 				else
234) 					echo "Deplace $to dans $to.old"
235) 					mv "$to" "$to.old"
236) 				fi
237) 			fi
238) 		done
239) 		echo "To : $to"
240) 		echo "Copie de $from dans $to"
241) 		rsync -a --copy-dirlinks "$from/" "$to/"
242) 
243) 		echo "Mise a jour de l'installation $to a partir de $src : "
Benjamin Renard Upgrade script to use bin/i...

Benjamin Renard authored 10 years ago

244) 		cd "$src"
245) 		./bin/installto.sh "$to"
root Change order for download f...

root authored 13 years ago

246) 
Benjamin Renard Add after_upgrade() functio...

Benjamin Renard authored 10 years ago

247) 		type after_upgrade > /dev/null 2>&1
248) 		if [ $? -eq 0 ]
249) 		then
250) 			echo "Execution de la fonction custom after_upgrade() :"
Benjamin Renard Pass installation path to a...

Benjamin Renard authored 9 years ago

251) 			after_upgrade "$to"
Benjamin Renard Add after_upgrade() functio...

Benjamin Renard authored 10 years ago

252) 			echo "Fin de la fonction after_upgrade()"
253) 		fi
254) 
root Added upgrade feature

root authored 13 years ago

255) 		if [ -L "$RC_HOME" ]
256) 		then
257) 			echo -n "Voulez-vous faire pointer le lien symbolique $RC_HOME vers cette nouvelle installation [Y/n] ? "
258) 			read a
259) 			if [ "$a" != "n" -a "$a" != "N" ]
260) 			then
261) 				echo "  - Suppression de l'actuel lien $RC_HOME"
262) 				rm -f $RC_HOME
263) 				echo "  - Creation du nouveau lien $RC_HOME vers $to"
264) 				ln -s "$to" "$RC_HOME"
265) 			fi
266) 		fi
267) 	else 
bn8 Import initial

bn8 authored 14 years ago

268) 	
root Added upgrade feature

root authored 13 years ago

269) 		tmp=`mktemp`
270) 		echo "New RoundCude release" > $tmp
271) 		echo "=====================" >> $tmp
272) 		echo "Current : $current" >> $tmp
273) 		echo "Newest : $newest" >> $tmp
274) 		echo >> $tmp
275) 		echo "Download URL : $DOWNLOAD_URL" >> $tmp
276) 		[ -n "$DOWNLOAD_FILE" -a -f "$DOWNLOAD_FILE" ] && echo "Download file : $( pwd )/roundcubemail-$newest.tar.gz" >> $tmp
277) 	
278) 		
279) 		M=0
280) 		if [ -f $CACHE ]
bn8 Import initial

bn8 authored 14 years ago

281) 		then
root Added upgrade feature

root authored 13 years ago

282) 			if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
283) 			then
284) 				[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
285) 				M=1
286) 			else
287) 				[ $DEBUG -eq 1 ] && echo "Pas de modif et cache trop recent : pas d'envoi"
288) 			fi
bn8 Import initial

bn8 authored 14 years ago

289) 		else
root Added upgrade feature

root authored 13 years ago

290) 			[ $DEBUG -eq 1 ] && echo "Pas encore de cache => On envoi"
291) 			M=1
bn8 Import initial

bn8 authored 14 years ago

292) 		fi
root Added upgrade feature

root authored 13 years ago

293) 		if [ $DEBUG -eq 1 -a $M -eq 1 ]
Benjamin Renard Desactivation de l'envoi de...

Benjamin Renard authored 13 years ago

294) 		then
root Added upgrade feature

root authored 13 years ago

295) 			echo "Mode debug : Pas d'envoi de mail"
Benjamin Renard Desactivation de l'envoi de...

Benjamin Renard authored 13 years ago

296) 		fi
root Added upgrade feature

root authored 13 years ago

297) 		if [ $M -eq 1 -a $DEBUG -ne 1 ]
298) 		then
299) 			cat $tmp > $CACHE
300) 			if [ -n "$NAME" ]
301) 			then
302) 				S="[$NAME] New RoundCude release"
303) 			else
304) 				S="New RoundCude release"
305) 			fi
306) 			cat $tmp | mail -s "$S : $newest" $MAIL
307) 			[ $DEBUG -eq 1 ] && echo "Mail envoyé"
308) 		fi
309) 		rm -f $tmp
310) 
bn8 Import initial

bn8 authored 14 years ago

311) 	fi
312) else
313) 	[ $DEBUG -eq 1 ] && echo "Pas de changement de version"
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

314) 	[ $NAGIOS -eq 1 ] && echo "OK : Lastest version installed" && exit 1