Skip to content

Instantly share code, notes, and snippets.

@yanokwa
Created May 20, 2016 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanokwa/1585d7f79b2af06b702505f606cbd362 to your computer and use it in GitHub Desktop.
Save yanokwa/1585d7f79b2af06b702505f606cbd362 to your computer and use it in GitHub Desktop.
#!/bin/bash
# safety
set -e
# variables
HOSTNAME=$1
WAR_PATH="/var/lib/tomcat6/webapps/ROOT.war"
WAR_FOLDER_PATH="/var/lib/tomcat6/webapps/ROOT"
TIMESTAMP=$(date +%Y-%m-%dT%H:%M:%SZ)
BACKUP_WAR_PATH="/usr/local/etc/aggregate/ROOT.war.$TIMESTAMP"
ZIP_PATH=$(which zip)
UNZIP_PATH=$(which unzip)
# sanity check
if [ ! -f /etc/lsb-release ]
then
echo "No /etc/lsb-release found. Make sure you run this inside the VM!";
exit;
fi
# input check
if test $# -lt 1
then
echo "Usage: ./update-war-hostname.sh hostname";
exit;
fi
# url check
shopt -s nocasematch
if [[ $HOSTNAME =~ .*http.* ]]
then
echo "Hostname should not include http:// or https://";
exit
fi
# zip check
if [ -z "$ZIP_PATH" ]
then
echo "zip was not found. Install zip, and make sure it is on your path.";
exit;
fi
# unzip check
if [ -z "$UNZIP_PATH" ]
then
echo "unzip was not found. Install unzip, and make sure it is on your path.";
exit;
fi
# war check
if [ ! -f $WAR_PATH ]
then
echo "Aggregate war $WAR_PATH was not found."
exit;
fi
echo "Stopping Tomcat";
/etc/init.d/tomcat6 stop;
sleep 1;
echo "Cleaning up tmp folders";
cd /tmp;
if [ -d /tmp/ODKAggregate ]
then
rm -rf /tmp/ODKAggregate;
fi
if [ -d /tmp/ODKAggregate-settings ]
then
rm -rf /tmp/ODKAggregate-settings;
fi
echo "Unpacking ROOT.war";
$UNZIP_PATH -q $WAR_PATH -d /tmp/ODKAggregate;
echo "Unpacking ODKAggregate-settings.jar";
$UNZIP_PATH -q /tmp/ODKAggregate/WEB-INF/lib/ODKAggregate-settings.jar -d /tmp/ODKAggregate-settings;
echo "Changing ODKAggregate-settings.jar settings";
eval "sed -i -e 's/^security.server.hostname=.*/security.server.hostname=$HOSTNAME/g' /tmp/ODKAggregate-settings/security.properties;";
echo "Repacking ODKAggregate-settings.jar";
cd /tmp/ODKAggregate-settings;
$ZIP_PATH -q -r ../ODKAggregate/WEB-INF/lib/ODKAggregate-settings.jar .;
echo "Backing up old war and removing exploded folder";
if [ -f $WAR_PATH ]
then
mv $WAR_PATH "$BACKUP_WAR_PATH";
fi
if [ -d $WAR_FOLDER_PATH ]
then
rm -rf $WAR_FOLDER_PATH;
fi
echo "Repacking ROOT.war";
cd /tmp/ODKAggregate;
$ZIP_PATH -q -r $WAR_PATH .;
echo "Cleaning up tmp folders";
cd /tmp;
if [ -d /tmp/ODKAggregate ]
then
rm -rf /tmp/ODKAggregate;
fi
if [ -d /tmp/ODKAggregate-settings ]
then
rm -rf /tmp/ODKAggregate-settings;
fi
echo "Starting Tomcat";
/etc/init.d/tomcat6 start;
echo "----------------------------------------"
echo "New server hostname: $HOSTNAME";
echo "Old war location: $BACKUP_WAR_PATH";
@UNRECOGNIZED00
Copy link

what language will use to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment