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 CREATE_ARCHIVES="zip tgz"
30 # need zip with top-level jre dir for getdown updates. need tgz without top-level jre dir for install4j bundling
34 # unzip-strip from https://superuser.com/questions/518347/equivalent-to-tars-strip-components-1-in-unzip
38 local temp=$(mktemp -d) && $UNZIP -qq -d "$temp" "$zip" && mkdir -p "$dest" &&
39 shopt -s dotglob && local f=("$temp"/*) &&
40 if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
41 mv "$temp"/*/* "$dest"
44 fi && rmdir "$temp"/* "$temp"
57 echo "- Looking for download from Azul"
58 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)
59 local URL="${ZULU_BASE}/${LATEST_DL_URL_FILE}"
60 if [ -z "${LATEST_DL_URL_FILE}" ]; then
61 echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}' found at Azul"
64 echo "- Found at Azul. Downloading '${URL}'"
65 wget -q -O "${TARFILE}" "${URL}" "${TARFILE}"
67 if [ "$?" != 0 ]; then
68 echo "- Download from Azul failed"
74 declare -A DOWNLOAD_SUMMARY
76 for FEATURE_VERSION in 8 11 17; do
77 for OS_ARCH in mac:x64 mac:aarch64 windows:x64 linux:x64 linux:arm linux:aarch64; do
80 NAME="${IMAGE_TYPE}-${FEATURE_VERSION}-${OS}-${ARCH}"
82 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="None"
84 MAC_STRIP_COMPONENTS=3
85 echo "* Downloading ${TARFILE}"
86 URL="${BASE}/${FEATURE_VERSION}/${RELEASE_TYPE}/${OS}/${ARCH}/${IMAGE_TYPE}/${JVM_IMPL}/${HEAP_SIZE}/${VENDOR}"
87 wget -q -O "${TARFILE}" "${URL}"
88 if [ "$?" != 0 ]; then
89 echo "- No ${IMAGE_TYPE}-${FEATURE_VERSION} download for ${OS}-${ARCH} '${URL}' at Adoptium"
92 # Try Azul Zulu (not an API, a bit messier, but has Java 8 JRE for mac:aarch64
93 dl_zulu "${OS}" "${ARCH}" "${FEATURE_VERSION}" "${TARFILE}"
95 if [ "$?" != 0 ]; then
96 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="None"
100 MAC_STRIP_COMPONENTS=4
101 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="Azul"
102 echo "Set ${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}=Azul"
104 DOWNLOAD_SUMMARY["${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}"]="Adoptium"
105 echo "Set ${OS_ARCH}-${IMAGE_TYPE}-${FEATURE_VERSION}=Adoptium"
107 echo "Unpacking ${TARFILE}"
108 JREDIR="${NAME}/${IMAGE_TYPE}"
109 [ x$NAME != x -a -e "${JREDIR}" ] && $RM -rf "${JREDIR}"
111 if [ x$OS = xwindows ]; then
113 unzip-strip "${TARFILE}" "${JREDIR}"
117 if [ x$OS = xmac -a x$STRIP_MAC_APP_BUNDLING = xtrue ]; then
118 echo "Running $TAR --strip-components=\"${MAC_STRIP_COMPONENTS}\" -C \"${JREDIR}\" -zxf \"${TARFILE}\" \"*/Contents/Home\""
119 $TAR --strip-components="${MAC_STRIP_COMPONENTS}" -C "${JREDIR}" -zxf "${TARFILE}" "*/Contents/Home"
122 $TAR --strip-components="${STRIP_COMPONENTS}" -C "${JREDIR}" -zxf "${TARFILE}"
126 if [ "$RET" != 0 ]; then
127 echo "Error unpacking ${TARFILE}"
131 if [ \! -z "$CREATE_ARCHIVES" ]; then
132 for CREATEARCHIVE in ${CREATE_ARCHIVES}; do
133 ARCHIVEDIR=$CREATEARCHIVE
134 case $CREATEARCHIVE in
137 echo "Creating ${NAME}.${EXT} for getdown updates"
138 [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
139 ABSARCHIVEDIR="${PWD}/$ARCHIVEDIR"
140 ZIPFILE="${ABSARCHIVEDIR}/${NAME}.${CREATEARCHIVE}"
141 [ -e "${ZIPFILE}" ] && $RM "${ZIPFILE}"
143 $ZIP -X -r "${ZIPFILE}" "${IMAGE_TYPE}"
148 echo "Creating ${NAME}.${EXT} for install4j bundling"
149 [ \! -d ${ARCHIVEDIR} ] && mkdir -p "${ARCHIVEDIR}"
150 if [ x$OS = xmac ]; then
151 # install4j requires top level folder of "Contents" NOT "./Contents"
152 $TAR -C "${JREDIR}" -zcf "${ARCHIVEDIR}/${NAME}.${EXT}" Contents
154 $TAR -C "${JREDIR}" -zcf "${ARCHIVEDIR}/${NAME}.${EXT}" .
156 # make symbolic link with _ instead of - for install4j9
158 echo "Linking from ${NEWNAME}.${EXT} for install4j9"
159 [ -e "${ARCHIVEDIR}/${NEWNAME}.${EXT}" ] && $RM "${ARCHIVEDIR}/${NEWNAME}.${EXT}"
160 ln -s "${NAME}.${EXT}" "${ARCHIVEDIR}/${NEWNAME}.${EXT}"
163 echo "Archiving as '${CREATEARCHIVE}' file not supported"
172 echo "Download Summary"
173 for OA in "${!DOWNLOAD_SUMMARY[@]}"; do
174 echo "$OA: ${DOWNLOAD_SUMMARY[$OA]}"