diff options
author | glewis <glewis@FreeBSD.org> | 2006-04-27 03:48:08 +0800 |
---|---|---|
committer | glewis <glewis@FreeBSD.org> | 2006-04-27 03:48:08 +0800 |
commit | 09135f1fcfc039cfabb1d5b8c003c3698bc68bf5 (patch) | |
tree | d1e466c33b522634611dc70e16a8a3fb9152bf3f /java/javavmwrapper | |
parent | 686b43351f31ba3ddec908c84b5a5e7873fef524 (diff) | |
download | freebsd-ports-gnome-09135f1fcfc039cfabb1d5b8c003c3698bc68bf5.tar.gz freebsd-ports-gnome-09135f1fcfc039cfabb1d5b8c003c3698bc68bf5.tar.zst freebsd-ports-gnome-09135f1fcfc039cfabb1d5b8c003c3698bc68bf5.zip |
. Avoid stomping on environment variables by prefixing variable names with
_JAVAVM_. The notable exception is JAVA_HOME, which is deliberately set
by the wrapper.
PR: 88048
Diffstat (limited to 'java/javavmwrapper')
-rw-r--r-- | java/javavmwrapper/src/javavmwrapper.sh | 244 |
1 files changed, 121 insertions, 123 deletions
diff --git a/java/javavmwrapper/src/javavmwrapper.sh b/java/javavmwrapper/src/javavmwrapper.sh index 7cf77c6dbcd8..f459c34e2c88 100644 --- a/java/javavmwrapper/src/javavmwrapper.sh +++ b/java/javavmwrapper/src/javavmwrapper.sh @@ -29,13 +29,13 @@ # # MAINTAINER=java@FreeBSD.org -SAVE_PATH=${PATH} +_JAVAVM_SAVE_PATH=${PATH} export PATH=/bin:/sbin:/usr/bin:/usr/sbin -PREFIX="%%PREFIX%%" -CONF="${PREFIX}/etc/javavms" -IAM=`basename "${0}"` -MAKE=/usr/bin/make +_JAVAVM_PREFIX="%%PREFIX%%" +_JAVAVM_CONF="${_JAVAVM_PREFIX}/etc/javavms" +_JAVAVM_PROG=`basename "${0}"` +_JAVAVM_MAKE=/usr/bin/make # # Try to run a Java command. @@ -43,13 +43,13 @@ MAKE=/usr/bin/make tryJavaCommand () { # Check for the command being executable and exec it if so. if [ -x "${1}" ]; then - if [ ! -z "${SAVE_PATH}" ]; then - export PATH=${SAVE_PATH} + if [ ! -z "${_JAVAVM_SAVE_PATH}" ]; then + export PATH=${_JAVAVM_SAVE_PATH} fi exec "${@}" fi - echo "${IAM}: warning: couldn't run specified Java command - \"${1}\"" >&2 + echo "${_JAVAVM_PROG}: warning: couldn't run specified Java command - \"${1}\"" >&2 } # @@ -60,10 +60,10 @@ createJavaLinks () { if [ -x "${exe}" -a \ ! -d "${exe}" -a \ "`basename "${exe}"`" = "`basename "${exe}" .so`" -a \ - ! -e "${PREFIX}/bin/`basename "${exe}"`" -a \ - -w "${PREFIX}/bin" ]; then - ln -s "${PREFIX}/bin/javavm" \ - "${PREFIX}/bin/`basename "${exe}"`" 2>/dev/null + ! -e "${_JAVAVM_PREFIX}/bin/`basename "${exe}"`" -a \ + -w "${_JAVAVM_PREFIX}/bin" ]; then + ln -s "${_JAVAVM_PREFIX}/bin/javavm" \ + "${_JAVAVM_PREFIX}/bin/`basename "${exe}"`" 2>/dev/null fi done } @@ -72,20 +72,20 @@ createJavaLinks () { # Sort the configuration file # sortConfiguration () { + local IFS=: + # Ensure the configuration file exists - if [ ! -f "${CONF}" ]; then + if [ ! -f "${_JAVAVM_CONF}" ]; then return fi # Ensure the configuration file has the correct permissions - if [ ! -w "${CONF}" -o ! -r "${CONF}" ]; then - echo "${IAM}: error: can't read/write ${CONF} configuration file!" >&2 + if [ ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then + echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" >&2 return fi - ifs="${IFS}" - IFS=: - cat "${CONF}" | \ + cat "${_JAVAVM_CONF}" | \ ( export JAVAVMS while read JAVAVM; do @@ -103,7 +103,7 @@ sortConfiguration () { if [ `basename "${VM}"` != "java" ]; then continue fi - if [ "`realpath "${VM}" 2>/dev/null `" = "${PREFIX}/bin/javavm" ]; then + if [ "`realpath "${VM}" 2>/dev/null `" = "${_JAVAVM_PREFIX}/bin/javavm" ]; then continue fi # Skip duplicate VMs @@ -212,16 +212,14 @@ sortConfiguration () { fi done; if [ ! -z "${JAVAVMS}" ]; then - rm "${CONF}" + rm "${_JAVAVM_CONF}" for JAVAVM in ${JAVAVMS}; do if [ ! -z "${JAVAVM}" ]; then - echo "${JAVAVM}" >> "${CONF}" + echo "${JAVAVM}" >> "${_JAVAVM_CONF}" fi done fi ) - - IFS="${ifs}" } # @@ -229,13 +227,13 @@ sortConfiguration () { # checkVMs () { # Ensure the configuration file exists - if [ ! -f "${CONF}" ]; then + if [ ! -f "${_JAVAVM_CONF}" ]; then exit 0 fi # Ensure the configuration file has the correct permissions - if [ ! -w "${CONF}" -o ! -r "${CONF}" ]; then - echo "${IAM}: error: can't read/write ${CONF} configuration file!" 1>&2 + if [ ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then + echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" 1>&2 exit 1 fi @@ -244,7 +242,7 @@ checkVMs () { sortConfiguration # Ensure links are created for every executable for a VM. - cat "${CONF}" | \ + cat "${_JAVAVM_CONF}" | \ ( while read JAVAVM; do VM=`echo "${JAVAVM}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null` @@ -264,54 +262,54 @@ checkVMs () { registerVM () { # Check the java command given to us. if [ -z "${1}" ]; then - echo "Usage: ${IAM} path" + echo "Usage: ${_JAVAVM_PROG} path" exit 1 fi # Create the configuration file if it doesn't exist - if [ ! -e "${CONF}" ]; then - touch "${CONF}" + if [ ! -e "${_JAVAVM_CONF}" ]; then + touch "${_JAVAVM_CONF}" fi # Ensure the configuration file exists and has the correct permissions - if [ ! -f "${CONF}" -o ! -w "${CONF}" -o ! -r "${CONF}" ]; then - echo "${IAM}: error: can't read/write ${CONF} configuration file!" 1>&2 + if [ ! -f "${_JAVAVM_CONF}" -o ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then + echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" 1>&2 exit 1 fi # Check that the given VM can be found in the configuration file VM=`echo "${1}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null` REGISTERED= - if [ ! -z "`grep "${VM}" "${CONF}"`" ]; then - echo "${IAM}: warning: JavaVM \"${VM}\" is already registered" 1>&2 + if [ ! -z "`grep "${VM}" "${_JAVAVM_CONF}"`" ]; then + echo "${_JAVAVM_PROG}: warning: JavaVM \"${VM}\" is already registered" 1>&2 REGISTERED="yes" fi # Check that the VM exists and is "sane" if [ ! -e "${VM}" ]; then - echo "${IAM}: error: JavaVM \"${VM}\" does not exist" 1>&2 + echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" does not exist" 1>&2 exit 1 fi if [ -d "${VM}" ]; then - echo "${IAM}: error: JavaVM \"${VM}\" is a directory" 1>&2 + echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is a directory" 1>&2 exit 1 fi if [ ! -x "${VM}" ]; then - echo "${IAM}: error: JavaVM \"${VM}\" is not executable" 1>&2 + echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is not executable" 1>&2 exit 1 fi if [ `basename "${VM}"` != "java" ]; then - echo "${IAM}: error: JavaVM \"${VM}\" is not valid" 1>&2 + echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is not valid" 1>&2 exit 1 fi - if [ "`realpath "${VM}" 2>/dev/null `" = "${PREFIX}/bin/javavm" ]; then - echo "${IAM}: error: JavaVM \"${VM}\" is javavm!" 1>&2 + if [ "`realpath "${VM}" 2>/dev/null `" = "${_JAVAVM_PREFIX}/bin/javavm" ]; then + echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is javavm!" 1>&2 exit 1 fi # Add the VM to the configuration file if [ "${REGISTERED}" != "yes" ]; then - echo "${1}" >> "${CONF}" + echo "${1}" >> "${_JAVAVM_CONF}" fi # Create symbolic links as appropriate if they don't exist. @@ -331,38 +329,38 @@ registerVM () { unregisterVM () { # Check usage if [ -z "${1}" ]; then - echo "Usage: ${IAM} path" + echo "Usage: ${_JAVAVM_PROG} path" exit 1 fi # Check for the configuration file - if [ ! -e "${CONF}" ]; then - echo "${IAM}: error: can't find ${CONF} configuration file!" >&2 + if [ ! -e "${_JAVAVM_CONF}" ]; then + echo "${_JAVAVM_PROG}: error: can't find ${_JAVAVM_CONF} configuration file!" >&2 exit 1 fi # Ensure the configuration file has the correct permissions - if [ ! -w "${CONF}" -o ! -r "${CONF}" ]; then - echo "${IAM}: error: can't read/write ${CONF} configuration file!" >&2 + if [ ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then + echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" >&2 exit 1 fi # Check that the given VM can be found in the configuration file - if [ -z "`grep "${1}" "${CONF}"`" ]; then - echo "${IAM}: error: \"${1}\" JavaVM is not currently registered" + if [ -z "`grep "${1}" "${_JAVAVM_CONF}"`" ]; then + echo "${_JAVAVM_PROG}: error: \"${1}\" JavaVM is not currently registered" exit 1 fi # Remove unneeded symlinks - VMS=`sed -E 's|[[:space:]]*#.*||' < "${CONF}" | uniq 2>/dev/null` - VM=`grep "${1}" "${CONF}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null` + VMS=`sed -E 's|[[:space:]]*#.*||' < "${_JAVAVM_CONF}" | uniq 2>/dev/null` + VM=`grep "${1}" "${_JAVAVM_CONF}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null` JAVA_HOME=`dirname "${VM}"` JAVA_HOME=`dirname "${JAVA_HOME}"` for exe in "${JAVA_HOME}"/bin/* "${JAVA_HOME}"/jre/bin/*; do exe=`basename "${exe}"` - if [ -L "${PREFIX}/bin/${exe}" -a \ - "`realpath "${PREFIX}/bin/${exe}" 2>/dev/null `" = \ - "${PREFIX}/bin/javavm" ]; then + if [ -L "${_JAVAVM_PREFIX}/bin/${exe}" -a \ + "`realpath "${_JAVAVM_PREFIX}/bin/${exe}" 2>/dev/null `" = \ + "${_JAVAVM_PREFIX}/bin/javavm" ]; then for JAVAVM in ${VMS}; do if [ "${JAVAVM}" != "${VM}" ]; then JAVAVM=`dirname "${JAVAVM}"` @@ -374,27 +372,27 @@ unregisterVM () { fi done - rm "${PREFIX}/bin/${exe}" + rm "${_JAVAVM_PREFIX}/bin/${exe}" fi done # Remove the VM from the configuration file - ed "${CONF}" >/dev/null <<EOF + ed "${_JAVAVM_CONF}" >/dev/null <<EOF g|${1}|d w q EOF # Remove configuration file if its size reached 0 - if [ ! -s "${CONF}" ]; then - rm "${CONF}" + if [ ! -s "${_JAVAVM_CONF}" ]; then + rm "${_JAVAVM_CONF}" fi exit 0 } # Check for an alias and call the appropriate function. -case "${IAM}" in +case "${_JAVAVM_PROG}" in registervm ) registerVM "${1}" ;; @@ -409,168 +407,168 @@ esac # Main () # Backwards compatibility -if [ "${IAM}" = "javavm" ]; then - echo "${IAM}: warning: The use of 'javavm' as a synonym for 'java' is deprecated" 1>&2 - IAM=java +if [ "${_JAVAVM_PROG}" = "javavm" ]; then + echo "${_JAVAVM_PROG}: warning: The use of 'javavm' as a synonym for 'java' is deprecated" 1>&2 + _JAVAVM_PROG=java fi # Ignore JAVA_HOME if it's set to %%PREFIX%% -if [ "`realpath "${JAVA_HOME}"`" != "`realpath "${PREFIX}"`" ]; then +if [ "`realpath "${JAVA_HOME}"`" != "`realpath "${_JAVAVM_PREFIX}"`" ]; then # Otherwise use JAVA_HOME if it's set - if [ ! -z "${JAVA_HOME}" -a -x "${JAVA_HOME}/bin/${IAM}" ]; then + if [ ! -z "${JAVA_HOME}" -a -x "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then export JAVA_HOME - tryJavaCommand "${JAVA_HOME}/bin/${IAM}" "${@}" - elif [ ! -z "${JAVA_HOME}" -a -x "${JAVA_HOME}/jre/bin/${IAM}" ]; then + tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" "${@}" + elif [ ! -z "${JAVA_HOME}" -a -x "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then export JAVA_HOME - tryJavaCommand "${JAVA_HOME}/jre/bin/${IAM}" "${@}" + tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" "${@}" fi fi unset JAVA_HOME # Determine location of bsd.port.mk if it exists -PORTSDIR= +_JAVAVM_PORTSDIR= if [ -r /usr/share/mk/bsd.port.mk ]; then - PORTSDIR=`"${MAKE}" -f /usr/share/mk/bsd.port.mk -V PORTSDIR 2>/dev/null` + _JAVAVM_PORTSDIR=`"${_JAVAVM_MAKE}" -f /usr/share/mk/bsd.port.mk -V PORTSDIR 2>/dev/null` fi -BSD_PORT_MK= -if [ ! -z "${PORTSDIR}" -a -r "${PORTSDIR}/Mk/bsd.port.mk" ]; then - BSD_PORT_MK="${PORTSDIR}/Mk/bsd.port.mk" +_JAVAVM_BSD_PORT_MK= +if [ ! -z "${_JAVAVM_PORTSDIR}" -a -r "${_JAVAVM_PORTSDIR}/Mk/bsd.port.mk" ]; then + _JAVAVM_BSD_PORT_MK="${_JAVAVM_PORTSDIR}/Mk/bsd.port.mk" fi # If bsd.port.mk was found, use that to determine the VM to use. -if [ ! -z "${BSD_PORT_MK}" ]; then - JAVA_HOME=`"${MAKE}" -f "${BSD_PORT_MK}" -V JAVA_HOME USE_JAVA=yes 2>/dev/null` +if [ ! -z "${_JAVAVM_BSD_PORT_MK}" ]; then + JAVA_HOME=`"${_JAVAVM_MAKE}" -f "${_JAVAVM_BSD_PORT_MK}" -V JAVA_HOME USE_JAVA=yes 2>/dev/null` if [ ! -z "${JAVA_HOME}" -a \ - -x "${JAVA_HOME}/bin/${IAM}" ]; then + -x "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then export JAVA_HOME - tryJavaCommand "${JAVA_HOME}/bin/${IAM}" "${@}" + tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" "${@}" elif [ ! -z "${JAVA_HOME}" -a \ - -x "${JAVA_HOME}/jre/bin/${IAM}" ]; then + -x "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then export JAVA_HOME - tryJavaCommand "${JAVA_HOME}/jre/bin/${IAM}" "${@}" + tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" "${@}" fi fi -# Then try to make sure that ${CONF} exists -if [ ! -e "${CONF}" ]; then - echo "${IAM}: error: can't find ${CONF} configuration file" >&2 +# Then try to make sure that ${_JAVAVM_CONF} exists +if [ ! -e "${_JAVAVM_CONF}" ]; then + echo "${_JAVAVM_PROG}: error: can't find ${_JAVAVM_CONF} configuration file" >&2 exit 1 fi -# Allow comments in the ${CONF} -VMS=`sed -E 's|[[:space:]]*#.*||' < "${CONF}" | uniq 2>/dev/null` +# Allow comments in the ${_JAVAVM_CONF} +_JAVAVM_VMS=`sed -E 's|[[:space:]]*#.*||' < "${_JAVAVM_CONF}" | uniq 2>/dev/null` # Fix up JAVA_VERSION if [ ! -z "${JAVA_VERSION}" ]; then - VERSION= + _JAVAVM_VERSION= for version in ${JAVA_VERSION}; do case "${version}" in 1.1+) - VERSION="${VERSION} 1.1 1.2 1.3 1.4 1.5" + _JAVAVM_VERSION="${_JAVAVM_VERSION} 1.1 1.2 1.3 1.4 1.5" ;; 1.2+) - VERSION="${VERSION} 1.2 1.3 1.4 1.5" + _JAVAVM_VERSION="${_JAVAVM_VERSION} 1.2 1.3 1.4 1.5" ;; 1.3+) - VERSION="${VERSION} 1.3 1.4 1.5" + _JAVAVM_VERSION="${_JAVAVM_VERSION} 1.3 1.4 1.5" ;; 1.4+) - VERSION="${VERSION} 1.4 1.5" + _JAVAVM_VERSION="${_JAVAVM_VERSION} 1.4 1.5" ;; 1.5+) - VERSION="${VERSION} 1.5" + _JAVAVM_VERSION="${_JAVAVM_VERSION} 1.5" ;; *) - VERSION="${VERSION} ${version}" + _JAVAVM_VERSION="${_JAVAVM_VERSION} ${version}" ;; esac done - JAVA_VERSION=`echo "${VERSION}" | sort | uniq` + JAVA_VERSION=`echo "${_JAVAVM_VERSION}" | sort | uniq` fi -# Finally try to run one of the ${VMS} -for JAVAVM in ${VMS}; do - JAVA_HOME=`dirname "${JAVAVM}"` +# Finally try to run one of the ${_JAVAVM_VMS} +for _JAVAVM_JAVAVM in ${_JAVAVM_VMS}; do + JAVA_HOME=`dirname "${_JAVAVM_JAVAVM}"` JAVA_HOME=`dirname "${JAVA_HOME}"` - VM=`basename "${JAVA_HOME}"` + _JAVAVM_VM=`basename "${JAVA_HOME}"` # Respect JAVA_VERSION if [ ! -z "${JAVA_VERSION}" ]; then - VERSION=`echo ${VM} | \ + _JAVAVM_VERSION=`echo ${_JAVAVM_VM} | \ sed -e 's|[^0-9]*\([0-9]\)\.\([0-9]\)\.[0-9]|\1.\2|'` - for version in ${JAVA_VERSION}; do - if [ "${VERSION}" = "${version}" ]; then - VERSION= + for _JAVAVM_REQUESTED_VERSION in ${JAVA_VERSION}; do + if [ "${_JAVAVM_VERSION}" = "${_JAVAVM_REQUESTED_VERSION}" ]; then + _JAVAVM_VERSION= break fi done - if [ ! -z "${VERSION}" ]; then + if [ ! -z "${_JAVAVM_VERSION}" ]; then continue fi fi # Respect JAVA_OS if [ ! -z "${JAVA_OS}" ]; then - OS= - case "${VM}" in + _JAVAVM_OS= + case "${_JAVAVM_VM}" in diablo*|j*) - OS=native + _JAVAVM_OS=native ;; linux*) - OS=linux + _JAVAVM_OS=linux ;; esac - for os in ${JAVA_OS}; do - if [ "${OS}" = "${os}" ]; then - OS= + for _JAVAVM_REQUESTED_OS in ${JAVA_OS}; do + if [ "${_JAVAVM_OS}" = "${_JAVAVM_REQUESTED_OS}" ]; then + _JAVAVM_OS= break fi done - if [ ! -z "${OS}" ]; then + if [ ! -z "${_JAVAVM_OS}" ]; then continue fi fi # Respect JAVA_VENDOR if [ ! -z "${JAVA_VENDOR}" ]; then - VENDOR= - case "${VM}" in + _JAVAVM_VENDOR= + case "${_JAVAVM_VM}" in diablo*) - VENDOR=bsdjava + _JAVAVM_VENDOR=bsdjava ;; j*) - VENDOR=freebsd + _JAVAVM_VENDOR=freebsd ;; linux-blackdown*) - VENDOR=blackdown + _JAVAVM_VENDOR=blackdown ;; linux-ibm*) - VENDOR=ibm + _JAVAVM_VENDOR=ibm ;; linux-sun*) - VENDOR=sun + _JAVAVM_VENDOR=sun ;; esac - for vendor in ${JAVA_VENDOR}; do - if [ "${VENDOR}" = "${vendor}" ]; then - VENDOR= + for _JAVAVM_REQUESTED_VENDOR in ${JAVA_VENDOR}; do + if [ "${_JAVAVM_VENDOR}" = "${_JAVAVM_REQUESTED_VENDOR}" ]; then + _JAVAVM_VENDOR= break fi done - if [ ! -z "${VENDOR}" ]; then + if [ ! -z "${_JAVAVM_VENDOR}" ]; then continue fi fi # Check if the command exists and try to run it. if [ ! -z "${JAVA_HOME}" -a \ - -x "${JAVA_HOME}/bin/${IAM}" ]; then + -x "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then export JAVA_HOME - tryJavaCommand "${JAVA_HOME}/bin/${IAM}" "${@}" + tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" "${@}" elif [ ! -z "${JAVA_HOME}" -a \ - -x "${JAVA_HOME}/jre/bin/${IAM}" ]; then + -x "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then export JAVA_HOME - tryJavaCommand "${JAVA_HOME}/jre/bin/${IAM}" "${@}" + tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" "${@}" fi done -echo "${IAM}: error: no suitable JavaVMs found" >&2 +echo "${_JAVAVM_PROG}: error: no suitable JavaVMs found" >&2 exit 1 |