From 9038c9b054cee6232692f51d9370ad707a0efceb Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 12 Mar 2021 18:26:29 +0000 Subject: [PATCH] JAL-3830 improved bash scripts. Added powershell script. Needs testing --- build.gradle | 2 +- gradle.properties | 1 + utils/getdown/jalviewc | 25 ++++++++++------- utils/getdown/jalviewc-macos | 63 ++++++++++++++++++++++++++++++++---------- utils/getdown/jalviewc.ps1 | 28 +++++++++++++++++++ 5 files changed, 94 insertions(+), 25 deletions(-) create mode 100644 utils/getdown/jalviewc.ps1 diff --git a/build.gradle b/build.gradle index 4930f94..0a27370 100644 --- a/build.gradle +++ b/build.gradle @@ -1573,7 +1573,7 @@ task getdownWebsite() { } } - def getdownWrapperScripts = [ getdown_mac_wrapper_script, getdown_unix_wrapper_script ] + def getdownWrapperScripts = [ getdown_mac_wrapper_script, getdown_unix_wrapper_script, getdown_windows_wrapper_script ] getdownWrapperScripts.each{ script -> def s = file( "${jalviewDir}/utils/getdown/${script}" ) if (s.exists()) { diff --git a/gradle.properties b/gradle.properties index 8157012..c4e9422 100644 --- a/gradle.properties +++ b/gradle.properties @@ -136,6 +136,7 @@ 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.ps1 OSX_KEYSTORE = OSX_KEYPASS = diff --git a/utils/getdown/jalviewc b/utils/getdown/jalviewc index a3fa66b..4792a9c 100755 --- a/utils/getdown/jalviewc +++ b/utils/getdown/jalviewc @@ -1,12 +1,11 @@ #!/usr/bin/env bash ARG1=$1 -WDIR="$( pwd )" -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +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 +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 @@ -14,15 +13,21 @@ fi APPDIR="${DIR}" JAVA="${APPDIR}/jre/bin/java" GETDOWNTXT="${APPDIR}/getdown.txt" -if [ -e "$GETDOWNTXT" ]; then - CLASSPATH="" - for x in $(grep -e 'code = ' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do - [ -n "$CLASSPATH" ] && CLASSPATH="${CLASSPATH}:" - CLASSPATH="${CLASSPATH}${APPDIR}/${x}" +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 1 + exit 3 fi -"$JAVA" -cp "$CLASSPATH" jalview.bin.Launcher $OPEN "$@" +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}" -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "$@" diff --git a/utils/getdown/jalviewc-macos b/utils/getdown/jalviewc-macos index 32748cb..e34685d 100755 --- a/utils/getdown/jalviewc-macos +++ b/utils/getdown/jalviewc-macos @@ -1,17 +1,46 @@ #!/usr/bin/env bash -ARG1=$1 -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -APP=${DIR%/Contents/*} +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 .app dir" >&2 - exit 1 + 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 +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 @@ -19,16 +48,22 @@ fi APPDIR="${APP}/Contents/Resources/app" JAVA="${APPDIR}/jre/Contents/Home/bin/java" GETDOWNTXT="${APPDIR}/getdown.txt" -# always check grep and sed regexes on macOS -- they're not the same -if [ -e "$GETDOWNTXT" ]; then - CLASSPATH="" - for x in $(grep -e 'code = ' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do - [ -n "$CLASSPATH" ] && CLASSPATH="${CLASSPATH}:" - CLASSPATH="${CLASSPATH}${APPDIR}/${x}" +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 1 + exit 3 +fi + +if [ \! -e "${JAVA}" ]; then + echo "Cannot find bundled java, using system and hoping for the best!" >&2 + JAVA=java fi -"$JAVA" -cp "$CLASSPATH" jalview.bin.Launcher $OPEN "$@" +# don't quote $OPEN +"${JAVA}" -Xdock:icon="${APPDIR}"/resource/jalview_logo.png -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "$@" diff --git a/utils/getdown/jalviewc.ps1 b/utils/getdown/jalviewc.ps1 new file mode 100644 index 0000000..ff4d6d8 --- /dev/null +++ b/utils/getdown/jalviewc.ps1 @@ -0,0 +1,28 @@ +# save first parameter +$ARGS = $args +$ARG1 = $args[0] +# parent dir of this script (should be the getdown app dir) +$DIR = Split-Path $MyInvocation.MyCommand.Path -Parent + +# insert an "-open" parameter to Jalview's ARGS if ARG1 is non-zero-length, and not "open" or starts with a "-" +if ( $ARG1.length -gt 0 -and (-not $ARG1.StartsWith("-")) -and $ARG1 -ne "open" ) { + $ARGS = "-open " + $ARGS +} + +$APPDIR = $DIR +$JAVA = "${APPDIR}/jre/bin/java.exe" +$GETDOWNTXT = "${APPDIR}/getdown.txt" + +if (-not (Test-Path -Path "${GETDOWNTXT}")) { + throw "Cannot find getdown.txt" +} + +if (-not (Test-Path -Path "${JAVA}")) { + Write-Host "Cannot find bundled java.exe. Using system and hoping for the best!" + $JAVA = "java.exe" +} + +$CLASSPATH = (Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { "$DIR/$($_.Matches.Groups[1].Value)" }) -join ":" + +Invoke-Expression -Command "${JAVA} -cp ${CLASSPATH} jalview.bin.Launcher $ARGS" + -- 1.7.10.2