From: Ben Soares Date: Wed, 17 Mar 2021 21:06:11 +0000 (+0000) Subject: JAL-3830 Now using a single universal bash script (jalviewc) for bash in linux, macos... X-Git-Tag: Release_2_11_2_0~54 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c278f1c989d8b8facc353d36c64d713e67ab24f5;p=jalview.git JAL-3830 Now using a single universal bash script (jalviewc) for bash in linux, macos, cygwin and WSL. It keeps things together. --- diff --git a/build.gradle b/build.gradle index 009b0c1..bea9951 100644 --- a/build.gradle +++ b/build.gradle @@ -1573,7 +1573,7 @@ task getdownWebsite() { } } - def getdownWrapperScripts = [ getdown_mac_wrapper_script, getdown_unix_wrapper_script, getdown_windows_wrapper_script, getdown_powershell_wrapper_script ] + def getdownWrapperScripts = [ getdown_bash_wrapper_script, getdown_powershell_wrapper_script ] getdownWrapperScripts.each{ script -> def s = file( "${jalviewDir}/utils/getdown/${script}" ) if (s.exists()) { @@ -1912,8 +1912,8 @@ task installers(type: com.install4j.gradle.Install4jTask) { 'WINDOWS_APPLICATION_ID': install4jWinApplicationId, 'MACOS_DMG_DS_STORE': install4jDMGDSStore, 'MACOS_DMG_BG_IMAGE': install4jDMGBackgroundImage, - 'MACOS_DMG_WRAPPER_LINK': install4j_dmg_wrapper_link, - 'MACOS_WRAPPER_SCRIPT': getdown_mac_wrapper_script, + 'MACOS_DMG_WRAPPER_LINK': getdown_bash_wrapper_script, + 'MACOS_WRAPPER_SCRIPT': getdown_bash_wrapper_script, 'INSTALLER_NAME': install4jInstallerName, 'INSTALL4J_UTILS_DIR': install4j_utils_dir, 'GETDOWN_WEBSITE_DIR': getdown_website_dir, diff --git a/gradle.properties b/gradle.properties index d87a598..ba87a6c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -133,10 +133,7 @@ install4j_png_icon_file = jalview_logo.png install4j_background = jalview_logo_background_fade-640x480.png install4j_dmg_background = jalview_dmg_background-NON-RELEASE.png install4j_dmg_ds_store = jalview_dmg_DS_Store -install4j_dmg_wrapper_link = jalviewc -getdown_mac_wrapper_script = jalviewc-macos -getdown_unix_wrapper_script = jalviewc -getdown_windows_wrapper_script = jalviewc-windows +getdown_bash_wrapper_script = jalviewc getdown_powershell_wrapper_script = jalviewc.ps1 OSX_KEYSTORE = diff --git a/utils/getdown/jalviewc b/utils/getdown/jalviewc index 4792a9c..29beb98 100755 --- a/utils/getdown/jalviewc +++ b/utils/getdown/jalviewc @@ -1,33 +1,132 @@ #!/usr/bin/env bash +declare -a ARGS=("${@}") ARG1=$1 -DIR="$(dirname "$(readlink -f "$0")")" -# check to see if $1 is set and is not start of other cli set args -OPEN="" -if [ -n "${ARG1}" -a "${ARG1}" = "${ARG1#-}" -a "${ARG1}" != "open" ]; then - # first argument exists and does not start with a "-" and is not "open" - OPEN="-open" +# this whole next part is because there's no readlink -f in Darwin +function readlinkf() { + FINDFILE="$1" + FILE="${FINDFILE}" + PREVFILE="" + C=0 + MAX=100 # just in case we end up in a loop + FOUND=0 + while [ "${C}" -lt "${MAX}" -a "${FILE}" != "${PREVFILE}" -a "${FOUND}" -ne 1 ]; do + PREVFILE="${FILE}" + FILE="$(readlink "${FILE}")" + if [ -z "${FILE}" ]; then + # the readlink is empty means we've arrived at the script, let's canonicalize with pwd + FILE="$(cd "$(dirname "${PREVFILE}")" &> /dev/null && pwd -P)"/"$(basename "${PREVFILE}")" + FOUND=1 + elif [ "${FILE#/}" = "${FILE}" ]; then + # FILE is not an absolute path link, we need to add the relative path to the previous dir + FILE="$(dirname "${PREVFILE}")/${FILE}" + fi + C=$((C+1)) + done + if [ "${FOUND}" -ne 1 ]; then + echo "Could not determine path to actual file '$(basename "${FINDFILE}")'" >&2 + exit 1 + fi + echo "${FILE}" +} + +ISMACOS=0 +if [ "$( uname -s )" = "Darwin" ]; then + ISMACOS=1 +fi + +declare -a JVMARGS=() + +# set vars for being inside the macos App Bundle +if [ "${ISMACOS}" = 1 ]; then +# MACOS ONLY + DIR="$(dirname "$(readlinkf "$0")")" + APP="${DIR%.app/Contents/*}".app + if [ "${APP}" = "${APP%.app}" ]; then + echo "Could not find Jalview.app" >&2 + exit 2 + fi + APPDIR="${APP}/Contents/Resources/app" + JAVA="${APPDIR}/jre/Contents/Home/bin/java" + JVMARGS=( "${JVMARGS[@]}" "-Xdock:icon=${APPDIR}/resource/jalview_logo.png" ) +else +# NOT MACOS + DIR="$(dirname "$(readlink -f "$0")")" + APPDIR="${DIR}" + JAVA="${APPDIR}/jre/bin/java" fi -APPDIR="${DIR}" -JAVA="${APPDIR}/jre/bin/java" +SYSJAVA=java GETDOWNTXT="${APPDIR}/getdown.txt" + CLASSPATH="" +# save an array of JAR paths in case we're in WSL (see later) +declare -a JARPATHS=() if [ -e "${GETDOWNTXT}" ]; then + # always check grep and sed regexes on macos -- they're not the same for JAR in $(grep -e '^code\s*=\s*' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:" CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}" + JARPATHS=( "${JARPATHS[@]}" "${APPDIR}/${JAR}" ) done else echo "Cannot find getdown.txt" >&2 exit 3 fi +# WINDOWS ONLY (Cygwin or WSL) +# change paths for Cygwin or Windows Subsystem for Linux (WSL) +if [ "${ISMACOS}" != 1 ]; then # macos doesn't like uname -o, best to avoid + if [ "$(uname -o)" = "Cygwin" ]; then + # CYGWIN + echo "When using relative paths in args within Cygwin, please start with './' or '../'" >&2 + CLASSPATH=$(cygpath -pw "${CLASSPATH}") + # now for some arg paths fun. only translating paths starting with './', '../' or '/' + ARGS=() + for ARG in "${@}"; do + if [ "${ARG}" != "${ARG#./}" -o "${ARG}" != "${ARG#/}" -o "${ARG}" != "${ARG#../}" ]; then + ARGS=( "${ARGS[@]}" "$(cygpath -aw "${ARG}")" ) + else + ARGS=( "${ARGS[@]}" "${ARG}" ) + fi + done + elif uname -r | grep Microsoft >/dev/null; then + # WSL + echo "When using relative paths in args within WSL, please start with './' or '../'" >&2 + CLASSPATH="" + for JARPATH in "${JARPATHS[@]}"; do + [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH};" + CLASSPATH="${CLASSPATH}$(wslpath -aw "${JARPATH}")" + done + ARGS=() + for ARG in "${@}"; do + if [ "${ARG}" != "${ARG#./}" -o "${ARG}" != "${ARG#/}" -o "${ARG}" != "${ARG#../}" ]; then + # annoyingly wslpath does not work if the file doesn't exist! + ARGBASENAME="$(basename "${ARG}")" + ARGDIRNAME="$(dirname "${ARG}")" + ARGS=( "${ARGS[@]}" "$(wslpath -aw "${ARGDIRNAME}")\\${ARGBASENAME}" ) + else + ARGS=( "${ARGS[@]}" "${ARG}" ) + fi + done + JAVA="${JAVA}.exe" + SYSJAVA="java.exe" + fi +fi + +# Is there a bundled Java? If not just try one in the PATH (do need .exe in WSL) if [ \! -e "${JAVA}" ]; then - echo "Cannot find bundled java, using system and hoping for the best!" >&2 - JAVA=java + JAVA=$SYSJAVA + echo "Cannot find bundled java, using system ${JAVA} and hoping for the best!" >&2 +fi + +# check to see if $1 is set and is not start of other cli args +OPEN="" +if [ -n "${ARG1}" -a "${ARG1}" = "${ARG1#-}" -a "${ARG1}" != "open" ]; then + # first argument exists and does not start with a "-" and is not "open" + OPEN="-open" fi -# don't quote $OPEN -"${JAVA}" -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "$@" +# don't quote $OPEN (don't want it accidentally mistaken as an empty string arg!) +"${JAVA}" "${JVMARGS[@]}" -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "${ARGS[@]}" diff --git a/utils/getdown/jalviewc-macos b/utils/getdown/jalviewc-macos deleted file mode 100755 index e34685d..0000000 --- a/utils/getdown/jalviewc-macos +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env bash - -ARG1="$1" - -# this whole next part is because there's no readlink -f in Darwin -function readlinkf() { - FINDFILE="$1" - FILE="${FINDFILE}" - PREVFILE="" - C=0 - MAX=100 # just in case we end up in a loop - FOUND=0 - while [ "${C}" -lt "${MAX}" -a "${FILE}" != "${PREVFILE}" -a "${FOUND}" -ne 1 ]; do - PREVFILE="${FILE}" - FILE="$(readlink "${FILE}")" - if [ -z "${FILE}" ]; then - # the readlink is empty means we've arrived at the script, let's canonicalize with pwd - FILE="$(cd "$(dirname "${PREVFILE}")" &> /dev/null && pwd -P)"/"$(basename "${PREVFILE}")" - FOUND=1 - elif [ "${FILE#/}" = "${FILE}" ]; then - # FILE is not an absolute path link, we need to add the relative path to the previous dir - FILE="$(dirname "${PREVFILE}")/${FILE}" - fi - C=$((C+1)) - done - if [ "${FOUND}" -ne 1 ]; then - echo "Could not determine path to actual file '$(basename "${FINDFILE}")'" >&2 - exit 1 - fi - echo "${FILE}" -} - -DIR="$(dirname "$(readlinkf "$0")")" -APP="${DIR%.app/Contents/*}".app - -if [ "${APP}" = "${APP%.app}" ]; then - echo "Could not find Jalview.app dir" >&2 - exit 2 -fi - -# check to see if $1 is set and is not start of other cli set args -OPEN="" -if [ -n "${ARG1}" -a "${ARG1}" = "${ARG1#-}" -a "${ARG1}" != "open" ]; then - # first argument exists and does not start with a "-" and is not "open" - OPEN="-open" -fi - -APPDIR="${APP}/Contents/Resources/app" -JAVA="${APPDIR}/jre/Contents/Home/bin/java" -GETDOWNTXT="${APPDIR}/getdown.txt" -CLASSPATH="" -if [ -e "${GETDOWNTXT}" ]; then - # always check grep and sed regexes on macOS -- they're not the same - for JAR in $(grep -e '^code\s*=\s*' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do - [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:" - CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}" - done -else - echo "Cannot find getdown.txt" >&2 - exit 3 -fi - -if [ \! -e "${JAVA}" ]; then - echo "Cannot find bundled java, using system and hoping for the best!" >&2 - JAVA=java -fi - -# don't quote $OPEN -"${JAVA}" -Xdock:icon="${APPDIR}"/resource/jalview_logo.png -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "$@" diff --git a/utils/getdown/jalviewc-windows b/utils/getdown/jalviewc-windows deleted file mode 100755 index 2f0f968..0000000 --- a/utils/getdown/jalviewc-windows +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env bash - -ARG1=$1 -DIR="$(dirname "$(readlink -f "$0")")" - -# check to see if $1 is set and is not start of other cli set args -OPEN="" -if [ -n "${ARG1}" -a "${ARG1}" = "${ARG1#-}" -a "${ARG1}" != "open" ]; then - # first argument exists and does not start with a "-" and is not "open" - OPEN="-open" -fi - -APPDIR="${DIR}" -JAVA="${APPDIR}/jre/bin/java" -GETDOWNTXT="${APPDIR}/getdown.txt" -CLASSPATH="" -if [ -e "${GETDOWNTXT}" ]; then - for JAR in $(grep -e '^code\s*=\s*' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do - [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:" - CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}" - done -else - echo "Cannot find getdown.txt" >&2 - exit 3 -fi - -if [ \! -e "${JAVA}" ]; then - echo "Cannot find bundled java, using system and hoping for the best!" >&2 - JAVA=java -fi - -declare -a ARGS=("${@}") - -# change paths for Cygwin or Windows Subsystem for Linux (WSL) -if [ "$(uname -o)" = "Cygwin" ]; then - echo "When using relative paths in args within Cygwin, please start with './' or '../'" >&2 - CLASSPATH=$(cygpath -pw "${CLASSPATH}") - # now for some arg paths fun. only translating paths starting with './', '../' or '/' - ARGS=() - for ARG in "${@}"; do - if [ "${ARG}" != "${ARG#./}" -o "${ARG}" != "${ARG#/}" -o "${ARG}" != "${ARG#../}" ]; then - ARGS=( "${ARGS[@]}" "$(cygpath -aw "${ARG}")" ) - else - ARGS=( "${ARGS[@]}" "${ARG}" ) - fi - done - JAVA="${JAVA}.exe" -elif uname -r | grep Microsoft >/dev/null; then - echo "When using relative paths in args within WSL. please start with './' or '../'" >&2 - WCLASSPATH="" - OLD_IFS="${IFS}" - IFS=":" - for JAR in $CLASSPATH; do - [ -n "${WCLASSPATH}" ] && WCLASSPATH="${WCLASSPATH};" - WCLASSPATH="${WCLASSPATH}$(wslpath -aw "${JAR}")" - done - CLASSPATH="${WCLASSPATH}" - IFS="${OLD_IFS}" - ARGS=() - for ARG in "${@}"; do - if [ "${ARG}" != "${ARG#./}" -o "${ARG}" != "${ARG#/}" -o "${ARG}" != "${ARG#../}" ]; then - # annoyingly wslpath does not work if the file doesn't exist! - ARGBASENAME="$(basename "${ARG}")" - ARGDIRNAME="$(dirname "${ARG}")" - ARGS=( "${ARGS[@]}" "$(wslpath -aw "${ARGDIRNAME}")\\${ARGBASENAME}" ) - else - ARGS=( "${ARGS[@]}" "${ARG}" ) - fi - done - JAVA="${JAVA}.exe" -fi - -# don't quote $OPEN -"${JAVA}" -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "${ARGS[@]}" diff --git a/utils/install4j/install4j8_template.install4j b/utils/install4j/install4j8_template.install4j index 0ab7fad..f81bab8 100644 --- a/utils/install4j/install4j8_template.install4j +++ b/utils/install4j/install4j8_template.install4j @@ -107,15 +107,11 @@ - - - - @@ -717,7 +713,7 @@ return console.askYesNo(message, true); - + jre @@ -905,39 +901,19 @@ return console.askYesNo(message, true); - jalviewc-macos - - - - jalviewc.ps1 - + jalviewcv - - - jalviewc-macosv - - - + jalviewc.ps1v - - - jalviewc-windows - - - - - jalviewc-windowsv - -