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_
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
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
15 ### Edited to use adoptium domain to gain access to Java 17 (LTS) versions.
17 BASE=https://api.adoptium.net/v3/binary/latest
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
33 # unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
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"
43 fi && rmdir "$temp"/* "$temp"
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
50 NAME="${IMAGE_TYPE}-${FEATURE_VERSION}-${OS}-${ARCH}"
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}'"
60 echo "Unpacking ${TARFILE}"
61 JREDIR="${NAME}/${IMAGE_TYPE}"
62 [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
64 if [ x$OS = xwindows ]; then
66 unzip-strip "${TARFILE}" "${JREDIR}"
70 if [ x$OS = xmac -a x$STRIP_MAC_APP_BUNDLING = xtrue ]; then
71 $TAR --strip-components=3 -C "${JREDIR}" -zxf "${TARFILE}" "*/Contents/Home"
74 $TAR --strip-components=1 -C "${JREDIR}" -zxf "${TARFILE}"
78 if [ "$RET" != 0 ]; then
79 echo "Error unpacking ${TARFILE}"
83 if [ \! -z "$CREATE_ARCHIVES" ]; then
84 for CREATEARCHIVE in ${CREATE_ARCHIVES}; do
85 ARCHIVEDIR=$CREATEARCHIVE
86 case $CREATEARCHIVE in
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}"
95 $ZIP -X -r "${ZIPFILE}" "${IMAGE_TYPE}"
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
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}"
110 echo "Archiving as '${CREATEARCHIVE}' file not supported"