#!/bin/sh

PRODUCT_NAME="Linaro Forge"

# Don't wipe LD_PRELOAD if script was launched under squish
[ -z "$SQUISH_PATH" ] && LD_PRELOAD=

# First find FORGE_TOOLS_PATH. Don't set this is in your environment - this script will
# find it.

# Follow symlinks to get the canonical path of this script (in case we're symlinked outside the install directory).
if type readlink >/dev/null 2>&1; then
	CANONICAL_EXE="`readlink -f "$0"`"
else
	CANONICAL_EXE="$0"
fi

# Set FORGE_TOOLS_PATH to the parent of this script's directory.
FORGE_TOOLS_PATH="$(cd "$(dirname "$CANONICAL_EXE")/.."; pwd)"
. "$FORGE_TOOLS_PATH/libexec/common"

for var in "$@"; do
    if [ ! "${var##--offline=}" = "$var" ]
    then
        FORGE_OFFLINE_LAUNCHER_USE=on
        continue
    fi
    if [ ! "${var##-offline=}" = "$var" ]
    then
        FORGE_OFFLINE_LAUNCHER_USE=on
        continue
    fi
    if [ ! "${var##--profile=}" = "$var" ]
    then
        FORGE_OFFLINE_LAUNCHER_USE=on
        continue
    fi
    if [ ! "${var##-profile=}" = "$var" ]
    then
        FORGE_OFFLINE_LAUNCHER_USE=on
        continue
    fi
    case "$var" in
        "-offline" | "--offline")
            FORGE_OFFLINE_LAUNCHER_USE=on
            ;;
        "-profile" | "--profile")
            FORGE_OFFLINE_LAUNCHER_USE=on
            ;;
        "--" | "---") #19544
            break
            ;;
    esac
done

if [ "$FORGE_OFFLINE_LAUNCHER_USE" = "on" ]; then
    echo "To debug or profile a program from the command line use the ddt or map commands." >&2
    exit 1
else
    exec $SSH_AGENT "$FORGE_TOOLS_PATH/libexec/forge.bin" "$@"
fi
