Skip to content

Instantly share code, notes, and snippets.

@deluan
Created October 31, 2010 03:06
Show Gist options
  • Save deluan/656064 to your computer and use it in GitHub Desktop.
Save deluan/656064 to your computer and use it in GitHub Desktop.
Script for selecting and calling the correct Griffon version when you have more than one version installed
#!/bin/sh
# Author: Deluan (http://techbeats.deluan.com)
# Check if GRIFFON_HOME is set
if [ -z "$GRIFFON_HOME" -o ! -d "$GRIFFON_HOME" ]; then
echo "Error: GRIFFON_HOME not set"
exit 2
fi
# Extract the default version and base path from GRIFFON_HOME
DEFAULT_VERSION=`basename $GRIFFON_HOME | cut -f 2 -d "-"`
BASE_GRIFFON_PATH=`dirname $GRIFFON_HOME`
APP_PROP="application.properties"
# Try to get the version from the command line
TRY_VERSION=$1
if [ -d "${BASE_GRIFFON_PATH}/griffon-${TRY_VERSION}" ]; then
VERSION=$TRY_VERSION
shift
fi
# Or else get the version from the application.properties in the current directory
[ -z "$VERSION" -a -f "$APP_PROP" ] &&
VERSION=`awk -F'=' '/app.griffon.version/ { print $2 }' $APP_PROP | tr -d '\r\n'`
# Or else use the default version
[ -z "$VERSION" ] &&
VERSION=$DEFAULT_VERSION
export GRIFFON_HOME=${BASE_GRIFFON_PATH}/griffon-${VERSION}
GRIFFON_CMD=${GRIFFON_HOME}/bin/griffon
if [ ! -x "$GRIFFON_CMD" ]; then
echo "Error: griffon command not found at '$GRIFFON_CMD'!"
exit 3
fi
exec $GRIFFON_CMD $*
@deluan
Copy link
Author

deluan commented Oct 31, 2010

Prerequisites

  • All your Griffon versions must be installed under the same base directory. Ex:

    /opt/griffon-0.3.1
    /opt/griffon-0.9
    /opt/griffon-0.9.1a
    
  • GRIFFON_HOME environment variable must be set and point to your "default" Griffon installation

  • This script was tested on Mac OS X (Snow Leopard), Linux (Ubuntu) and Windows (with cygwin)

Installation

Usage

Using the script is as transparent as possible:

  • If you invoke it from a project folder, it will detect the version used by the project and call the correct griffon (if it is installed in your system)

  • If you invoke it from any other folder that does not contain a Griffon project, it will call the "default" Griffon installation

  • If you want to call a specific Griffon version (i.e. when doing an upgrade) you can specify the version you want in the first parameter. Ex:

    $ griffon 0.9.1a upgrade
    

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