23765ce7c8ff553d712771598d2dd7ab6b2cad12
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
Benjamin Renard Upgrade script to use bin/i...

Benjamin Renard authored 10 years ago

165) 			if [ ! -x "$src/bin/installto.sh" ]
166) 			then
167) 				echo -n "[WARNING] Le script bin/installto.sh n'est pas présent dans ce répertoire source."
168) 				src=""
169) 				[ ! -n "$a" ] && default_src=""
170) 			fi
root Added upgrade feature

root authored 13 years ago

171) 		done
172) 		echo "Source : $src"
173) 
174) 		cd "$RC_HOME/../"
175) 		from=""
176) 		while [ ! -n "$from" ]
177) 		do 
178) 			echo -n "Installation source [$RC_HOME] : "
179) 			read a
180) 			if [ -n "$a" ]
181) 			then
182) 				if [ -d "$a" ]
183) 				then
184) 					from="$a"
185) 				else
Benjamin Renard Fixed bug when asking for s...

Benjamin Renard authored 12 years ago

186) 					from=""
root Added upgrade feature

root authored 13 years ago

187) 					echo "[ERROR] $a n'est pas un dossier valide"
188) 				fi
189) 			else
190) 				from="$RC_HOME"
191) 			fi	
192) 		done
193) 		echo "From : $from"
194) 		default_to="$( pwd )/roundcubemail-$newest"
195) 		to=""
196) 		while [ ! -n "$to" ]
197) 		do
198) 			echo -n "Destination de la nouvelle installation [$default_to] : "
199) 			read a
200) 			if [ -n "$a" ]
201) 			then
202) 				to="$a"
203) 			else
204) 				to="$default_to"
205) 			fi
206) 			if [ -d "$to" ]
207) 			then
208) 				echo -n "[WARNING] Le dossier $to existe deja. Celui-ci va etre deplace dans $to.old. Confirmez-vous votre choix [Y/n] ? "
209) 				read b
210) 				if [ "$b" == "n" -o "$b" == "N" ]
211) 				then
212) 					to=""
213) 					[ ! -n "$a" ] && default_to=""
214) 				else
215) 					echo "Deplace $to dans $to.old"
216) 					mv "$to" "$to.old"
217) 				fi
218) 			fi
219) 		done
220) 		echo "To : $to"
221) 		echo "Copie de $from dans $to"
222) 		rsync -a --copy-dirlinks "$from/" "$to/"
223) 
224) 		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

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

root authored 13 years ago

227) 
Benjamin Renard Add after_upgrade() functio...

Benjamin Renard authored 10 years ago

228) 		type after_upgrade > /dev/null 2>&1
229) 		if [ $? -eq 0 ]
230) 		then
231) 			echo "Execution de la fonction custom after_upgrade() :"
232) 			after_upgrade
233) 			echo "Fin de la fonction after_upgrade()"
234) 		fi
235) 
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

249) 	
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

262) 		then
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

270) 		else
root Added upgrade feature

root authored 13 years ago

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

bn8 authored 14 years ago

273) 		fi
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

275) 		then
root Added upgrade feature

root authored 13 years ago

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

Benjamin Renard authored 13 years ago

277) 		fi
root Added upgrade feature

root authored 13 years ago

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