Skip to content

Instantly share code, notes, and snippets.

@vgrichina
Created February 13, 2010 01:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrichina/303196 to your computer and use it in GitHub Desktop.
Save vgrichina/303196 to your computer and use it in GitHub Desktop.
Script to launch appropriate Grails version for current application
#!/bin/bash
# Check if GRAILS_PREFIX is set
if [ -z $GRAILS_PREFIX ]; then
echo "You must define environment variable GRAILS_PREFIX before running Automatic Grails Version Selector"
exit 1
fi
# Define script params array
declare -a PARAMS
# Process script parameters
for PARAM in $*; do
if [ ${PARAM:0:5} == "-ver:" ]; then
# Extract version from -ver parameter
GRAILS_VERSION=${PARAM:5}
else
# Add parameter to array, so that it is passed to original script
PARAMS=( "${PARAMS[@]}" "$PARAM" )
fi
done
# If version to use is not specified, try to detect it
if [ -z $GRAILS_VERSION ]; then
# Check if application.properties file exists
if [ -e application.properties ]; then
# Get required Grails version
# Note that CR characters are removed at first
GRAILS_VERSION=`tr -d '\015' < application.properties | sed -n 's/app.grails.version=\(.*\)$/\1/p'`
else
echo "Current directory doesn't represent existing Grails project, specify version as -ver:1.3.1"
exit 1
fi
fi
# Set Grails home using configured prefix and determined version
export GRAILS_HOME=$GRAILS_PREFIX$GRAILS_VERSION
# Check if GRAILS_HOME directory exists
if [ -d $GRAILS_HOME ]; then
# Run original Grails script
$GRAILS_HOME/bin/grails ${PARAMS[@]}
else
echo Grails home directory for this project does not exist: $GRAILS_HOME
echo The current project might have updated to a newer Grails version.
echo Make sure you have downloaded and installed the version of Grails required: $GRAILS_VERSION
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment