Pages

Thursday, August 21, 2008

Estetica Bash

Da così...
#!/bin/bash
found_in_application_xml=$(grep ProjectName /bea/one/9/923/apps/BEdomain/BHcluster/ear/h2o/BHapp/app/META-INF/application.xml)
if [ -n "$found_in_application_xml" ]; then
echo "/bea/one/9/923/apps/BEdomain/BHcluster/ear/h2o/BHapp/app/META-INF/application.xml: OK"
else
echo "/bea/one/9/923/apps/BEdomain/BHcluster/ear/h2o/BHapp/app/META-INF/application.xml: ProjectName not found"
sed -i 's/<\/application>/<module><ejb>ejb\/ProjectName\/ejb20_BH_ProjectName_81.jar<\/ejb><\/module>\n<\/application>/' /bea/one/9/923/apps/BEdomain/BHcluster/ear/h2o/BHapp/app/META-INF/application.xml
fi
found_in_log4j=$(grep projectname /bea/one/9/923/system/BEdomain/BHcluster/log4j.properties)
if [ -n "$found_in_log4j" ]; then
echo "/bea/one/9/923/system/BEdomain/BHcluster/log4j.properties: OK"
else
echo "/bea/one/9/923/system/BEdomain/BHcluster/log4j.properties: projectname not found"
echo "
log4j.appender.PROJECTNAME=org.apache.log4j.FileAppender
log4j.appender.PROJECTNAME.File=/log/projectname.log
log4j.appender.PROJECTNAME.layout=org.apache.log4j.PatternLayout
log4j.appender.PROJECTNAME.layout.ConversionPattern=[%t] [%d{DATE}] - %c -%p: %m%n
log4j.logger.it.sella.projectname=INFO, PROJECTNAME" >> /bea/one/9/923/system/BEdomain/BHcluster/log4j.properties
fi
found_in_integrazione_sistemi_esterni_properties=$(grep ProjectName /bea/one/9/923/system/BEdomain/BHcluster/subSystem.properties)
if [ -n "$found_in_integrazione_sistemi_esterni_properties" ]; then
echo "/bea/one/9/923/system/BEdomain/BHcluster/subSystem.properties: OK"
else
echo "/bea/one/9/923/system/BEdomain/BHcluster/subSystem.properties: ProjectName not found"
echo "
#<ProjectName>
Service.SomeSystem.serviceType=ejb
Service.SomeSystem.xmlStrategy=./data/ProjectName/subsystem.xml
Service.TestSomeSystem.serviceType=ejb
Service.TestSomeSystem.xmlStrategy=./data/ProjectName/ise/ise_TestSomeSystem.xml
#</ProjectName>" >> /bea/one/9/923/system/BEdomain/BHcluster/subSystem.properties
fi
found_in_do_post_contabilizzazione_properties=$(grep projectname /bea/one/9/923/system/BEdomain/BHcluster/OtherSubSystem.properties)
if [ -n "$found_in_do_post_contabilizzazione_properties" ]; then
echo "/bea/one/9/923/system/BEdomain/BHcluster/OtherSubSystem.properties: OK"
else
echo "/bea/one/9/923/system/BEdomain/BHcluster/OtherSubSystem.properties: projectname not found"
echo "
#<ProjectName>
DEB03=it.home.projectname.lib.Class
DEB05=it.home.projectname.lib.Class
#</ProjectName>
" >> /bea/one/9/923/system/BEdomain/BHcluster/OtherSubSystem.properties
fi


a così:
#!/bin/bash
PROJECTNAME="ProjectName"
BEADIR="/bea/one/9/923"

BH_JAR_NAME="ejb20_BH_${PROJECTNAME}_81.jar"
MODULEPATH="ejb/$PROJECTNAME/"

APPLICATION_XML="${BEADIR}/apps/BEdomain/BHcluster/ear/h2o/BHapp/app/META-INF/application.xml"

LOG4JFILE="${BEADIR}/system/BEdomain/BHcluster/log4j.properties"
DOPOSTFILE="${BEADIR}/system/BEdomain/BHcluster/OtherSubSystem.properties"
ISEFILE="${BEADIR}/system/BEdomain/BHcluster/subSystem.properties"



function searchIn() {
FILE="$1"
SUBSTRING="$2"
GREPOPTS="$3 $4 $5 $6 $7 $8 $9"
grep -q $GREPOPTS $SUBSTRING $FILE
return
}

function stringForSed() {
echo "${1//\//\\/}"
}

function addEjbModuleToXml() {
MODULE=$1
XMLFILE=$2
APPLICATION_TAG="</application>"
EJB_TAG="<module><ejb>$MODULE</ejb></module>"
sed -i "s/$(stringForSed $APPLICATION_TAG)/$(stringForSed $EJB_TAG)\n$(stringForSed $APPLICATION_TAG)/g" $XMLFILE
}

function log4j_properties() {
FILENAME="$1"
cat >>"$FILE" <<EOF
log4j.appender.PROJECTNAME=org.apache.log4j.FileAppender
log4j.appender.PROJECTNAME.File=/log/projectname.log
log4j.appender.PROJECTNAME.layout=org.apache.log4j.PatternLayout
log4j.appender.PROJECTNAME.layout.ConversionPattern=[%t] [%d{DATE}] - %c -%p: %m%n
log4j.logger.it.sella.projectname=INFO, PROJECTNAME
EOF
}

function subSystem_properties() {
FILENAME="$1"
cat >>"$FILE" <<EOF
#<ProjectName>
Service.SomeSystem.serviceType=ejb
Service.SomeSystem.xmlStrategy=./data/ProjectName/subsystem.xml
Service.TestSomeSystem.serviceType=ejb
Service.TestSomeSystem.xmlStrategy=./data/ProjectName/ise/ise_TestSomeSystem.xml
#</ProjectName>
EOF
}

function OtherSubSystem_properties {
FILENAME="$1"
cat >>"$FILE" <<EOF
#<ProjectName>
DEB03=it.home.projectname.lib.Class
DEB05=it.home.projectname.lib.Class
#</ProjectName>
EOF
}


if ! searchIn "$APPLICATION_XML" "$BH_JAR_NAME"; then
echo "Adding $BH_JAR_NAME in $APPLICATION_XML"
addEjbModuleToXml "$MODULEPATH/$BH_JAR_NAME" $APPLICATION_XML
fi


for FILE in $LOG4JFILE $DOPOSTFILE $ISEFILE; do
if ! searchIn "$FILE" $PROJECTNAME "-i"; then
appenderName="$(basename "$FILE")"
echo "Updating $FILE..."
${appenderName//./_} "$FILE"
fi
done

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.