JAL-3394 Made Categories line configurable/readable in gradle.properties as will...
[jalview.git] / utils / 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 STRIP_MAC_APP_BUNDLING=false
23 CREATE_ARCHIVES="zip tgz"
24 # need zip with top-level jre dir for getdown updates. need tgz without top-level jre dir for install4j bundling
25
26 RM=/bin/rm
27
28 # unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
29 unzip-strip() (
30   local zip=$1
31   local dest=${2:-.}
32   local temp=$(mktemp -d) && unzip -qq -d "$temp" "$zip" && mkdir -p "$dest" &&
33   shopt -s dotglob && local f=("$temp"/*) &&
34   if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
35     mv "$temp"/*/* "$dest"
36   else
37     mv "$temp"/* "$dest"
38   fi && rmdir "$temp"/* "$temp"
39 )
40
41 for FEATURE_VERSION in 8 11; do
42   for OS in linux mac windows; do
43     for ARCH in x64 x32 arm; do
44       #for ARCH in aarch64 arm x32 x64; do
45       NAME="${IMAGE_TYPE}-${FEATURE_VERSION}-${OS}-${ARCH}"
46       TARFILE="${NAME}.tgz"
47       echo "* Downloading ${TARFILE}"
48       URL="${BASE}/${FEATURE_VERSION}/${RELEASE_TYPE}/${OS}/${ARCH}/${IMAGE_TYPE}/${JVM_IMPL}/${HEAP_SIZE}/${VENDOR}"
49       wget -q -O "${TARFILE}" "${URL}"
50       if [ "$?" != 0 ]; then
51         echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}'"
52         $RM -f "${TARFILE}"
53         continue;
54       fi
55       echo "Unpacking ${TARFILE}"
56       JREDIR="${NAME}/${IMAGE_TYPE}"
57       [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
58       mkdir -p "${JREDIR}"
59       if [ x$OS = xwindows ]; then
60         echo "using unzip"
61         unzip-strip "${TARFILE}" "${JREDIR}"
62         RET=$?
63       else
64         echo "using tar"
65         if [ x$OS = xmac -a x$STRIP_MAC_APP_BUNDLING = xtrue ]; then
66           tar --strip-components=3 -C "${JREDIR}" -zxf "${TARFILE}" "*/Contents/Home"
67           RET=$?
68         else
69           tar --strip-components=1 -C "${JREDIR}" -zxf "${TARFILE}"
70           RET=$?
71         fi
72       fi
73       if [ "$RET" != 0 ]; then
74         echo "Error unpacking ${TARFILE}"
75         exit 1
76       fi
77       $RM "${TARFILE}"
78       if [ \! -z "$CREATE_ARCHIVES" ]; then
79         for CREATEARCHIVE in ${CREATE_ARCHIVES}; do
80           ARCHIVEDIR=$CREATEARCHIVE
81           case $CREATEARCHIVE in
82             zip)
83               EXT=${CREATEARCHIVE}
84               echo "Creating ${NAME}.${EXT} for getdown updates"
85               [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
86               ABSARCHIVEDIR="${PWD}/$ARCHIVEDIR"
87               ZIPFILE="${ABSARCHIVEDIR}/${NAME}.${CREATEARCHIVE}"
88               [ -e "${ZIPFILE}" ] && $RM "${ZIPFILE}"
89               cd ${NAME}
90               zip -X -r "${ZIPFILE}" "${IMAGE_TYPE}"
91               cd -
92               ;;
93             tgz)
94               EXT=tar.gz
95               echo "Creating ${NAME}.${EXT} for install4j bundling"
96               [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
97               tar -C "${JREDIR}" -zcf "${ARCHIVEDIR}/${NAME}.${EXT}" .
98               ;;
99             *)
100               echo "Archiving as '${CREATEARCHIVE}' file not supported"
101               ;;
102           esac
103         done
104       fi
105     done
106   done
107 done
108