71aeb4805d114c6ffe8c322da35fe694115f57df
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
root Added upgrade feature

root authored 13 years ago

19) UPGRADE=0
20) EXTRACT=0
root Used getopts and added down...

root authored 13 years ago

21) 
22) function usage() {
root Added upgrade feature

root authored 13 years ago

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

root authored 13 years ago

24) 	echo "  -v   Verbose mode"
25) 	echo "  -d   Download new release"
root Added upgrade feature

root authored 13 years ago

26) 	echo "  -u   Upgrade installation"
root Used getopts and added down...

root authored 13 years ago

27) 	echo "  -h   Display this help"
28) }
29) 
root Added upgrade feature

root authored 13 years ago

30) while getopts ":dvhu" opt; do
root Used getopts and added down...

root authored 13 years ago

31) 	case $opt in
32) 		v)
33) 			DEBUG=1
34) 		;;
35) 		d)
36) 			DOWNLOAD=1
37) 		;;
root Added upgrade feature

root authored 13 years ago

38) 		u)
39) 			DOWNLOAD=1
40) 			UPGRADE=1
41) 			DEBUG=1
42) 			EXTRACT=1
43) 		;;
root Used getopts and added down...

root authored 13 years ago

44) 		h)
45) 			usage
46) 			exit 0
47) 		;;
48) 		\?)
49)                         echo "Invalid option: -$OPTARG" >&2
50) 			echo
51) 			usage
52) 			exit 1
53) 		;;
54) 		:)
55)                         echo "Option -$OPTARG requires an argument." >&2
56) 			echo
57) 			usage
58)                         exit 1
59)                 ;;
60) 
61) 	esac
62) done
bn8 Import initial

bn8 authored 14 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

67) current="`echo $current|sed 's/-rc$//'`"
Benjamin Renard Added filter on release ver...

Benjamin Renard authored 12 years ago

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

bn8 authored 14 years ago

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

root authored 13 years ago

71) for i in `seq 1 $MAX_CHECK`
72) do
73) 	tmpfile=`mktemp`
74) 	wget -q $CHECK_URL -O $tmpfile
Benjamin Renard Fix check upgrade when two...

Benjamin Renard authored 11 years ago

75) 	newest=`cat $tmpfile|grep Stable|grep dlversion|sed 's/^.*Stable.*: \(.*\)<\/td>.*$/\1/'|head -n 1`
root Multi check en cas d'erreur...

root authored 13 years ago

76) 	if [ -n "$newest" ]
77) 	then
78) 		[ $DEBUG -eq 1 ] && echo "Newest : $newest"
79) 		rm -f $CACHE_FAILED > /dev/null 2>&1
80) 
Benjamin Renard change regex to match downl...

Benjamin Renard authored 12 years ago

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

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

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

root authored 13 years ago

85) 		rm -f $tmpfile > /dev/null 2>&1
86) 		break;
87) 	elif [ $i -eq $MAX_CHECK ]
88) 	then
89) 		error="Site du projet injoignable (ou structure du site modifie !!) => Impossible de recuperer le numero de la version stable actuel."
90) 		[ $DEBUG -eq 1 ] && echo $error
91) 		if [ -f $CACHE_FAILED ]
92) 		then
93) 			NB=`cat $CACHE_FAILED`
94) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur existe : $NB echec. Max : $MAX_FAILED"
95) 			if [ $NB -lt $MAX_FAILED ]
96) 			then
97) 				let NNB=NB+1
98) 				[ $DEBUG -eq 1 ] && echo "Augmentation du nb d'erreur dans le fichier de cache d'erreur : $NB -> $NNB"
99) 				echo -n $NNB > $CACHE_FAILED
100) 			else
101) 				[ $DEBUG -eq 1 ] && echo "MAX_FAILED atteint : on envoi un mail"
102) 				echo $error|mail -s "New RoundCude release check : FAILED" $MAIL
103) 			fi
104) 		else
105) 			[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur n'existe pas : on l'initialise à 1."
106) 			echo -n 1 > $CACHE_FAILED
107) 		fi
108) 		[ $DEBUG -eq 1 ] && echo "exit 1"
109) 		exit 1
110) 	fi
111) 	[ $DEBUG -eq 1 ] && echo "Check failed ($i/$MAX_CHECK) : Sleep $SLEEP_ON_FAILED second before try again ..."
112) 	sleep $SLEEP_ON_FAILED
113) done
bn8 Import initial

bn8 authored 14 years ago

114) 
115) if [ "$newest" != "$current" ]
116) then
root Used getopts and added down...

root authored 13 years ago

117) 
118) 	if [ $DOWNLOAD -eq 1 ]
119) 	then
120) 		if [ -d "$DOWNLOAD_DIR" ]
121) 		then
122) 			cd "$DOWNLOAD_DIR"
root Change order for download f...

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

126) 			if [ $EXTRACT -eq 1 ]
127) 			then
128) 				[ $DEBUG -eq 1 ] && echo "Extract new release"
129) 				tar xzf $DOWNLOAD_FILE
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

135) 		fi
136) 	fi
root Change order for download f...

root authored 13 years ago

137) 
root Added upgrade feature

root authored 13 years ago

138) 	if [ $UPGRADE -eq 1 ]
139) 	then
140) 		cd "$DOWNLOAD_DIR"
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

142) 		src=""
143) 		while [ ! -n "$src" ]
144) 		do 
145) 			echo -n "Source de la nouvelle version [$default_src] : "
146) 			read a
147) 			if [ -n "$a" ]
148) 			then
149) 				src="$a"
150) 			else
151) 				src="$default_src"
152) 			fi
153) 			if [ ! -d "$src" ]
154) 			then
155) 				echo -n "[WARNING] Le dossier $src n'existe pas."
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

156) 				src=""
root Added upgrade feature

root authored 13 years ago

157) 				[ ! -n "$a" ] && default_src=""
158) 			fi
159) 		done
160) 		echo "Source : $src"
161) 
162) 		cd "$RC_HOME/../"
163) 		from=""
164) 		while [ ! -n "$from" ]
165) 		do 
166) 			echo -n "Installation source [$RC_HOME] : "
167) 			read a
168) 			if [ -n "$a" ]
169) 			then
170) 				if [ -d "$a" ]
171) 				then
172) 					from="$a"
173) 				else
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

174) 					from=""
root Added upgrade feature

root authored 13 years ago

175) 					echo "[ERROR] $a n'est pas un dossier valide"
176) 				fi
177) 			else
178) 				from="$RC_HOME"
179) 			fi	
180) 		done
181) 		echo "From : $from"
182) 		default_to="$( pwd )/roundcubemail-$newest"
183) 		to=""
184) 		while [ ! -n "$to" ]
185) 		do
186) 			echo -n "Destination de la nouvelle installation [$default_to] : "
187) 			read a
188) 			if [ -n "$a" ]
189) 			then
190) 				to="$a"
191) 			else
192) 				to="$default_to"
193) 			fi
194) 			if [ -d "$to" ]
195) 			then
196) 				echo -n "[WARNING] Le dossier $to existe deja. Celui-ci va etre deplace dans $to.old. Confirmez-vous votre choix [Y/n] ? "
197) 				read b
198) 				if [ "$b" == "n" -o "$b" == "N" ]
199) 				then
200) 					to=""
201) 					[ ! -n "$a" ] && default_to=""
202) 				else
203) 					echo "Deplace $to dans $to.old"
204) 					mv "$to" "$to.old"
205) 				fi
206) 			fi
207) 		done
208) 		echo "To : $to"
209) 		echo "Copie de $from dans $to"
210) 		rsync -a --copy-dirlinks "$from/" "$to/"
211) 
212) 		echo "Mise a jour de l'installation $to a partir de $src : "
213) 		for file in index.php bin/ SQL/ program/ installer/ skins/default/ plugins/
214) 		do
215) 			echo "  - Mise a jour de $file"
Benjamin Renard Fix bug : preserve non-stan...

Benjamin Renard authored 12 years ago

216) 			rsync -a $src/$file $to/$file
root Added upgrade feature

root authored 13 years ago

217) 			chown $OWNER:$GROUP -R $to/$file
218) 		done
219) 
220) 		cd "$to"
221) 		if [ -x "bin/update.sh" ]
222) 		then
223) 			echo "Lancement de l'utilitaire de verification de mise a jour"
224) 			./bin/update.sh
225) 		fi
root Change order for download f...

root authored 13 years ago

226) 
root Added upgrade feature

root authored 13 years ago

227) 		if [ -L "$RC_HOME" ]
228) 		then
229) 			echo -n "Voulez-vous faire pointer le lien symbolique $RC_HOME vers cette nouvelle installation [Y/n] ? "
230) 			read a
231) 			if [ "$a" != "n" -a "$a" != "N" ]
232) 			then
233) 				echo "  - Suppression de l'actuel lien $RC_HOME"
234) 				rm -f $RC_HOME
235) 				echo "  - Creation du nouveau lien $RC_HOME vers $to"
236) 				ln -s "$to" "$RC_HOME"
237) 			fi
238) 		fi
239) 	else 
bn8 Import initial

bn8 authored 14 years ago

240) 	
root Added upgrade feature

root authored 13 years ago

241) 		tmp=`mktemp`
242) 		echo "New RoundCude release" > $tmp
243) 		echo "=====================" >> $tmp
244) 		echo "Current : $current" >> $tmp
245) 		echo "Newest : $newest" >> $tmp
246) 		echo >> $tmp
247) 		echo "Download URL : $DOWNLOAD_URL" >> $tmp
248) 		[ -n "$DOWNLOAD_FILE" -a -f "$DOWNLOAD_FILE" ] && echo "Download file : $( pwd )/roundcubemail-$newest.tar.gz" >> $tmp
249) 	
250) 		
251) 		M=0
252) 		if [ -f $CACHE ]
bn8 Import initial

bn8 authored 14 years ago

253) 		then
root Added upgrade feature

root authored 13 years ago

254) 			if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
255) 			then
256) 				[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
257) 				M=1
258) 			else
259) 				[ $DEBUG -eq 1 ] && echo "Pas de modif et cache trop recent : pas d'envoi"
260) 			fi
bn8 Import initial

bn8 authored 14 years ago

261) 		else
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

264) 		fi
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

266) 		then
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

268) 		fi
root Added upgrade feature

root authored 13 years ago

269) 		if [ $M -eq 1 -a $DEBUG -ne 1 ]
270) 		then
271) 			cat $tmp > $CACHE
272) 			if [ -n "$NAME" ]
273) 			then
274) 				S="[$NAME] New RoundCude release"
275) 			else
276) 				S="New RoundCude release"
277) 			fi
278) 			cat $tmp | mail -s "$S : $newest" $MAIL
279) 			[ $DEBUG -eq 1 ] && echo "Mail envoyé"
280) 		fi
281) 		rm -f $tmp
282)