6d9a8089e73ba301e522c16c212f5757d118a27d
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 14 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 14 years ago

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

root authored 14 years ago

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

root authored 14 years ago

10) CACHE_FAILED=$CACHE.failed
11) MAX_CHECK=10
12) MAX_FAILED=3
13) SLEEP_ON_FAILED=10
Benjamin Renard Update CHECK_URL

Benjamin Renard authored 7 years ago

14) CHECK_URL=https://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 Add possibility to use curl...

Benjamin Renard authored 7 years ago

18) WGET_OPTS=""
19) CURL_OPTS=""
Benjamin Renard Remove OWNER and GROUP depr...

Benjamin Renard authored 9 years ago

20) 
21) ### DO NOT MODIFY AFTER THIS LINE ###
bn8 Import initial

bn8 authored 14 years ago

22) 
23) DEBUG=0
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

24) NAGIOS=0
root Added upgrade feature

root authored 13 years ago

25) UPGRADE=0
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

26) CURL=0
root Added upgrade feature

root authored 13 years ago

27) EXTRACT=0
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

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

Benjamin Renard authored 9 years ago

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

root authored 13 years ago

30) 
31) function usage() {
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

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

root authored 13 years ago

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

Benjamin Renard authored 9 years ago

34) 	echo "  -n   Nagios mode"
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

35) 	echo "  -S   Don't check SSL certificate (Wget only)"
root Used getopts and added down...

root authored 13 years ago

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

root authored 13 years ago

37) 	echo "  -u   Upgrade installation"
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

38) 	echo "  -c   Use curl instead of wget"
Benjamin Renard Add -a parameter to only ru...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 11 years ago

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

root authored 13 years ago

41) 	echo "  -h   Display this help"
42) }
43) 
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

44) while getopts ":dvnShucaj" opt; do
root Used getopts and added down...

root authored 13 years ago

45) 	case $opt in
46) 		v)
47) 			DEBUG=1
48) 		;;
Benjamin Renard Add Nagios mode

Benjamin Renard authored 9 years ago

49) 		n)
50) 			NAGIOS=1
51) 		;;
Benjamin Renard Add option to disable SSL c...

Benjamin Renard authored 8 years ago

52) 		S)
53) 			DONT_CHECK_SSL_CERT=1
54) 		;;
root Used getopts and added down...

root authored 13 years ago

55) 		d)
56) 			DOWNLOAD=1
57) 		;;
root Added upgrade feature

root authored 13 years ago

58) 		u)
59) 			DOWNLOAD=1
60) 			UPGRADE=1
61) 			DEBUG=1
62) 			EXTRACT=1
63) 		;;
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

64) 		c)
65) 			CURL=1
66) 		;;
Benjamin Renard Add -a parameter to only ru...

Benjamin Renard authored 9 years ago

67) 		a)
68) 			JUST_AFTER_UPGRADE=1
69) 		;;
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

70) 		j)
71) 			JUST_DISP=1
72) 		;;
root Used getopts and added down...

root authored 13 years ago

73) 		h)
74) 			usage
75) 			exit 0
76) 		;;
77) 		\?)
78)                         echo "Invalid option: -$OPTARG" >&2
79) 			echo
80) 			usage
81) 			exit 1
82) 		;;
83) 		:)
84)                         echo "Option -$OPTARG requires an argument." >&2
85) 			echo
86) 			usage
87)                         exit 1
88)                 ;;
89) 
90) 	esac
91) done
bn8 Import initial

bn8 authored 14 years ago

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

root authored 14 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 8 years ago

117) WGET_SSL_OPT=""
118) if [ "$DONT_CHECK_SSL_CERT" == "1" ]
119) then
120) 	[ $DEBUG -eq 1 ] && echo "Disable SSL certificate check"
121) 	WGET_SSL_OPT="--no-check-certificate"
122) fi
123) 
root Multi check en cas d'erreur...

root authored 14 years ago

124) for i in `seq 1 $MAX_CHECK`
125) do
126) 	tmpfile=`mktemp`
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

127) 	if [ $CURL -eq 1 ]
128) 	then
Benjamin Renard Add --location parameter in...

Benjamin Renard authored 7 years ago

129) 		curl $CURL_OPTS --location --silent --output $tmpfile $CHECK_URL
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

130) 	else
131) 		wget $WGET_OPTS $WGET_SSL_OPT -q $CHECK_URL -O $tmpfile
132) 	fi
Benjamin Renard Fix method to retreive curr...

Benjamin Renard authored 8 years ago

133) 	newest=`cat $tmpfile|grep 'github.com'|grep 'complete.tar.gz'|head -n 1|sed 's|^.*github.com/roundcube/roundcubemail/releases/download/\([^/]*\)/roundcubemail-.*$|\1|'`
root Multi check en cas d'erreur...

root authored 14 years ago

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

Benjamin Renard authored 9 years ago

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

root authored 14 years ago

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

root authored 9 years ago

139) 		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 14 years ago

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

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

root authored 14 years ago

143) 		rm -f $tmpfile > /dev/null 2>&1
144) 		break;
145) 	elif [ $i -eq $MAX_CHECK ]
146) 	then
Benjamin Renard Fix Nagios mode return levels

Benjamin Renard authored 9 years ago

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

root authored 14 years ago

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

Benjamin Renard authored 11 years ago

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

bn8 authored 14 years ago

174) 
Benjamin Renard Added -j parameter

Benjamin Renard authored 11 years ago

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

Benjamin Renard authored 9 years ago

180) 
181) if [ -z "$current" ]
182) then
183) 	[ $NAGIOS -eq 1 ] && echo "UNKNOWN : Fail to retrieve current installed version" && exit 3
184) 	echo "ERROR : Fail to retrieve current version !"
185) 	exit 3
186) fi
187) 
bn8 Import initial

bn8 authored 14 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

192) 		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

193) 		exit 2
194) 	fi
root Used getopts and added down...

root authored 13 years ago

195) 
196) 	if [ $DOWNLOAD -eq 1 ]
197) 	then
198) 		if [ -d "$DOWNLOAD_DIR" ]
199) 		then
200) 			cd "$DOWNLOAD_DIR"
root Change order for download f...

root authored 13 years ago

201) 			DOWNLOAD_FILE="$( pwd )/roundcubemail-$newest.tar.gz"
202) 			[ $DEBUG -eq 1 ] && echo "Download new release in $DOWNLOAD_FILE"
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

203) 			if [ $CURL -eq 1 ]
204) 			then
Benjamin Renard Add --location parameter in...

Benjamin Renard authored 7 years ago

205) 				curl $CURL_OPTS --location --silent --output $DOWNLOAD_FILE $DOWNLOAD_URL
Benjamin Renard Add possibility to use curl...

Benjamin Renard authored 7 years ago

206) 			else
207) 				wget $WGET_OPTS $WGET_SSL_OPT -q -O "$DOWNLOAD_FILE" "$DOWNLOAD_URL"
208) 			fi
root Added upgrade feature

root authored 13 years ago

209) 			if [ $EXTRACT -eq 1 ]
210) 			then
211) 				[ $DEBUG -eq 1 ] && echo "Extract new release"
212) 				tar xzf $DOWNLOAD_FILE
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

218) 		fi
219) 	fi
root Change order for download f...

root authored 13 years ago

220) 
root Added upgrade feature

root authored 13 years ago

221) 	if [ $UPGRADE -eq 1 ]
222) 	then
223) 		cd "$DOWNLOAD_DIR"
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 13 years ago

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

root authored 13 years ago

225) 		src=""
226) 		while [ ! -n "$src" ]
227) 		do 
228) 			echo -n "Source de la nouvelle version [$default_src] : "
229) 			read a
230) 			if [ -n "$a" ]
231) 			then
232) 				src="$a"
233) 			else
234) 				src="$default_src"
235) 			fi
236) 			if [ ! -d "$src" ]
237) 			then
238) 				echo -n "[WARNING] Le dossier $src n'existe pas."
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 13 years ago

239) 				src=""
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 10 years ago

242) 			if [ ! -x "$src/bin/installto.sh" ]
243) 			then
244) 				echo -n "[WARNING] Le script bin/installto.sh n'est pas présent dans ce répertoire source."
245) 				src=""
246) 				[ ! -n "$a" ] && default_src=""
247) 			fi
root Added upgrade feature

root authored 13 years ago

248) 		done
249) 		echo "Source : $src"
250) 
251) 		cd "$RC_HOME/../"
252) 		from=""
253) 		while [ ! -n "$from" ]
254) 		do 
255) 			echo -n "Installation source [$RC_HOME] : "
256) 			read a
257) 			if [ -n "$a" ]
258) 			then
259) 				if [ -d "$a" ]
260) 				then
261) 					from="$a"
262) 				else
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 13 years ago

263) 					from=""
root Added upgrade feature

root authored 13 years ago

264) 					echo "[ERROR] $a n'est pas un dossier valide"
265) 				fi
266) 			else
267) 				from="$RC_HOME"
268) 			fi	
269) 		done
270) 		echo "From : $from"
271) 		default_to="$( pwd )/roundcubemail-$newest"
272) 		to=""
273) 		while [ ! -n "$to" ]
274) 		do
275) 			echo -n "Destination de la nouvelle installation [$default_to] : "
276) 			read a
277) 			if [ -n "$a" ]
278) 			then
279) 				to="$a"
280) 			else
281) 				to="$default_to"
282) 			fi
283) 			if [ -d "$to" ]
284) 			then
285) 				echo -n "[WARNING] Le dossier $to existe deja. Celui-ci va etre deplace dans $to.old. Confirmez-vous votre choix [Y/n] ? "
286) 				read b
287) 				if [ "$b" == "n" -o "$b" == "N" ]
288) 				then
289) 					to=""
290) 					[ ! -n "$a" ] && default_to=""
291) 				else
292) 					echo "Deplace $to dans $to.old"
293) 					mv "$to" "$to.old"
294) 				fi
295) 			fi
296) 		done
297) 		echo "To : $to"
298) 		echo "Copie de $from dans $to"
299) 		rsync -a --copy-dirlinks "$from/" "$to/"
300) 
301) 		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

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

root authored 13 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

306) 
root Added upgrade feature

root authored 13 years ago

307) 		if [ -L "$RC_HOME" ]
308) 		then
309) 			echo -n "Voulez-vous faire pointer le lien symbolique $RC_HOME vers cette nouvelle installation [Y/n] ? "
310) 			read a
311) 			if [ "$a" != "n" -a "$a" != "N" ]
312) 			then
313) 				echo "  - Suppression de l'actuel lien $RC_HOME"
314) 				rm -f $RC_HOME
315) 				echo "  - Creation du nouveau lien $RC_HOME vers $to"
316) 				ln -s "$to" "$RC_HOME"
317) 			fi
318) 		fi
319) 	else 
bn8 Import initial

bn8 authored 14 years ago

320) 	
root Added upgrade feature

root authored 13 years ago

321) 		tmp=`mktemp`
322) 		echo "New RoundCude release" > $tmp
323) 		echo "=====================" >> $tmp
324) 		echo "Current : $current" >> $tmp
325) 		echo "Newest : $newest" >> $tmp
326) 		echo >> $tmp
327) 		echo "Download URL : $DOWNLOAD_URL" >> $tmp
328) 		[ -n "$DOWNLOAD_FILE" -a -f "$DOWNLOAD_FILE" ] && echo "Download file : $( pwd )/roundcubemail-$newest.tar.gz" >> $tmp
329) 	
330) 		
331) 		M=0
332) 		if [ -f $CACHE ]
bn8 Import initial

bn8 authored 14 years ago

333) 		then
root Added upgrade feature

root authored 13 years ago

334) 			if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
335) 			then
336) 				[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
337) 				M=1
338) 			else
339) 				[ $DEBUG -eq 1 ] && echo "Pas de modif et cache trop recent : pas d'envoi"
340) 			fi
bn8 Import initial

bn8 authored 14 years ago

341) 		else
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

344) 		fi
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

346) 		then
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

348) 		fi
root Added upgrade feature

root authored 13 years ago

349) 		if [ $M -eq 1 -a $DEBUG -ne 1 ]
350) 		then
351) 			cat $tmp > $CACHE
352) 			if [ -n "$NAME" ]
353) 			then
354) 				S="[$NAME] New RoundCude release"
355) 			else
356) 				S="New RoundCude release"
357) 			fi
358) 			cat $tmp | mail -s "$S : $newest" $MAIL
359) 			[ $DEBUG -eq 1 ] && echo "Mail envoyé"
360) 		fi
361) 		rm -f $tmp
362) 
bn8 Import initial

bn8 authored 14 years ago

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

Benjamin Renard authored 9 years ago

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