Added upgrade feature

This commit is contained in:
root 2011-02-10 13:16:06 +01:00
parent bfdb18d89c
commit 59a095860a

View file

@ -12,17 +12,22 @@ SLEEP_ON_FAILED=10
CHECK_URL=http://www.roundcube.net/download
DOWNLOAD=0
DOWNLOAD_DIR=$RC_HOME/../upstream
OWNER=root
GROUP=www-data
DEBUG=0
UPGRADE=0
EXTRACT=0
function usage() {
echo "Usage : $0 [-v] [-d]"
echo "Usage : $0 [-v] [-d] [-u]"
echo " -v Verbose mode"
echo " -d Download new release"
echo " -u Upgrade installation"
echo " -h Display this help"
}
while getopts ":dvh" opt; do
while getopts ":dvhu" opt; do
case $opt in
v)
DEBUG=1
@ -30,6 +35,12 @@ while getopts ":dvh" opt; do
d)
DOWNLOAD=1
;;
u)
DOWNLOAD=1
UPGRADE=1
DEBUG=1
EXTRACT=1
;;
h)
usage
exit 0
@ -110,53 +121,162 @@ then
cd "$DOWNLOAD_DIR"
DOWNLOAD_FILE="$( pwd )/roundcubemail-$newest.tar.gz"
[ $DEBUG -eq 1 ] && echo "Download new release in $DOWNLOAD_FILE"
wget -q -O "$DOWNLOAD_FILE" "$DOWNLOAD_URL"
#wget -q -O "$DOWNLOAD_FILE" "$DOWNLOAD_URL"
if [ $EXTRACT -eq 1 ]
then
[ $DEBUG -eq 1 ] && echo "Extract new release"
tar xzf $DOWNLOAD_FILE
fi
else
echo "[WARNING] Le dossier de telechargement n'existe pas ($DOWNLOAD_DIR)."
[ $UPGRADE -eq 1 ] && exit 1
fi
fi
tmp=`mktemp`
echo "New RoundCude release" > $tmp
echo "=====================" >> $tmp
echo "Current : $current" >> $tmp
echo "Newest : $newest" >> $tmp
echo >> $tmp
echo "Download URL : $DOWNLOAD_URL" >> $tmp
[ -n "$DOWNLOAD_FILE" -a -f "$DOWNLOAD_FILE" ] && echo "Download file : $( pwd )/roundcubemail-$newest.tar.gz" >> $tmp
if [ $UPGRADE -eq 1 ]
then
cd "$DOWNLOAD_DIR"
default_src="$( pwd )/roundcubemail-$newest"
src=""
while [ ! -n "$src" ]
do
echo -n "Source de la nouvelle version [$default_src] : "
read a
if [ -n "$a" ]
then
src="$a"
else
src="$default_src"
fi
if [ ! -d "$src" ]
then
echo -n "[WARNING] Le dossier $src n'existe pas."
[ ! -n "$a" ] && default_src=""
fi
done
echo "Source : $src"
cd "$RC_HOME/../"
from=""
while [ ! -n "$from" ]
do
echo -n "Installation source [$RC_HOME] : "
read a
if [ -n "$a" ]
then
if [ -d "$a" ]
then
from="$a"
else
echo "[ERROR] $a n'est pas un dossier valide"
fi
else
from="$RC_HOME"
fi
done
echo "From : $from"
default_to="$( pwd )/roundcubemail-$newest"
to=""
while [ ! -n "$to" ]
do
echo -n "Destination de la nouvelle installation [$default_to] : "
read a
if [ -n "$a" ]
then
to="$a"
else
to="$default_to"
fi
if [ -d "$to" ]
then
echo -n "[WARNING] Le dossier $to existe deja. Celui-ci va etre deplace dans $to.old. Confirmez-vous votre choix [Y/n] ? "
read b
if [ "$b" == "n" -o "$b" == "N" ]
then
to=""
[ ! -n "$a" ] && default_to=""
else
echo "Deplace $to dans $to.old"
mv "$to" "$to.old"
fi
fi
done
echo "To : $to"
echo "Copie de $from dans $to"
rsync -a --copy-dirlinks "$from/" "$to/"
echo "Mise a jour de l'installation $to a partir de $src : "
for file in index.php bin/ SQL/ program/ installer/ skins/default/ plugins/
do
echo " - Mise a jour de $file"
rsync -a --delete $src/$file $to/$file
chown $OWNER:$GROUP -R $to/$file
done
cd "$to"
if [ -x "bin/update.sh" ]
then
echo "Lancement de l'utilitaire de verification de mise a jour"
./bin/update.sh
fi
if [ -L "$RC_HOME" ]
then
echo -n "Voulez-vous faire pointer le lien symbolique $RC_HOME vers cette nouvelle installation [Y/n] ? "
read a
if [ "$a" != "n" -a "$a" != "N" ]
then
echo " - Suppression de l'actuel lien $RC_HOME"
rm -f $RC_HOME
echo " - Creation du nouveau lien $RC_HOME vers $to"
ln -s "$to" "$RC_HOME"
fi
fi
else
M=0
if [ -f $CACHE ]
then
if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
tmp=`mktemp`
echo "New RoundCude release" > $tmp
echo "=====================" >> $tmp
echo "Current : $current" >> $tmp
echo "Newest : $newest" >> $tmp
echo >> $tmp
echo "Download URL : $DOWNLOAD_URL" >> $tmp
[ -n "$DOWNLOAD_FILE" -a -f "$DOWNLOAD_FILE" ] && echo "Download file : $( pwd )/roundcubemail-$newest.tar.gz" >> $tmp
M=0
if [ -f $CACHE ]
then
[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
then
[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
M=1
else
[ $DEBUG -eq 1 ] && echo "Pas de modif et cache trop recent : pas d'envoi"
fi
else
[ $DEBUG -eq 1 ] && echo "Pas encore de cache => On envoi"
M=1
else
[ $DEBUG -eq 1 ] && echo "Pas de modif et cache trop recent : pas d'envoi"
fi
else
[ $DEBUG -eq 1 ] && echo "Pas encore de cache => On envoi"
M=1
fi
if [ $DEBUG -eq 1 -a $M -eq 1 ]
then
echo "Mode debug : Pas d'envoi de mail"
fi
if [ $M -eq 1 -a $DEBUG -ne 1 ]
then
cat $tmp > $CACHE
if [ -n "$NAME" ]
if [ $DEBUG -eq 1 -a $M -eq 1 ]
then
S="[$NAME] New RoundCude release"
else
S="New RoundCude release"
echo "Mode debug : Pas d'envoi de mail"
fi
cat $tmp | mail -s "$S : $newest" $MAIL
[ $DEBUG -eq 1 ] && echo "Mail envoyé"
if [ $M -eq 1 -a $DEBUG -ne 1 ]
then
cat $tmp > $CACHE
if [ -n "$NAME" ]
then
S="[$NAME] New RoundCude release"
else
S="New RoundCude release"
fi
cat $tmp | mail -s "$S : $newest" $MAIL
[ $DEBUG -eq 1 ] && echo "Mail envoyé"
fi
rm -f $tmp
fi
rm -f $tmp
else
[ $DEBUG -eq 1 ] && echo "Pas de changement de version"
fi