All pastes #78282 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-07-03 23:54 UTC
rendered paste body
#!/bin/sh
#################################################################################################
#
# LAXUNIX.SH - LaunchAnywhere (tm) version 7.0
#
# (c) Copyright 1999-2005 Zero G Software, Inc., all rights reserved.
#
#  To run this script you will need to have the following:
#       1) a Java VM installed (however, it will handle a lack of Java nicely).
#       2) a Java-style properties file having the same name as this script
#               with the suffix .lax.  If this script is appended to the
#               self-extractor, it will look for the properties file in the
#               directory specified by $seLaxPath; otherwise, it will look in
#               the same directory that this script is in.
#       3) a Java program in the file "lax.jar".
#
#  The .lax property file must contain at least the following properties:
#       1)  lax.class.path  classpath (do not include the environment variable $CLASSPATH )
#       2)  lax.nl.java.launcher.main.class  (main class of LaunchAnywhere Executable)
#
#################################################################################################

#
# Since USERENV is already set in the self-extractor, if its not set we know
# this is not an installer but a separate launcher.
# USERENV is just a flag passed from use.sh.
#
IS_INSTALLER=''
[ $USERENV ] && IS_INSTALLER=true

#
# later on we might add things to the PATH, but we want to preserve the PATH
# order for which VMs are the first ones found.
#
VM_SEARCH_PATH="$PATH"

####################################################################################
# Set some constants
if [ "$1" = "LAX_VM" ]; then
        lax_vm="LAX_VM"
        lax_vm_value="$2"
        shift 2
else
        lax_vm=""
fi
anyVMlist="JDK_J2 D12 JRE_J2 R12 JDK_J1 JRE_J1 JDK JRE ALL"


####################################################################################
# Format commandline args
# To overcome the problem of quoted args (with internal spaces) to the launcher
# is that they get "unquoted" or separated into discreet args when they are put
# on the cmdline for the application.  This following block makes  sure the stay intact
overrideDefaultUIMode="false"
ignoreMode="false";
uimode="not set"
hasSeenI="false"
tmpArgs=""
origArgs=$@
for arg in "$@"
do
        if [ "$arg" != "" ]; then
                tmpArgs="$tmpArgs \"$arg\""
                if [ "$arg" = "-i" -o "$arg" = "-I" ]; then
                        hasSeenI="true"
                elif [ "$hasSeenI" = "true" ]; then
                        lowerArg=`echo $arg | tr "[:upper:]" "[:lower:]"`
                        if [ "$lowerArg" = "awt" ]; then
                                uimode="awt"
                                overrideDefaultUIMode="true"
                        elif [ "$lowerArg" = "swing" ]; then
                                uimode="swing"
                                overrideDefaultUIMode="true"
                        elif [ "$lowerArg" = "gui" ]; then
                                uimode="gui"
                                overrideDefaultUIMode="true"
                        elif [ "$lowerArg" = "console" ]; then
                                uimode="console"
                                overrideDefaultUIMode="true"
                        elif [ "$lowerArg" = "text" ]; then
                                uimode="console"
                                overrideDefaultUIMode="true"
                        elif [ "$lowerArg" = "silent" ]; then
                                uimode="silent"
                                overrideDefaultUIMode="true"
                        else
                                ignoreMode="true"
                        fi
                fi
        fi
done
cmdLineArgs="$tmpArgs"
thisScript="$0"
# make sure thisScript is an abs path
case $thisScript in
        /*)
        ;;
        *)
                thisScript="`pwd`/$thisScript"
        ;;
esac

####################################################################################
#
# WHere does the LAX_DEBUG output go?
#

if [ "$LAX_DEBUG" = "file" ]; then
        jx_log="`pwd`/jx.log"
        rm -f "$jx_log"
        touch "$jx_log"
        if [ "$?" -gt "0" ]; then
                jx_log_ok="false"
                echo "Could not create $jx_log.  Sending debug output to console."
        else
                jx_log_ok="true"
        fi
fi

debugOut()
{
        case "$LAX_DEBUG" in
                "file" )
                        if [ "$jx_log_ok" = "true" ]; then
                                echo "$1" >> "$jx_log"
                        else
                                echo "$1"
                        fi
                ;;
                ""     )
                        echo "$1" >> /dev/null
                ;;
                *      )
                        echo "$1"
                ;;
        esac
}

####################################################################################
#
# UNIX ENVIRONMENT configuration
#
debugOut ""
debugOut "========= Analyzing UNIX Environment ================================="


# Get os type , note that it is LOWER-CASED.  Used here and later on
osName=`uname -s 2> /dev/null | tr "[:upper:]" "[:lower:]" 2> /dev/null`
debugOut "Setting UNIX ($osName) flavor specifics."
vmScript=".java_wrapper"
case "$osName" in
        *irix*)
                cpuName="unknown"
        ;;
        *hp-ux*|*hpux*)
                cpuName=`uname -m 2> /dev/null`
        ;;
        *solaris*|*sunos*)
                cpuName=`uname -p 2> /dev/null`
                THREADS_FLAG="";        export THREADS_FLAG
                PATH=/usr/bin:$PATH;    export PATH
        ;;
        *aix*)
                cpuName="unknown"
        ;;
        *freebsd*)
                cpuName=`uname -p 2> /dev/null`
        ;;
        *linux*)
                cpuName=`uname -m 2> /dev/null`
        ;;
        # tlb 2001-09-18 updating to support Darwin
        *rhapsody*|*darwin*)
                cpuName=`uname -p 2> /dev/null`
                vmScript=".java_command"
        ;;
        *compaq*|*dg*|*osf*)
                cpuName="unknown"
        ;;
        *)
                cpuName="unknown"
        ;;
esac


if [ -x /bin/ls ]; then
        lsCMD="/bin/ls"
elif [ -x /usr/bin/ls ]; then
        lsCMD="/usr/bin/ls"
else
        lsCMD="ls"
fi

debugOut "Importing UNIX environment into LAX properties."

####################################################################################
#
# CREATE ENV.PROPERTIES and figure out if this is being exec'd from an installer
#
# We need POSIX awk. On some systems it's called awk, on others
# nawk. It's most frequently called nawk, so start with that.
#
debugOut "Checking for POSIX awk."
AWK=nawk
( $AWK '{}' ) < /dev/null 2>&0 || AWK=awk

if [ -z "$IATEMPDIR" ]; then
        TMPDIR=/tmp
else
        TMPDIR=$IATEMPDIR
fi


if [ -z "$envPropertiesFile" ]
then
        if [ -d $TMPDIR ]
        then
                envPropertiesFile=$TMPDIR/env.properties.$$
        else
                envPropertiesFile="$HOME/env.properties.$$"
        fi
fi

#
# Convert environment variables to LAX properties. The variables
# are also named with alternate case (all upper, all lower).
#
# E.g.
#     export My_Env_Var="abc
#     def"
#
# is converted to:
#     lax.nl.env.exact_case.My_Env_Var=abc def
#     lax.nl.env.MY_ENV_VAR=abc def
#     lax.nl.env.my_env_var=abc def
#
# The second gsub() is used to escape backslashes so that when the properties
# file is read by the java.util.Properties object, there is not a problem
# with incorrectly interpreted escaped unicode.
#
# This code segment is written in POSIX awk for performance reasons.
#

$AWK -v LAX_PREFIX=lax.nl.env. '
END {
        for (var in ENVIRON)
        {
                # get variable value
                value = ENVIRON[var]

                # strip newlines
                gsub(/\n/, " ", value)

                # convert one backslash to two
                gsub(/\\/, "\\\\", value)

                # print as LAX property
                print LAX_PREFIX "exact_case." var "=" value
                print LAX_PREFIX tolower(var) "=" value
                print LAX_PREFIX toupper(var) "=" value
        }
}' < /dev/null > $envPropertiesFile



####################################################################################
#
# Tracing symbolic links to actual launcher location
#

resolveLink()
{
        rl_linked="true"
        rl_operand="$1"
        rl_origDir="`dirname "$1"`"

        # bypass the whole thing if this isnt a link
        rl_ls=`$lsCMD -l "$rl_operand"`
        case "$rl_ls" in
                *"->"*)
                ;;
                *)
                        resolvedLink="$rl_operand"
                        return
                ;;
        esac

        while [ "$rl_linked" = "true" ]; do
                # if the operand is not of an abs path, get its abs path
                case "$rl_operand" in
                        /*)
                                rl_origDir=`dirname "$rl_operand"`
                        ;;
                        \./*)
                                rl_origDir=`pwd`
                                rl_operand="$rl_origDir/$rl_operand"
                        ;;
                        *)
                                rl_operand="$rl_origDir/$rl_operand"
                        ;;
                esac
                #
                # the prevPrev hack is here because .../java often points to .java_wrapper.
                # at the end of the resolution rl_operand actually points to garbage
                # signifying it is done resolving the link.  So prev is actually .java_wrapper.
                # but we want the one just before that, its the real vm starting poiint we want
                #
                rl_prevOperand="$rl_operand"
                rl_ls=`$lsCMD -l "$rl_operand"`
                # get the output ls into a list
                set x $rl_ls
                # get rid of x and file info from ls -l
                shift 9

                #is this a link?
                case "$rl_ls" in
                        *"->"*)
                                rl_linked="true"
                                # is a link, shift past the "->"
                                rl_linker=""
                                while [ "$1" != "->" -a $# -gt 1 ]; do
                                        rl_linker="$rl_linker $1"
                                        shift
                                done

                                if [ "$1" = "->" ]; then
                                        shift
                                fi
                        ;;
                        *)
                                # not a link, the rest must be the targets name
                                rl_linked="false"
                        ;;
                esac
                # now grab what's left
                rl_linkee="$*"

                # debugOut "Following link to LAX $rl_linker -> $rl_linkee"
                if [ "$rl_linked" = "true" -a "`basename "$rl_linkee"`" != "$vmScript" ]; then
                        # set to true incase the thing linked to is also a link and we can
                        # try again.  The current think linked to now becomes the operand
                        rl_operand="$rl_linkee"
                        # if the linkee is not abs, make it abs relative to the linker
                        case "$rl_operand" in
                                /*)
                                ;;
                                *)
                                        rl_operand="$rl_origDir/$rl_operand"
                                ;;
                        esac
                else
                        # otherwise, this operand is not a link itself and we are done
                        rl_resolvedLink="$rl_prevOperand"
                        # however, do not resolve the last leg of a VMs linked scripts. this will
                        # disrupt their scripts.  it is expecting a link to the .java* script
                        # let us believe it is not linked and continue on...
                        if [ "`basename "$rl_linkee"`" = "$vmScript" ]; then
                                rl_linked="false"
                        fi
                fi
                # make sure the path returned is absolute
                case "$rl_operand" in
                        \.\/*)
                                rl_operand="`pwd`/$rl_operand"
                        ;;
                esac
        done

        # remove "/./" in paths, make it "/"
        # i,e,  "/a/b/./c" becomes "/a/b/c"
        resolvedLink=`echo "$rl_resolvedLink" |  sed 's,/\./,/,'`
####################################################################################
#
#  FINDING THE LAX FILE
#
# If this is an installer, use $seLaxPath
#
debugOut ""
debugOut "========= Analyzing LAX =============================================="
olddir=`pwd`
resolveLink "$thisScript"
absLauncherName="$resolvedLink"
cd "`dirname "$absLauncherName"`"
if [ "$IS_INSTALLER" != "" ]; then
        if [ ! -z "$seLaxPath" ]; then
                propfname="$seLaxPath"
        else
                # legacy for old self-extractors
                propfname="$templaxpath"
        fi
else
        propfname="$absLauncherName.lax"
fi


if [ ! -r "$propfname" ]; then
        debugOut "The file "$propfname" could"
        debugOut "not be found, and the program cannot be run without it."
        debugOut "Try reinstalling the program."
        exit;
else
        debugOut "LAX found............................ OK."
fi
####################################################################################
#
# READING THE LAX FILE
#
OFS="$IFS"
# run prop file through sed calls that do:
# 1. transform first '=' on a line into a control-O
# 2. transform all other ='s to control-F
# 3. transform control-Os back to =
# this is to differentiate the lhs=rhs processing from confusing the first = from other
# = that might be part of the value.  Later on those =-tranformed-to-control-Fs are
# transformed back to = signs.
set x `cat "$propfname" | sed -e 's~^\([^\=]*\)\=\(.*\)~\1\\2~g' -e 's~=~~g' -e 's~~=~g' | grep '='`; shift

while test $# -gt 0; do
        # line separator
        case "x${1}x" in
                *"="* ) BIFS=" "; ;;
                *     ) BIFS="" ; ;;
        esac
        # word separator
        case "x${2}x" in
                *"="* ) AIFS=""; ;;
                *     ) AIFS=""; ;;
        esac
        INPUT="$INPUT$BIFS$1$AIFS"
        shift
done

while test "x$INPUT" != "x"; do
        set x $INPUT; shift
        X="$1"
        shift
        INPUT="$@"
        IFS="=$AIFS"
        set x $X; shift
        IFS="$OFS"

        lhs="${1}"
        shift
        rhs="$@"

        # transform non lhs=rhs delimiting = signs back from ^F to =
        case "$rhs" in
                **)
                rhs=`echo $rhs | sed 's~~=~g'`
                ;;
        esac

        # assing the values
        case $lhs in
                lax.class.path*)
                        lax_class_path="$rhs"
                ;;
                lax.main.class*)
                        lax_main_class="$rhs"
                ;;
                lax.nl.java.launcher.main.class*)
                        lax_nl_java_launcher_main_class="$rhs"
                ;;
                lax.nl.current.vm*)
                        lax_nl_current_vm="$rhs"
                ;;
                lax.user.dir*)
                        lax_user_dir="$rhs"
                        lax_user_dir=`echo $lax_user_dir | sed 's;^[ ]*\(.*\)[ ]*$;\1;'`
                ;;
                lax.resource.dir*)
                        lax_resource_dir="$rhs"
                        lax_resource_dir=`echo $lax_resource_dir | sed 's;^[ ]*\(.*\)[ ]*$;\1;'`
                ;;
                lax.stdout.redirect*)
                        lax_stdout_redirect="$rhs"
                ;;
                lax.stderr.redirect*)
                        lax_stderr_redirect="$rhs"
                ;;
                lax.dir*)
                        lax_dir="$rhs"
                ;;
                lax.always.ask*)
                        lax_always_ask="$rhs"
                ;;
                lax.application.name*)
                        lax_application_name="$rhs"
                ;;
                lax.nl.message.vm.not.loaded*)
                        lax_nl_message_vm_loaded="$rhs"
                ;;
                lax.nl.valid.vm.list*)
                        # transform an blank value to "ALL"
                        case "$rhs" in
                                "") rhs="ALL"; ;;
                        esac
                        lax_nl_valid_vm_list="$rhs"
                ;;
                lax.nl.java.option.check.source*)
                        verify="$rhs"
                ;;
                lax.nl.java.option.verify.mode*)
                        verify_mode="$rhs"
                lax.resource.dir*)
                        lax_resource_dir="$rhs"
                        lax_resource_dir=`echo $lax_resource_dir | sed 's;^[ ]*\(.*\)[ ]*$;\1;'`
                ;;
                lax.stdout.redirect*)
                        lax_stdout_redirect="$rhs"
                ;;
                lax.stderr.redirect*)
                        lax_stderr_redirect="$rhs"
                ;;
                lax.dir*)
                        lax_dir="$rhs"
                ;;
                lax.always.ask*)
                        lax_always_ask="$rhs"
                ;;
                lax.application.name*)
                        lax_application_name="$rhs"
                ;;
                lax.nl.message.vm.not.loaded*)
                        lax_nl_message_vm_loaded="$rhs"
                ;;
                lax.nl.valid.vm.list*)
                        # transform an blank value to "ALL"
                        case "$rhs" in
                                "") rhs="ALL"; ;;
                        esac
                        lax_nl_valid_vm_list="$rhs"
                ;;
                lax.nl.java.option.check.source*)
                        verify="$rhs"
                ;;
                lax.nl.java.option.verify.mode*)
                        verify_mode="$rhs"
                ;;
                lax.nl.java.option.verbose*)
                        verbo="$rhs"
                ;;
                lax.nl.java.option.garbage.collection.extent*)
                        gcxtnt="$rhs"
                ;;
                lax.nl.java.option.garbage.collection.background.thread*)
                        gcthrd="$rhs"
                ;;
                lax.nl.java.option.native.stack.size.max*)
                        nsmax="$rhs"
                ;;
                lax.nl.java.option.java.stack.size.max*)
                        jsmax="$rhs"
                ;;
                lax.nl.java.option.java.heap.size.max*)
                        jhmax="$rhs"
                ;;
                lax.nl.java.option.java.heap.size.initial*)
                        jhinit="$rhs"
                ;;
                lax.nl.java.option.debugging*)
                        debug="$rhs"
                ;;
                lax.nl.$osName.$cpuName.java.compiler*)
                        lax_nl_osname_cpuname_java_compiler="$rhs"
                ;;
                lax.nl.$osName.java.compiler*)
                        lax_nl_osname_java_compiler="$rhs"
                ;;
                lax.nl.java.compiler*)
                        lax_nl_java_compiler="$rhs"
                ;;