Script for making a webapp of Carbon 3.2.0 (Beta)

I’m not a script junkie, but I thought I’d spend a bit of time and learn a bit, so that I can do something useful with scripts, i.e. go beyond just executing one or two commands with the script.

So here’s a script I wrote to create a webapp out of a WSO2 BAM product. You have to pass in your extracted distribution location tot he script. Ex: sh makeWar.sh ~/wso2/wso2bam-1.3.0-SNAPSHOT.
After running the script, make sure to follow this cool article, on how to configure and deploy it on weblogic (http://wso2.org/library/knowledge-base/2011/01/deploy-wso2-greg-360-weblogic-103). Now you can skip ahead and start from step 4 – editing the registry.xml part. The steps are more or less the same for other web apps.
Here’s the script: 
#!/bin/bash
curr_dir=${PWD}
bam_dir=${PWD}/$1
echo $bam_dir
if [ ! -d "$bam_dir" ]; then
echo "distro not found"
exit
fi
webapp_parent=wso2-webapp-resources
if [ -d "$webapp_parent" ]; then
echo "deleting $webapp_parent"
rm -rf $webapp_parent
fi
mkdir $webapp_parent
#if [ -f "$curr_dir/wso2bam.war" ]; then
# echo "deleting old war"
webapp_dir=${webapp_parent}/wso2bam_war
echo "Creating WAR"
mkdir $webapp_dir
cp $bam_dir/lib/core/WEB-INF $webapp_dir -r
cp $bam_dir/lib/api/* $webapp_dir/WEB-INF/lib
cp `find $bam_dir/lib/ -iname "*.properties"` $webapp_dir/WEB-INF/classes
cd $webapp_dir
webapp_name=wso2bam.war
zip -r $webapp_name .
mv $webapp_name $curr_dir
cd $curr_dir
rm -rf $webapp_dir
mv $webapp_name $webapp_parent
echo "War created"
cp $bam_dir/repository $webapp_parent/ -r
echo "repository copied"
sed -i -e "s/\/<\/WebContextRoot>/\/wso2bam<\/WebContextRoot>/g" $webapp_parent/repository/conf/carbon.xml
sed -i -e "s/https:\/\/\${carbon.local.ip}:\${carbon.management.port}\${carbon.context}\/services\/<\/ServerURL>/https:\/\/localhost:9444\/wso2bam\/services\/<\/ServerURL>/g" $webapp_parent/repository/conf/carbon.xml
echo "web context root and server URL changed"
grep -Rl "9763" $webapp_parent/repository/ | xargs sed -i -e "s/9763/7001/g"
grep -Rl "9443" $webapp_parent/repository/ | xargs sed -i -e "s/9443/7002/g"
echo "carbon.xml edited; Please edit registry.xml, user-mgt.xml"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s