04a82c5a725bf9e716f4f4c4957f0bf775a68300
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
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

Benjamin Renard authored 10 years ago

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

root authored 13 years ago

29) 	echo "  -h   Display this help"
30) }
31) 
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

32) while getopts ":dvhuj" opt; do
root Used getopts and added down...

root authored 13 years ago

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

root authored 13 years ago

40) 		u)
41) 			DOWNLOAD=1
42) 			UPGRADE=1
43) 			DEBUG=1
44) 			EXTRACT=1
45) 		;;
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

46) 		j)
47) 			JUST_DISP=1
48) 		;;
root Used getopts and added down...

root authored 13 years ago

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

bn8 authored 14 years ago

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

root authored 13 years ago

69) [ -f "$0.local" ] && source "$0.local" && [ $DEBUG -eq 1 ] && echo "Import local config file : $0.local"
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 Fixed after website structu...

Benjamin Renard authored 11 years ago

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

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
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

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

bn8 authored 14 years ago

115) 
Benjamin Renard Added -j parameter

Benjamin Renard authored 10 years ago

116) current=`egrep "define.*RCMAIL_VERSION" $RC_HOME/program/include/iniset.php|sed "s/define('.*', '\([^']*\)'.*$/\1/"`
117) current="`echo $current|sed 's/-rc$//'`"
118) current="`echo $current|sed 's/-beta$//'`"
119) 
120) [ $DEBUG -eq 1 ] && echo "Current : $current"
bn8 Import initial

bn8 authored 14 years ago

121) if [ "$newest" != "$current" ]
122) then
root Used getopts and added down...

root authored 13 years ago

123) 
124) 	if [ $DOWNLOAD -eq 1 ]
125) 	then
126) 		if [ -d "$DOWNLOAD_DIR" ]
127) 		then
128) 			cd "$DOWNLOAD_DIR"
root Change order for download f...

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

132) 			if [ $EXTRACT -eq 1 ]
133) 			then
134) 				[ $DEBUG -eq 1 ] && echo "Extract new release"
135) 				tar xzf $DOWNLOAD_FILE
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

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

root authored 13 years ago

141) 		fi
142) 	fi
root Change order for download f...

root authored 13 years ago

143) 
root Added upgrade feature

root authored 13 years ago

144) 	if [ $UPGRADE -eq 1 ]
145) 	then
146) 		cd "$DOWNLOAD_DIR"
Benjamin Renard Added auto-detection of dir...

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

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

Benjamin Renard authored 12 years ago

162) 				src=""
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 12 years ago

180) 					from=""
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 11 years ago

219) 		for file in index.php bin/ SQL/ program/ installer/ skins/ plugins/
root Added upgrade feature

root authored 13 years ago

220) 		do
221) 			echo "  - Mise a jour de $file"
Benjamin Renard Fix bug : preserve non-stan...

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

223) 			chown $OWNER:$GROUP -R $to/$file
224) 		done
225) 
226) 		cd "$to"
227) 		if [ -x "bin/update.sh" ]
228) 		then
229) 			echo "Lancement de l'utilitaire de verification de mise a jour"
230) 			./bin/update.sh
231) 		fi
root Change order for download f...

root authored 13 years ago

232) 
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

246) 	
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

259) 		then
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

267) 		else
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

270) 		fi
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

272) 		then
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

274) 		fi
root Added upgrade feature

root authored 13 years ago

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