JAL-3130 Improved locations of AdoptOpenJDK JRE downloads \(locally and on build...
[jalview.git] / utils / install4j / download_jres.sh
1 #!/usr/bin/env bash
2
3 # 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_
4
5
6 ### bs 2020-01-22
7 ### This is a script to download and update the JREs used in the windows, mac (and maybe linux) installations, and update channel
8 ### It creates a structure with
9 ### ./jre-VERSION-OS-ARCH/jre/...
10 ### as used by getdown
11 ### and
12 ### ./tgz/jre-VERSION-OS-ARCH.tgz
13 ### which is an archive of the _contents_ of ./jre-VERSION-OS-ARCH/jre/ and used by install4j for the installer
14
15 BASE=https://api.adoptopenjdk.net/v3/binary/latest
16 RELEASE_TYPE=ga
17 JVM_IMPL=hotspot
18 HEAP_SIZE=normal
19 VENDOR=adoptopenjdk
20 IMAGE_TYPE=jre
21
22 RM=/bin/rm
23
24 # unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
25 unzip-strip() (
26   local zip=$1
27   local dest=${2:-.}
28   local temp=$(mktemp -d) && unzip -qq -d "$temp" "$zip" && mkdir -p "$dest" &&
29   shopt -s dotglob && local f=("$temp"/*) &&
30   if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
31     mv "$temp"/*/* "$dest"
32   else
33     mv "$temp"/* "$dest"
34   fi && rmdir "$temp"/* "$temp"
35 )
36
37 for FEATURE_VERSION in 8 11; do
38   for OS in linux mac windows; do
39     for ARCH in x64 x32 arm; do
40       #for ARCH in aarch64 arm x32 x64; do
41       NAME="${IMAGE_TYPE}-${FEATURE_VERSION}-${OS}-${ARCH}"
42       TARFILE="${NAME}.tgz"
43       echo "* Downloading ${TARFILE}"
44       URL="${BASE}/${FEATURE_VERSION}/${RELEASE_TYPE}/${OS}/${ARCH}/${IMAGE_TYPE}/${JVM_IMPL}/${HEAP_SIZE}/${VENDOR}"
45       wget -q -O "${TARFILE}" "${URL}"
46       if [ "$?" != 0 ]; then
47         echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}'"
48         $RM -f "${TARFILE}"
49         continue;
50       fi
51       echo "Unpacking ${TARFILE}"
52       JREDIR="${NAME}/jre"
53       [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
54       mkdir -p "${JREDIR}"
55       if [ x$OS = xwindows ]; then
56         echo "using unzip"
57         unzip-strip "${TARFILE}" "${JREDIR}"
58         RET=$?
59       else
60         echo "using tar"
61         tar --strip-components=1 -C "${JREDIR}" -zxf "${TARFILE}"
62         RET=$?
63       fi
64       if [ "$RET" != 0 ]; then
65         echo "Error unpacking ${TARFILE}"
66         exit 1
67       fi
68       $RM "${TARFILE}"
69       echo "Creating .tar.gz for install4j bundling and updates"
70       TGZDIR=tgz
71       mkdir -p "${TGZDIR}"
72       tar -C "${JREDIR}" -zcf "${TGZDIR}/${NAME}.tar.gz" .
73     done
74   done
75 done
76