3a840fb501a6f3a1360491b07c0ee8b32e82c4d6
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."
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

154) 				src=""
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 12 years ago

172) 					from=""
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 12 years ago

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

root authored 13 years ago

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

root authored 13 years ago

224) 
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

238) 	
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

251) 		then
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

259) 		else
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

262) 		fi
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

264) 		then
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

266) 		fi
root Added upgrade feature

root authored 13 years ago

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