10caef85b802b02c03e0a3610f5b485f101bc54e
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$//'`"
bn8 Import initial

bn8 authored 14 years ago

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

root authored 13 years ago

70) for i in `seq 1 $MAX_CHECK`
71) do
72) 	tmpfile=`mktemp`
73) 	wget -q $CHECK_URL -O $tmpfile
74) 	newest=`cat $tmpfile|grep Stable|sed 's/^.*Stable.*: \(.*\)<\/td>.*$/\1/'`
75) 	if [ -n "$newest" ]
76) 	then
77) 		[ $DEBUG -eq 1 ] && echo "Newest : $newest"
78) 		rm -f $CACHE_FAILED > /dev/null 2>&1
79) 
80) 		DOWNLOAD_URL=`cat $tmpfile|grep "$newest"|grep "tar.gz"|head -1|sed 's/.* href="\([^"]*\)" .*$/\1/'`
81) 		[ $DEBUG -eq 1 ] && echo "Download URL : $DOWNLOAD_URL"
82) 		[ ! -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

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

root authored 13 years ago

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

bn8 authored 14 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

125) 			if [ $EXTRACT -eq 1 ]
126) 			then
127) 				[ $DEBUG -eq 1 ] && echo "Extract new release"
128) 				tar xzf $DOWNLOAD_FILE
129) 			fi
root Used getopts and added down...

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

133) 		fi
134) 	fi
root Change order for download f...

root authored 13 years ago

135) 
root Added upgrade feature

root authored 13 years ago

136) 	if [ $UPGRADE -eq 1 ]
137) 	then
138) 		cd "$DOWNLOAD_DIR"
139) 		default_src="$( pwd )/roundcubemail-$newest"
140) 		src=""
141) 		while [ ! -n "$src" ]
142) 		do 
143) 			echo -n "Source de la nouvelle version [$default_src] : "
144) 			read a
145) 			if [ -n "$a" ]
146) 			then
147) 				src="$a"
148) 			else
149) 				src="$default_src"
150) 			fi
151) 			if [ ! -d "$src" ]
152) 			then
153) 				echo -n "[WARNING] Le dossier $src n'existe pas."
154) 				[ ! -n "$a" ] && default_src=""
155) 			fi
156) 		done
157) 		echo "Source : $src"
158) 
159) 		cd "$RC_HOME/../"
160) 		from=""
161) 		while [ ! -n "$from" ]
162) 		do 
163) 			echo -n "Installation source [$RC_HOME] : "
164) 			read a
165) 			if [ -n "$a" ]
166) 			then
167) 				if [ -d "$a" ]
168) 				then
169) 					from="$a"
170) 				else
171) 					echo "[ERROR] $a n'est pas un dossier valide"
172) 				fi
173) 			else
174) 				from="$RC_HOME"
175) 			fi	
176) 		done
177) 		echo "From : $from"
178) 		default_to="$( pwd )/roundcubemail-$newest"
179) 		to=""
180) 		while [ ! -n "$to" ]
181) 		do
182) 			echo -n "Destination de la nouvelle installation [$default_to] : "
183) 			read a
184) 			if [ -n "$a" ]
185) 			then
186) 				to="$a"
187) 			else
188) 				to="$default_to"
189) 			fi
190) 			if [ -d "$to" ]
191) 			then
192) 				echo -n "[WARNING] Le dossier $to existe deja. Celui-ci va etre deplace dans $to.old. Confirmez-vous votre choix [Y/n] ? "
193) 				read b
194) 				if [ "$b" == "n" -o "$b" == "N" ]
195) 				then
196) 					to=""
197) 					[ ! -n "$a" ] && default_to=""
198) 				else
199) 					echo "Deplace $to dans $to.old"
200) 					mv "$to" "$to.old"
201) 				fi
202) 			fi
203) 		done
204) 		echo "To : $to"
205) 		echo "Copie de $from dans $to"
206) 		rsync -a --copy-dirlinks "$from/" "$to/"
207) 
208) 		echo "Mise a jour de l'installation $to a partir de $src : "
209) 		for file in index.php bin/ SQL/ program/ installer/ skins/default/ plugins/
210) 		do
211) 			echo "  - Mise a jour de $file"
212) 			rsync -a --delete $src/$file $to/$file
213) 			chown $OWNER:$GROUP -R $to/$file
214) 		done
215) 
216) 		cd "$to"
217) 		if [ -x "bin/update.sh" ]
218) 		then
219) 			echo "Lancement de l'utilitaire de verification de mise a jour"
220) 			./bin/update.sh
221) 		fi
root Change order for download f...

root authored 13 years ago

222) 
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

236) 	
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

249) 		then
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

257) 		else
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

260) 		fi
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

262) 		then
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

264) 		fi
root Added upgrade feature

root authored 13 years ago

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