Skip to content

Commit

Permalink
"--add-opens" for J11+; J17+ SWT check
Browse files Browse the repository at this point in the history
Cleanup script: quotes, ` -> $(
  • Loading branch information
TuxPaper committed Nov 15, 2023
1 parent 774d5f1 commit c6492cc
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 deletions core/src/com/biglybt/platform/unix/startupScript
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ JAVA_PROPS=""

######## YOU PROBABLY DO NOT WANT TO TOUCH ANYTHING BELOW! ########

SCRIPT_VERSION=10
SCRIPT_VERSION=11
START_CLASS="com.biglybt.ui.Main"

MSG_LOADING="Loading BiglyBT:"
Expand All @@ -32,6 +32,9 @@ export GDK_BACKEND=x11
export FT2_SUBPIXEL_HINTING=2

JAVA_ARGS=$(grep -o '^[^#]*' ~/.biglybt/java.vmoptions 2>/dev/null | tr '\n' ' ')
JAVA_VERSION=""
isJ17=false
JAVABIN="${JAVA_PROGRAM_DIR}java"

look_for_java()
{
Expand All @@ -42,51 +45,52 @@ look_for_java()
fi
fi

echo $MSG_JAVASEARCH
echo "$MSG_JAVASEARCH"


JAVA_CHECK_DIRS="/usr/java/latest /usr/java /usr/lib/jvm/latest /usr/lib/jvm"
for JAVADIR in $JAVA_CHECK_DIRS; do
IFS=$'\n'
potential_java_dirs=(`ls -1 "$JAVADIR" | sort | tac 2>/dev/null`)
potential_java_dirs=($(ls -1 "$JAVADIR" | sort | tac 2>/dev/null))
IFS=
for D in "${potential_java_dirs[@]}"; do
if [[ -d "$JAVADIR/$D" && -x "$JAVADIR/$D/bin/java" ]]; then
JAVA_PROGRAM_DIR="$JAVADIR/$D/bin/"
echo $MSG2 $JAVA_PROGRAM_DIR
JAVABIN="${JAVA_PROGRAM_DIR}java"
echo "$MSG2" "$JAVA_PROGRAM_DIR"
if check_version ; then
return 0
fi
fi
done
done

echo $MSG8 "${JAVADIR}/" $MSG9 ; echo $MSG_JAVA_BELOW_MIN
echo "${MSG8}${JAVADIR}/${MSG9}" ; echo "$MSG_JAVA_BELOW_MIN"

return 1
}

check_version()
{
JAVA_ISGCJ=`"${JAVA_PROGRAM_DIR}java" -version 2>&1 | grep "gcj"`
JAVA_ISGCJ=$($JAVABIN -version 2>&1 | grep "gcj")
if [ ! "$JAVA_ISGCJ x" = " x" ] ; then
echo $MSG_ISGCJ
echo "$MSG_ISGCJ"
return 1
fi

JAVA_HEADER=`"${JAVA_PROGRAM_DIR}java" -version 2>&1 | head -n 1`
JAVA_IMPL=`echo ${JAVA_HEADER} | cut -f1 -d' '`
JAVA_HEADER=$($JAVABIN -version 2>&1 | head -n 1)
JAVA_IMPL=$(echo "${JAVA_HEADER}" | cut -f1 -d' ')
if [ "$JAVA_IMPL" = "#" ] ; then
echo $MSG_JAVABORK
${JAVA_PROGRAM_DIR}java -version 2>&1
echo "$MSG_JAVABORK"
$JAVABIN -version 2>&1
exit 1
else
VERSION=`echo ${JAVA_HEADER} | sed "s/^.* version \"\(.*\)\"/\1/"`
if echo $VERSION | grep "^1.[0-7]" ; then
echo $MSG_JAVA_TOO_OLD "[${JAVA_PROGRAM_DIR}java = ${VERSION}]" ; echo $MSG_JAVA_BELOW_MIN
JAVA_VERSION=$(echo "${JAVA_HEADER}" | sed "s/^.* version \"\(.*\)\".*$/\1/")
if echo "$JAVA_VERSION" | grep "^1.[0-7]" ; then
echo "$MSG_JAVA_TOO_OLD" "[$JAVABIN = ${JAVA_VERSION}]" ; echo "$MSG_JAVA_BELOW_MIN"
return 1
else
echo $MSG5 "[${JAVA_PROGRAM_DIR}java = ${JAVA_IMPL} ${VERSION}]"
echo "${MSG5} [$JAVABIN = ${JAVA_IMPL} ${JAVA_VERSION}]"
return 0
fi
fi
Expand All @@ -96,7 +100,7 @@ runJavaOutput()
{
# assume we can write to the user's home..

RESULT=`${JAVA_PROGRAM_DIR}java \
RESULT=`$JAVABIN \
-cp "${CLASSPATH}" \
"-Djava.library.path=${PROGRAM_DIR}" \
"-Dazureus.install.path=${PROGRAM_DIR}" \
Expand All @@ -116,28 +120,32 @@ exists () {

moveInSWT()
{
if [ "$(echo ${PROGRAM_DIR}/swt/*.jar)" = "${PROGRAM_DIR}/swt/*.jar" ]; then
SWTDIR="${PROGRAM_DIR}/swt"

if [ ! -d "$SWTDIR" ] || [ -z "$(ls -A "$SWTDIR")" ]; then
# No swt dir
return;
fi
arch=`uname -m`
arch=$(uname -m)
if [[ "$OSTYPE" = "FreeBSD" ]]; then
SWTFILE="swt/swt-bsd.jar"
elif [ -f "${PROGRAM_DIR}/swt/swt-${arch}.jar" ]; then
SWTFILE="swt/swt-${arch}.jar"
SWTFILE="swt/swt-bsd.jar"
elif $isJ17 && [ -f "${SWTDIR}/J17/swt-${arch}.jar" ]; then
SWTFILE="swt/J17/swt-${arch}.jar"
elif [ -f "${SWTDIR}/swt-${arch}.jar" ]; then
SWTFILE="swt/swt-${arch}.jar"
else
if [ "`${JAVA_PROGRAM_DIR}java -cp \"${CLASSPATH}\" com.biglybt.platform.JavaBitMode`" = "64" ]; then
if [ "$($JAVABIN -cp \"${CLASSPATH}\" com.biglybt.platform.JavaBitMode)" = "64" ]; then
SWTFILE="swt/swt-x86_64.jar"
else
SWTFILE="swt/swt-x86.jar"
fi
fi

if exists "zip"; then
if [ -f "${PROGRAM_DIR}/swt/swt.jar" ]; then
SWTVER=`unzip -cq "${PROGRAM_DIR}/swt/swt.jar" version.txt | sed "s/^version \(.*\)/\1/"`
if [ -f "${SWTDIR}/swt.jar" ]; then
SWTVER=$(unzip -cq "${SWTDIR}/swt.jar" version.txt | sed "s/^version \(.*\)/\1/")
fi
SWTVERNEW=`unzip -cq "${PROGRAM_DIR}/${SWTFILE}" version.txt | sed "s/^version \(.*\)/\1/"`
SWTVERNEW=$(unzip -cq "${PROGRAM_DIR}/${SWTFILE}" version.txt | sed "s/^version \(.*\)/\1/")
else
if [ -f "${PROGRAM_DIR}/swt/swt.jar" ]; then
# User > Unknown
Expand All @@ -156,7 +164,7 @@ moveInSWT()
}


echo $MSG_STARTING
echo "$MSG_STARTING"

# locate and test the java executable
if [ "$JAVA_PROGRAM_DIR" == "" ]; then
Expand All @@ -165,24 +173,27 @@ if [ "$JAVA_PROGRAM_DIR" == "" ]; then
fi
fi

# Java 11+ needs --add-opens, which borks some older java versions
if echo "$JAVA_VERSION" | grep -E "^(1[1-9]|[2-9][0-9])\." > /dev/null ; then
JAVA_ARGS="${JAVA_ARGS} --add-opens java.base/java.net=ALL-UNNAMED"
fi
if echo "$JAVA_VERSION" | grep -E "^(1[7-9]|[2-9][0-9])\." > /dev/null ; then
isJ17=true
fi

# get the app dir if not already defined
if [ -z "$PROGRAM_DIR" ]; then
PROGRAM_DIR=`dirname "$0"`
PROGRAM_DIR=`cd "$PROGRAM_DIR"; pwd`
else
if [ "$(echo ${PROGRAM_DIR}/*.jar)" = "${PROGRAM_DIR}/*.jar" ]; then
echo "You seem to have set an invalid PROGRAM_DIR, unable to continue!"
exit 1
elif [ ! -f "${PROGRAM_DIR}/BiglyBT.jar" ]; then
echo "Unable to locate BiglyBT.jar in $PROGRAM_DIR, aborting!"
exit 1
fi
PROGRAM_DIR=$(dirname "$0")
PROGRAM_DIR=$(cd "$PROGRAM_DIR"; pwd)
elif [ ! -f "${PROGRAM_DIR}/BiglyBT.jar" ]; then
echo "Unable to locate BiglyBT.jar in $PROGRAM_DIR, aborting!"
exit 1
fi

OLDPATH=$PWD

# Change path here so we can do for loop on program dirs with spaces
cd "${PROGRAM_DIR}"
cd "${PROGRAM_DIR}" || exit

# build the classpath

Expand Down Expand Up @@ -210,12 +221,12 @@ JAVA_PROPS="${JAVA_PROPS} -Dazureus.script.version=${SCRIPT_VERSION}"

runJavaOutput "com.biglybt.platform.unix.ScriptBeforeStartup" "$@";

echo $MSG_LOADING
echo "$MSG_LOADING"

# Don't use "exec -a BiglyBT ..." here as exec quits this script after completion,
# preventing ScriptAfterShutdown from running, which installs updates and does
# restarts
${JAVA_PROGRAM_DIR}java -Xmx256m \
$JAVABIN -Xmx256m \
-cp "${CLASSPATH}" \
"-Djava.library.path=${PROGRAM_DIR}" \
"-Dazureus.install.path=${PROGRAM_DIR}" \
Expand All @@ -226,8 +237,8 @@ ${JAVA_PROGRAM_DIR}java -Xmx256m \
${OTHER_PARAMS} \
"$@"

echo $MSG_AZEXIT
echo "$MSG_AZEXIT"

runJavaOutput "com.biglybt.platform.unix.ScriptAfterShutdown" "$@";

echo $MSG_TERMINATED
echo "$MSG_TERMINATED"

0 comments on commit c6492cc

Please sign in to comment.