#!/bin/bash

usage() {
    echo ""
    echo "Run as: $0 <32|64>"
    echo "e.g."
    echo "   $0      - runs this script for 64 bit (default)"
    echo "   $0 32   - runs this script for 32 bit"
    echo "   $0 <anything else> to see this message again" 
    echo ""
    exit
}

if [ -z "$1" ]; then
    bit=`getconf LONG_BIT`
elif [ "$1" == "32" ] || [ "$1" == "64" ] ; then
    bit=$1
else
    usage
fi

# Doing $(dirname "$0") can be unreliable if the script was launched relatively
# Get absolute path to dir containing $0 this way, per Gemini:
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
#echo "### SCRIPT DIR: $SCRIPT_DIR"
# Need to CD into gs-release-builder: the directory that the update-builder.sh lives in
# /Users/greenstone/gs-release-builder on darwin, cd /greenstone/gs-release-builder on linux
pushd $SCRIPT_DIR
echo "Now in the folder from which this script is run: $SCRIPT_DIR"
echo "@@@ $0: Updating release-kits"
svn up release-kits
echo "@@@ $0: Updating cli tools"
pushd ext-cli
svn up .
# pass whatever args or at least bitness to the gs-core-cli-tools script
if [ -z "$1" ] ; then
    ./get-gs-core-cli-tools.sh $bit
else
    ./get-gs-core-cli-tools.sh $*
fi
popd
popd

echo ""
echo "Done running $0"
echo ""
