#!/bin/sh RACINE_MULTIINSTANCES="/var/lib/tomcat7-multiinstances" RACINE_PATCHS="$HOME/patchs" WAR_FILE="" WEBAPP_NAME="ROOT" RELANCE_AUTO_TOMCAT=1 JUST_TEST_THE_PATCHS=0 set -e # Fonctions # fonction d'aide usage() { cat <&2 exit 1 ;; esac done shift $( expr $OPTIND - 1 ) #REPDRUPAL="$1" # Petites vérifs if [ ! -f "$WAR_FILE" ]; then echo "ERREUR: fichier '$WAR_FILE' introuvable." >&2 exit 1 fi # Vérification des patchs echo "INFO: vérification des patchs..." # on dézippe le war dans un dossier temporaire TEMP_REP=$( mktemp -d ) cd "$TEMP_REP" unzip -q "$WAR_FILE" # ... et on boucle sur chacun de patchs demandés for INSTANCE in $@; do echo "$INSTANCE" if [ ! -f $RACINE_PATCHS/$INSTANCE.diff ]; then echo "ERREUR: patch inexistant pour l'instance '$INSTANCE'." >&2 exit 1 fi if ! patch --dry-run -p1 < $RACINE_PATCHS/$INSTANCE.diff; then echo "ERREUR: patch non applicable sur instance $INSTANCE." >&2 exit 1 fi done cd / rm -rf "$TEMP_REP" # Si on se contentait de tester les patchs, on s'arrête là [ "$JUST_TEST_THE_PATCHS" -eq 1 ] && exit 0 # Déploiement echo "INFO: déploiement..." for INSTANCE in $@; do echo "$INSTANCE" # Dézippage du war dans un dossier temporaire cd "$RACINE_MULTIINSTANCES/$INSTANCE" mkdir ROOT_new cd ROOT_new unzip -q "$WAR_FILE" # Patch de la copie dézippée patch -p1 < $RACINE_PATCHS/$INSTANCE.diff # Relance de tomcat if [ "$RELANCE_AUTO_TOMCAT" -ne 0 ]; then service $INSTANCE stop sleep 3 rm -rf "../webapps/$WEBAPP_NAME" mv -i ../ROOT_new "../webapps/$WEBAPP_NAME" service $INSTANCE start else # TODO : affichage des commandes ? true fi done