JAL-3227 helper shell scripts for setting up a build environment
authorBen Soares <bsoares@dundee.ac.uk>
Thu, 13 Feb 2020 17:12:35 +0000 (17:12 +0000)
committerBen Soares <bsoares@dundee.ac.uk>
Thu, 13 Feb 2020 17:12:35 +0000 (17:12 +0000)
utils/download_jdks.sh [new file with mode: 0755]
utils/download_jres.sh [moved from utils/install4j/download_jres.sh with 87% similarity]

diff --git a/utils/download_jdks.sh b/utils/download_jdks.sh
new file mode 100755 (executable)
index 0000000..c488d80
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+
+# see https://api.adoptopenjdk.net/swagger-ui/#/Binary/get_v3_binary_latest__feature_version___release_type___os___arch___image_type___jvm_impl___heap_size___vendor_
+
+
+### bs 2020-01-22
+### This is a script to download and update the JREs used in the windows, mac (and maybe linux) installations, and update channel
+### It creates a structure with
+### ./jre-VERSION-OS-ARCH/jre/...
+### as used by getdown
+### and
+### ./tgz/jre-VERSION-OS-ARCH.tgz
+### which is an archive of the _contents_ of ./jre-VERSION-OS-ARCH/jre/ and used by install4j for the installer
+
+BASE=https://api.adoptopenjdk.net/v3/binary/latest
+RELEASE_TYPE=ga
+JVM_IMPL=hotspot
+HEAP_SIZE=normal
+VENDOR=adoptopenjdk
+IMAGE_TYPE=jdk
+
+RM=/bin/rm
+
+# unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
+unzip-strip() (
+  local zip=$1
+  local dest=${2:-.}
+  local temp=$(mktemp -d) && unzip -qq -d "$temp" "$zip" && mkdir -p "$dest" &&
+  shopt -s dotglob && local f=("$temp"/*) &&
+  if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
+    mv "$temp"/*/* "$dest"
+  else
+    mv "$temp"/* "$dest"
+  fi && rmdir "$temp"/* "$temp"
+)
+
+for FEATURE_VERSION in 8 11 12 13; do
+  for OS in mac; do
+  #for OS in linux mac windows; do
+    for ARCH in x64; do
+    #for ARCH in aarch64 arm x32 x64; do
+      NAME="${IMAGE_TYPE}-${FEATURE_VERSION}-${OS}-${ARCH}"
+      TARFILE="${NAME}.tgz"
+      echo "* Downloading ${TARFILE}"
+      URL="${BASE}/${FEATURE_VERSION}/${RELEASE_TYPE}/${OS}/${ARCH}/${IMAGE_TYPE}/${JVM_IMPL}/${HEAP_SIZE}/${VENDOR}"
+      wget -q -O "${TARFILE}" "${URL}"
+      if [ "$?" != 0 ]; then
+        echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}'"
+        $RM -f "${TARFILE}"
+        continue;
+      fi
+      echo "Unpacking ${TARFILE}"
+      JREDIR="${NAME}/${IMAGE_TYPE}"
+      [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
+      mkdir -p "${JREDIR}"
+      if [ x$OS = xwindows ]; then
+        echo "using unzip"
+        unzip-strip "${TARFILE}" "${JREDIR}"
+        RET=$?
+      else
+        echo "using tar"
+        tar --strip-components=1 -C "${JREDIR}" -zxf "${TARFILE}"
+        RET=$?
+      fi
+      if [ "$RET" != 0 ]; then
+        echo "Error unpacking ${TARFILE}"
+        exit 1
+      fi
+      $RM "${TARFILE}"
+    done
+  done
+done
+
similarity index 87%
rename from utils/install4j/download_jres.sh
rename to utils/download_jres.sh
index 0a1cf9f..8b8abc3 100755 (executable)
@@ -19,6 +19,8 @@ HEAP_SIZE=normal
 VENDOR=adoptopenjdk
 IMAGE_TYPE=jre
 
+STRIP_MAC_APP_BUNDLING=false
+
 RM=/bin/rm
 
 # unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
@@ -49,7 +51,7 @@ for FEATURE_VERSION in 8 11; do
         continue;
       fi
       echo "Unpacking ${TARFILE}"
-      JREDIR="${NAME}/jre"
+      JREDIR="${NAME}/${IMAGE_TYPE}"
       [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
       mkdir -p "${JREDIR}"
       if [ x$OS = xwindows ]; then
@@ -58,8 +60,13 @@ for FEATURE_VERSION in 8 11; do
         RET=$?
       else
         echo "using tar"
-        tar --strip-components=1 -C "${JREDIR}" -zxf "${TARFILE}"
-        RET=$?
+        if [ x$OS = xmac -a x$STRIP_MAC_APP_BUNDLING = xtrue ]; then
+          tar --strip-components=3 -C "${JREDIR}" -zxf "${TARFILE}" "*/Contents/Home"
+          RET=$?
+        else
+          tar --strip-components=1 -C "${JREDIR}" -zxf "${TARFILE}"
+          RET=$?
+        fi
       fi
       if [ "$RET" != 0 ]; then
         echo "Error unpacking ${TARFILE}"