Select Git revision
Bertrand Gauthier authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
deploy.sh 2.38 KiB
#/bin/bash
########################################################################
# Synchronise le répertoire courant avec celui spécifié en argument.
# Une simple simulation peut etre faite.
#
# Les fichiers à exclure sont listés dans un fichier à part.
########################################################################
EXCLUSIONS="--exclude /docs/* --exclude /logs/* --exclude /tests --exclude *~ --exclude .svn/ --exclude .git/"
EXCLUSIONS="$EXCLUSIONS --exclude /config/autoload/*local.php"
EXCLUSIONS="$EXCLUSIONS --exclude /temp/*"
LOG_FILE='./deploy.log'
echo "Nom du répertoire sur le serveur ? "
read appName
dev="gauthierb@dev.unicaen.fr:/var/www/$appName/"
prod="gauthierb@lgest1.unicaen.fr:/var/www/html/$appName/"
sourceDir="."
simul="o"
doit="o"
echo
echo "------------------------------------------------------------------------------------------------------"
echo "S Y N C H R O N I S A T I O N"
echo "------------------------------------------------------------------------------------------------------"
echo "Répertoire source : $sourceDir"
if [ $1 -a $1 = "nosim" ]; then
simul="n"
targetDir=$2
else
if [ $2 -a $2 = "nosim" ]; then
simul="n"
fi
targetDir=$1
fi
# répertoire cible
if [ ! $targetDir ]; then
echo "La cible (dev ou prod), svp ? "
read targetDir
fi
if [ $targetDir = "dev" ]; then
targetDir=$dev
else
if [ $targetDir = "prod" ]; then
targetDir=$prod
else
echo "Répertoire cible inconnu!"
echo "------------------------------------------------------------------------------------------------------"
echo
exit
fi
fi
echo "Répertoire cible : $targetDir"
# simulation préalable
if [ $simul = "o" ]; then
echo
echo "SIMULATION :"
echo "------------"
rsync -avzn --perms --delete $EXCLUSIONS -e ssh $sourceDir $targetDir
echo
echo -n "Procéder à la synchronisation ? (o/n) "
read doit
fi
# logging
ts=`date +%d/%m/%Y-%H:%M:%S`
echo "------------------------------------------------------------------------------------------------------" >> $LOG_FILE
echo "$ts : $0 $*" >> $LOG_FILE
# synchronisation
if [ $doit = "o" ]; then
echo
echo "SYNCHRONISATION :"
echo "-----------------"
rsync -avz --perms --delete $EXCLUSIONS -e ssh --log-file=$LOG_FILE $sourceDir $targetDir
fi
echo "------------------------------------------------------------------------------------------------------"
echo