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
18 ZULU_BASE=https://cdn.azul.com/zulu/bin
28 STRIP_MAC_APP_BUNDLING=false
29 # archives not needed for JDKs
31 # need zip with top-level jre dir for getdown updates. need tgz without top-level jre dir for install4j bundling
35 # unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
39 local temp=$(mktemp -d) && $UNZIP -qq -d "$temp" "$zip" && mkdir -p "$dest" &&
40 shopt -s dotglob && local f=("$temp"/*) &&
41 if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
42 mv "$temp"/*/* "$dest"
45 fi && rmdir "$temp"/* "$temp"
58 echo "- Looking for download from Azul"
59 LATEST_DL_URL_FILE=$(wget -q -O - "${ZULU_BASE}/" | perl -n -e 'm/<a\b[^>]*href="(([^"]*\/)?zulu[^"]*-ca-'"${IMAGE_TYPE}""${VERSION}"'\.[^"]*-'"${ZOS}"'_'"${ARCH}"'.tar.gz)"[^"]*>/ && print "$1\n";' | tail -1)
60 local URL="${ZULU_BASE}/${LATEST_DL_URL_FILE}"
61 if [ -z "${LATEST_DL_URL_FILE}" ]; then
62 echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}' found at Azul"
65 echo "- Found at Azul. Downloading '${URL}'"
66 wget -q -O "${TARFILE}" "${URL}" "${TARFILE}"
68 if [ "$?" != 0 ]; then
69 echo "- Download from Azul failed"
75 declare -A DOWNLOAD_SUMMARY
77 for FEATURE_VERSION in 8 11 17; do
78 for OS_ARCH in mac:x64 mac:aarch64 windows:x64 linux:x64 linux:arm linux:aarch64; do
81 NAME="${IMAGE_TYPE}-${FEATURE_VERSION}-${OS}-${ARCH}"
83 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="None"
85 MAC_STRIP_COMPONENTS=3
86 echo "* Downloading ${TARFILE}"
87 URL="${BASE}/${FEATURE_VERSION}/${RELEASE_TYPE}/${OS}/${ARCH}/${IMAGE_TYPE}/${JVM_IMPL}/${HEAP_SIZE}/${VENDOR}"
88 wget -q -O "${TARFILE}" "${URL}"
89 if [ "$?" != 0 ]; then
90 echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}' at Adoptium"
93 # Try Azul Zulu (not an API, a bit messier, but has Java 8 JRE for mac:aarch64
94 dl_zulu "${OS}" "${ARCH}" "${FEATURE_VERSION}" "${TARFILE}"
96 if [ "$?" != 0 ]; then
97 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="None"
101 MAC_STRIP_COMPONENTS=4
102 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="Azul"
103 echo "Set ${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}=Azul"
105 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="Adoptium"
106 echo "Set ${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}=Adoptium"
108 echo "Unpacking ${TARFILE}"
109 JREDIR="${NAME}/${IMAGE_TYPE}"
110 [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
112 if [ x$OS = xwindows ]; then
114 unzip-strip "${TARFILE}" "${JREDIR}"
118 if [ x$OS = xmac -a x$STRIP_MAC_APP_BUNDLING = xtrue ]; then
119 echo "Running $TAR --strip-components=\"${MAC_STRIP_COMPONENTS}\" -C \"${JREDIR}\" -zxf \"${TARFILE}\" \"*/Contents/Home\""
120 $TAR --strip-components="${MAC_STRIP_COMPONENTS}" -C "${JREDIR}" -zxf "${TARFILE}" "*/Contents/Home"
123 $TAR --strip-components="${STRIP_COMPONENTS}" -C "${JREDIR}" -zxf "${TARFILE}"
127 if [ "$RET" != 0 ]; then
128 echo "Error unpacking ${TARFILE}"
132 if [ \! -z "$CREATE_ARCHIVES" ]; then
133 for CREATEARCHIVE in ${CREATE_ARCHIVES}; do
134 ARCHIVEDIR=$CREATEARCHIVE
135 case $CREATEARCHIVE in
138 echo "Creating ${NAME}.${EXT} for getdown updates"
139 [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
140 ABSARCHIVEDIR="${PWD}/$ARCHIVEDIR"
141 ZIPFILE="${ABSARCHIVEDIR}/${NAME}.${CREATEARCHIVE}"
142 [ -e "${ZIPFILE}" ] && $RM "${ZIPFILE}"
144 $ZIP -X -r "${ZIPFILE}" "${IMAGE_TYPE}"
149 echo "Creating ${NAME}.${EXT} for install4j bundling"
150 [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
151 $TAR -C "${JREDIR}" -zcf "${ARCHIVEDIR}/${NAME}.${EXT}" .
152 # make symbolic link with _ instead of - for install4j9
154 echo "Linking from ${NEWNAME}.${EXT} for install4j9"
155 [ -e "${ARCHIVEDIR}/${NEWNAME}.${EXT}" ] && $RM "${ARCHIVEDIR}/${NEWNAME}.${EXT}"
156 ln -s "${NAME}.${EXT}" "${ARCHIVEDIR}/${NEWNAME}.${EXT}"
159 echo "Archiving as '${CREATEARCHIVE}' file not supported"
168 echo "Download Summary"
169 for OA in "${!DOWNLOAD_SUMMARY[@]}"; do
170 echo "$OA: ${DOWNLOAD_SUMMARY[$OA]}"