JAL-4026 update the viewport’s wrapped width after calculating it
[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 ### bs 2021-10-26
15 ### Edited to use adoptium domain to gain access to Java 17 (LTS) versions.
16
17 BASE=https://api.adoptium.net/v3/binary/latest
18 RELEASE_TYPE=ga
19 JVM_IMPL=hotspot
20 HEAP_SIZE=normal
21 VENDOR=eclipse
22 IMAGE_TYPE=jre
23 TAR=tar
24 ZIP=zip
25 UNZIP=unzip
26
27 STRIP_MAC_APP_BUNDLING=false
28 CREATE_ARCHIVES="zip tgz"
29 # need zip with top-level jre dir for getdown updates. need tgz without top-level jre dir for install4j bundling
30
31 RM=/bin/rm
32
33 # unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
34 unzip-strip() (
35   local zip=$1
36   local dest=${2:-.}
37   local temp=$(mktemp -d) && $UNZIP -qq -d "$temp" "$zip" && mkdir -p "$dest" &&
38   shopt -s dotglob && local f=("$temp"/*) &&
39   if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
40     mv "$temp"/*/* "$dest"
41   else
42     mv "$temp"/* "$dest"
43   fi && rmdir "$temp"/* "$temp"
44 )
45
46 for FEATURE_VERSION in 8 11 17; do
47   for OS_ARCH in mac:x64 mac:aarch64 windows:x64 linux:x64 linux:arm linux:aarch64; do
48     OS=${OS_ARCH%:*}
49     ARCH=${OS_ARCH#*:}
50     NAME="${IMAGE_TYPE}-${FEATURE_VERSION}-${OS}-${ARCH}"
51     TARFILE="${NAME}.tgz"
52     echo "* Downloading ${TARFILE}"
53     URL="${BASE}/${FEATURE_VERSION}/${RELEASE_TYPE}/${OS}/${ARCH}/${IMAGE_TYPE}/${JVM_IMPL}/${HEAP_SIZE}/${VENDOR}"
54     wget -q -O "${TARFILE}" "${URL}"
55     if [ "$?" != 0 ]; then
56       echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}'"
57       $RM -f "${TARFILE}"
58       continue;
59     fi
60     echo "Unpacking ${TARFILE}"
61     JREDIR="${NAME}/${IMAGE_TYPE}"
62     [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
63     mkdir -p "${JREDIR}"
64     if [ x$OS = xwindows ]; then
65       echo "using unzip"
66       unzip-strip "${TARFILE}" "${JREDIR}"
67       RET=$?
68     else
69       echo "using tar"
70       if [ x$OS = xmac -a x$STRIP_MAC_APP_BUNDLING = xtrue ]; then
71         $TAR --strip-components=3 -C "${JREDIR}" -zxf "${TARFILE}" "*/Contents/Home"
72         RET=$?
73       else
74         $TAR --strip-components=1 -C "${JREDIR}" -zxf "${TARFILE}"
75         RET=$?
76       fi
77     fi
78     if [ "$RET" != 0 ]; then
79       echo "Error unpacking ${TARFILE}"
80       exit 1
81     fi
82     $RM "${TARFILE}"
83     if [ \! -z "$CREATE_ARCHIVES" ]; then
84       for CREATEARCHIVE in ${CREATE_ARCHIVES}; do
85         ARCHIVEDIR=$CREATEARCHIVE
86         case $CREATEARCHIVE in
87           zip)
88             EXT=${CREATEARCHIVE}
89             echo "Creating ${NAME}.${EXT} for getdown updates"
90             [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
91             ABSARCHIVEDIR="${PWD}/$ARCHIVEDIR"
92             ZIPFILE="${ABSARCHIVEDIR}/${NAME}.${CREATEARCHIVE}"
93             [ -e "${ZIPFILE}" ] && $RM "${ZIPFILE}"
94             cd ${NAME}
95             $ZIP -X -r "${ZIPFILE}" "${IMAGE_TYPE}"
96             cd -
97             ;;
98           tgz)
99             EXT=tar.gz
100             echo "Creating ${NAME}.${EXT} for install4j bundling"
101             [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
102             $TAR -C "${JREDIR}" -zcf "${ARCHIVEDIR}/${NAME}.${EXT}" .
103             # make symbolic link with _ instead of - for install4j9
104             NEWNAME=${NAME//-/_}
105             echo "Linking from ${NEWNAME}.${EXT} for install4j9"
106             [ -e "${ARCHIVEDIR}/${NEWNAME}.${EXT}" ] && $RM "${ARCHIVEDIR}/${NEWNAME}.${EXT}"
107             ln -s "${NAME}.${EXT}" "${ARCHIVEDIR}/${NEWNAME}.${EXT}"
108             ;;
109           *)
110             echo "Archiving as '${CREATEARCHIVE}' file not supported"
111             ;;
112         esac
113       done
114     fi
115   done
116 done
117