Author: tchemit Date: 2014-04-05 13:51:28 +0200 (Sat, 05 Apr 2014) New Revision: 59 Url: http://forge.codelutin.com/projects/adminsys/repository/revisions/59 Log: add update-tomcat-7 script Added: scripts/redmine-tools/update-tomcat-7.sh Copied: scripts/redmine-tools/update-tomcat-7.sh (from rev 58, forge-tools/sys/check-get-tomcat.sh) =================================================================== --- scripts/redmine-tools/update-tomcat-7.sh (rev 0) +++ scripts/redmine-tools/update-tomcat-7.sh 2014-04-05 11:51:28 UTC (rev 59) @@ -0,0 +1,89 @@ +#!/bin/sh + +# +# USAGE: check-get-tomcat.sh [debug] +# +# verifie s'il y a ou non une nouvelle version tomcat par rapport a celle installee +# si c'est le cas: +# - telecharge le fichier +# - le decompresse +# - le met en place pour les diffentes instances souhaite +# - affiche le chemin des nouvelles instances mise en place si besoin +# +# l'administrateur devra alors redemarrer les tomcat des forges +# - service tomcat-7 restart +# + +DEBUG=false +MIRROR=http://mirrors.linsrv.net/apache/tomcat +TARGET_DIR=/opt/repository +LINK_DIR=/opt + +if [ "$1" = "debug" ]; then + export DEBUG=true +fi + +debug () { + if [ "$DEBUG" = "true" ]; then + echo "$1" + fi +} + +getFileURL () { + local RELEASE=$2 + local VERSION=${2%%.*} + local result="$MIRROR/tomcat-$VERSION/v$RELEASE/bin/apache-tomcat-$RELEASE.tar.gz" + debug "getFileURL: $result" + eval $1=\$result +} + +# get the last release for specified tomcat version +# @param $1 returned value +# @param $2 tomcat version 6, 7 or 8 +getLastRelease () { + local VERSION=$2 + local result=$(curl -s http://mirrors.linsrv.net/apache/tomcat/tomcat-$VERSION/ |grep "href=.v" |sed -re 's/.*>v([0-9]+.[0-9]+.[0-9]+).*/\1/') + debug "getLastRelease: $result" + eval $1=\$result +} + +getCurrentRelease () { + local VERSION=$2 + local LINK=$(readlink $LINK_DIR/apache-tomcat-$VERSION) + local DIR=$(basename $LINK) + local result=${DIR##*-} + debug "getCurrentRelease: $result" + eval $1="$result" +} + +installRelease () { + local OLD_RELEASE=$1 + local RELEASE=$2 + local VERSION=${RELEASE%%.*} + local URL + getFileURL URL $RELEASE + mkdir -p $TARGET_DIR + curl -s "$URL" | tar --no-same-owner -C "$TARGET_DIR" -xz + local DIR=$(basename $URL .tar.gz) + local UNPACK_DIR=$TARGET_DIR/$DIR + local UNPACK_OLD_DIR=$TARGET_DIR/apache-tomcat-$OLD_RELEASE + cp $UNPACK_OLD_DIR/webapps/*.war $UNPACK_DIR/webapps + local LINK=$LINK_DIR/${DIR%%.*} + sed -i 's/<Connector /<Connector URIEncoding="UTF-8" /g' $UNPACK_DIR/conf/server.xml + rm -f $LINK + ln -s $UNPACK_DIR $LINK + echo "new release installed in $LINK -> $UNPACK_DIR" +} + +update () { + local VERSION=$1 + local CURRENT_RELEASE + local LAST_RELEASE + getCurrentRelease CURRENT_RELEASE $VERSION + getLastRelease LAST_RELEASE $VERSION + if [ "$CURRENT_RELEASE" != "$LAST_RELEASE" ]; then + installRelease $CURRENT_RELEASE $LAST_RELEASE + fi +} + +update 7