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