6717c5416bebda8fa3b37c18831f81f1ae474f93
bn8 Import initial

bn8 authored 14 years ago

1) #!/bin/bash
2) 
Benjamin Renard Remove OWNER and GROUP depr...

Benjamin Renard authored 9 years ago

3) ### CONFIGURATION ###
4) 
Benjamin Renard Ajout d'un paramètre NAME p...

Benjamin Renard authored 13 years ago

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

root authored 13 years ago

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

bn8 authored 14 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

10) CACHE_FAILED=$CACHE.failed
11) MAX_CHECK=10
12) MAX_FAILED=3
13) SLEEP_ON_FAILED=10
14) CHECK_URL=http://www.roundcube.net/download
root Change order for download f...

root authored 13 years ago

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

root authored 13 years ago

16) DOWNLOAD_DIR=$RC_HOME/../upstream
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

17) DONT_CHECK_SSL_CERT=0
Benjamin Renard Remove OWNER and GROUP depr...

Benjamin Renard authored 9 years ago

18) 
19) ### DO NOT MODIFY AFTER THIS LINE ###
bn8 Import initial

bn8 authored 14 years ago

20) 
21) DEBUG=0
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

22) NAGIOS=0
root Added upgrade feature

root authored 13 years ago

23) UPGRADE=0
24) EXTRACT=0
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

25) JUST_DISP=0
Benjamin Renard Add -a parameter to only ru...

Benjamin Renard authored 9 years ago

26) JUST_AFTER_UPGRADE=0
root Used getopts and added down...

root authored 13 years ago

27) 
28) function usage() {
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

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

root authored 13 years ago

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

Benjamin Renard authored 9 years ago

31) 	echo "  -n   Nagios mode"
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

32) 	echo "  -S   Don't check SSL certificate"
root Used getopts and added down...

root authored 13 years ago

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

root authored 13 years ago

34) 	echo "  -u   Upgrade installation"
Benjamin Renard Add -a parameter to only ru...

Benjamin Renard authored 9 years ago

35) 	echo "  -a   Just run after_upgrade function"
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

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

root authored 13 years ago

37) 	echo "  -h   Display this help"
38) }
39) 
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

40) while getopts ":dvnShuaj" opt; do
root Used getopts and added down...

root authored 13 years ago

41) 	case $opt in
42) 		v)
43) 			DEBUG=1
44) 		;;
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

45) 		n)
46) 			NAGIOS=1
47) 		;;
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

48) 		S)
49) 			DONT_CHECK_SSL_CERT=1
50) 		;;
root Used getopts and added down...

root authored 13 years ago

51) 		d)
52) 			DOWNLOAD=1
53) 		;;
root Added upgrade feature

root authored 13 years ago

54) 		u)
55) 			DOWNLOAD=1
56) 			UPGRADE=1
57) 			DEBUG=1
58) 			EXTRACT=1
59) 		;;
Benjamin Renard Add -a parameter to only ru...

Benjamin Renard authored 9 years ago

60) 		a)
61) 			JUST_AFTER_UPGRADE=1
62) 		;;
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

63) 		j)
64) 			JUST_DISP=1
65) 		;;
root Used getopts and added down...

root authored 13 years ago

66) 		h)
67) 			usage
68) 			exit 0
69) 		;;
70) 		\?)
71)                         echo "Invalid option: -$OPTARG" >&2
72) 			echo
73) 			usage
74) 			exit 1
75) 		;;
76) 		:)
77)                         echo "Option -$OPTARG requires an argument." >&2
78) 			echo
79) 			usage
80)                         exit 1
81)                 ;;
82) 
83) 	esac
84) done
bn8 Import initial

bn8 authored 14 years ago

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

root authored 13 years ago

86) [ -f "$0.local" ] && source "$0.local" && [ $DEBUG -eq 1 ] && echo "Import local config file : $0.local"
87) 
Benjamin Renard Add -a parameter to only ru...

Benjamin Renard authored 9 years ago

88) function run_after_upgrade() {
89) 	RC_NEW_HOME="$1"
90) 	type after_upgrade > /dev/null 2>&1
91) 	if [ $? -eq 0 ]
92) 	then
93) 		echo "Execution de la fonction custom after_upgrade() :"
94) 		after_upgrade "$RC_NEW_HOME"
95) 		res=$?
96) 		echo "Fin de la fonction after_upgrade() (Retour : $res)"
97) 		return $res
98) 	else
99) 		echo "La fonction 'after_upgrade' n'est pas définie. On passe."
100) 		return 0
101) 	fi
102) }
103) 
104) if [ $JUST_AFTER_UPGRADE -eq 1 ]
105) then
106) 	run_after_upgrade "$RC_HOME"
107) 	exit $?
108) fi
109) 
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

110) WGET_SSL_OPT=""
111) if [ "$DONT_CHECK_SSL_CERT" == "1" ]
112) then
113) 	[ $DEBUG -eq 1 ] && echo "Disable SSL certificate check"
114) 	WGET_SSL_OPT="--no-check-certificate"
115) fi
116) 
root Multi check en cas d'erreur...

root authored 13 years ago

117) for i in `seq 1 $MAX_CHECK`
118) do
119) 	tmpfile=`mktemp`
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

120) 	wget $WGET_SSL_OPT -q $CHECK_URL -O $tmpfile
root Fix to support complete/dep...

root authored 9 years ago

121) 	newest=`cat $tmpfile|grep 'downloads.sourceforge.net'|grep 'complete.tar.gz'|head -n 1|sed 's|^.*downloads.sourceforge.net/project/roundcubemail/roundcubemail/\([^/]*\)/roundcubemail-.*$|\1|'`
root Multi check en cas d'erreur...

root authored 13 years ago

122) 	if [ -n "$newest" ]
123) 	then
124) 		[ $DEBUG -eq 1 ] && echo "Newest : $newest"
Benjamin Renard Do not remove failed cache...

Benjamin Renard authored 9 years ago

125) 		[ $NAGIOS -ne 1 ] && rm -f $CACHE_FAILED > /dev/null 2>&1
root Multi check en cas d'erreur...

root authored 13 years ago

126) 
root Fix to support complete/dep...

root authored 9 years ago

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

root authored 13 years ago

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

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

root authored 13 years ago

131) 		rm -f $tmpfile > /dev/null 2>&1
132) 		break;
133) 	elif [ $i -eq $MAX_CHECK ]
134) 	then
Benjamin Renard Fix Nagios mode return levels

Benjamin Renard authored 9 years ago

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

root authored 13 years ago

136) 		error="Site du projet injoignable (ou structure du site modifie !!) => Impossible de recuperer le numero de la version stable actuel."
137) 		[ $DEBUG -eq 1 ] && echo $error
138) 		if [ -f $CACHE_FAILED ]
139) 		then
140) 			NB=`cat $CACHE_FAILED`
141) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur existe : $NB echec. Max : $MAX_FAILED"
142) 			if [ $NB -lt $MAX_FAILED ]
143) 			then
144) 				let NNB=NB+1
145) 				[ $DEBUG -eq 1 ] && echo "Augmentation du nb d'erreur dans le fichier de cache d'erreur : $NB -> $NNB"
146) 				echo -n $NNB > $CACHE_FAILED
147) 			else
148) 				[ $DEBUG -eq 1 ] && echo "MAX_FAILED atteint : on envoi un mail"
149) 				echo $error|mail -s "New RoundCude release check : FAILED" $MAIL
150) 			fi
151) 		else
152) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur n'existe pas : on l'initialise à 1."
153) 			echo -n 1 > $CACHE_FAILED
154) 		fi
155) 		[ $DEBUG -eq 1 ] && echo "exit 1"
156) 		exit 1
157) 	fi
158) 	[ $DEBUG -eq 1 ] && echo "Check failed ($i/$MAX_CHECK) : Sleep $SLEEP_ON_FAILED second before try again ..."
159) 	sleep $SLEEP_ON_FAILED
160) done
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

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

bn8 authored 14 years ago

162) 
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

168) 
169) if [ -z "$current" ]
170) then
171) 	[ $NAGIOS -eq 1 ] && echo "UNKNOWN : Fail to retrieve current installed version" && exit 3
172) 	echo "ERROR : Fail to retrieve current version !"
173) 	exit 3
174) fi
175) 
bn8 Import initial

bn8 authored 14 years ago

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

Benjamin Renard authored 9 years ago

178) 	if [ $NAGIOS -eq 1 ]
179) 	then
Benjamin Renard Fix Nagios mode return levels

Benjamin Renard authored 9 years ago

180) 		echo "WARNING : A newest version of Roundcube Webmail is available (newest : $newest / current : $current)"
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

181) 		exit 2
182) 	fi
root Used getopts and added down...

root authored 13 years ago

183) 
184) 	if [ $DOWNLOAD -eq 1 ]
185) 	then
186) 		if [ -d "$DOWNLOAD_DIR" ]
187) 		then
188) 			cd "$DOWNLOAD_DIR"
root Change order for download f...

root authored 13 years ago

189) 			DOWNLOAD_FILE="$( pwd )/roundcubemail-$newest.tar.gz"
190) 			[ $DEBUG -eq 1 ] && echo "Download new release in $DOWNLOAD_FILE"
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

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

root authored 13 years ago

192) 			if [ $EXTRACT -eq 1 ]
193) 			then
194) 				[ $DEBUG -eq 1 ] && echo "Extract new release"
195) 				tar xzf $DOWNLOAD_FILE
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

201) 		fi
202) 	fi
root Change order for download f...

root authored 13 years ago

203) 
root Added upgrade feature

root authored 13 years ago

204) 	if [ $UPGRADE -eq 1 ]
205) 	then
206) 		cd "$DOWNLOAD_DIR"
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

208) 		src=""
209) 		while [ ! -n "$src" ]
210) 		do 
211) 			echo -n "Source de la nouvelle version [$default_src] : "
212) 			read a
213) 			if [ -n "$a" ]
214) 			then
215) 				src="$a"
216) 			else
217) 				src="$default_src"
218) 			fi
219) 			if [ ! -d "$src" ]
220) 			then
221) 				echo -n "[WARNING] Le dossier $src n'existe pas."
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

222) 				src=""
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 10 years ago

225) 			if [ ! -x "$src/bin/installto.sh" ]
226) 			then
227) 				echo -n "[WARNING] Le script bin/installto.sh n'est pas présent dans ce répertoire source."
228) 				src=""
229) 				[ ! -n "$a" ] && default_src=""
230) 			fi
root Added upgrade feature

root authored 13 years ago

231) 		done
232) 		echo "Source : $src"
233) 
234) 		cd "$RC_HOME/../"
235) 		from=""
236) 		while [ ! -n "$from" ]
237) 		do 
238) 			echo -n "Installation source [$RC_HOME] : "
239) 			read a
240) 			if [ -n "$a" ]
241) 			then
242) 				if [ -d "$a" ]
243) 				then
244) 					from="$a"
245) 				else
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

246) 					from=""
root Added upgrade feature

root authored 13 years ago

247) 					echo "[ERROR] $a n'est pas un dossier valide"
248) 				fi
249) 			else
250) 				from="$RC_HOME"
251) 			fi	
252) 		done
253) 		echo "From : $from"
254) 		default_to="$( pwd )/roundcubemail-$newest"
255) 		to=""
256) 		while [ ! -n "$to" ]
257) 		do
258) 			echo -n "Destination de la nouvelle installation [$default_to] : "
259) 			read a
260) 			if [ -n "$a" ]
261) 			then
262) 				to="$a"
263) 			else
264) 				to="$default_to"
265) 			fi
266) 			if [ -d "$to" ]
267) 			then
268) 				echo -n "[WARNING] Le dossier $to existe deja. Celui-ci va etre deplace dans $to.old. Confirmez-vous votre choix [Y/n] ? "
269) 				read b
270) 				if [ "$b" == "n" -o "$b" == "N" ]
271) 				then
272) 					to=""
273) 					[ ! -n "$a" ] && default_to=""
274) 				else
275) 					echo "Deplace $to dans $to.old"
276) 					mv "$to" "$to.old"
277) 				fi
278) 			fi
279) 		done
280) 		echo "To : $to"
281) 		echo "Copie de $from dans $to"
282) 		rsync -a --copy-dirlinks "$from/" "$to/"
283) 
284) 		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

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

root authored 13 years ago

287) 
Benjamin Renard Add -a parameter to only ru...

Benjamin Renard authored 9 years ago

288) 		run_after_upgrade "$to"
Benjamin Renard Add after_upgrade() functio...

Benjamin Renard authored 10 years ago

289) 
root Added upgrade feature

root authored 13 years ago

290) 		if [ -L "$RC_HOME" ]
291) 		then
292) 			echo -n "Voulez-vous faire pointer le lien symbolique $RC_HOME vers cette nouvelle installation [Y/n] ? "
293) 			read a
294) 			if [ "$a" != "n" -a "$a" != "N" ]
295) 			then
296) 				echo "  - Suppression de l'actuel lien $RC_HOME"
297) 				rm -f $RC_HOME
298) 				echo "  - Creation du nouveau lien $RC_HOME vers $to"
299) 				ln -s "$to" "$RC_HOME"
300) 			fi
301) 		fi
302) 	else 
bn8 Import initial

bn8 authored 14 years ago

303) 	
root Added upgrade feature

root authored 13 years ago

304) 		tmp=`mktemp`
305) 		echo "New RoundCude release" > $tmp
306) 		echo "=====================" >> $tmp
307) 		echo "Current : $current" >> $tmp
308) 		echo "Newest : $newest" >> $tmp
309) 		echo >> $tmp
310) 		echo "Download URL : $DOWNLOAD_URL" >> $tmp
311) 		[ -n "$DOWNLOAD_FILE" -a -f "$DOWNLOAD_FILE" ] && echo "Download file : $( pwd )/roundcubemail-$newest.tar.gz" >> $tmp
312) 	
313) 		
314) 		M=0
315) 		if [ -f $CACHE ]
bn8 Import initial

bn8 authored 14 years ago

316) 		then
root Added upgrade feature

root authored 13 years ago

317) 			if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
318) 			then
319) 				[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
320) 				M=1
321) 			else
322) 				[ $DEBUG -eq 1 ] && echo "Pas de modif et cache trop recent : pas d'envoi"
323) 			fi
bn8 Import initial

bn8 authored 14 years ago

324) 		else
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

327) 		fi
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

329) 		then
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

331) 		fi
root Added upgrade feature

root authored 13 years ago

332) 		if [ $M -eq 1 -a $DEBUG -ne 1 ]
333) 		then
334) 			cat $tmp > $CACHE
335) 			if [ -n "$NAME" ]
336) 			then
337) 				S="[$NAME] New RoundCude release"
338) 			else
339) 				S="New RoundCude release"
340) 			fi
341) 			cat $tmp | mail -s "$S : $newest" $MAIL
342) 			[ $DEBUG -eq 1 ] && echo "Mail envoyé"
343) 		fi
344) 		rm -f $tmp
345) 
bn8 Import initial

bn8 authored 14 years ago

346) 	fi
347) else
348) 	[ $DEBUG -eq 1 ] && echo "Pas de changement de version"
Benjamin Renard Fix return code in OK case...

Benjamin Renard authored 9 years ago

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