Created
September 27, 2018 15:22
-
-
Save korzha/f9da7b89f82286b49077d2df9006455a to your computer and use it in GitHub Desktop.
Script to download and install AdoptOpenJDK 10 to /Library/Java/JavaVirtualMachines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Returns latest jdk 10 version, e.g. jdk-10.0.2+13 | |
JDK=$(curl --silent "https://api.github.com/repos/AdoptOpenJDK/openjdk10-releases/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') | |
# 10.0.2+13 | |
VERSION=$(basename "${JDK}" | awk -F"-" '{ print $2 }') | |
# 10.0.2 | |
SHORT_VERSION=$(echo "${VERSION}" | cut -f1 -d"+") | |
# 13 | |
BUILD=$(echo "${VERSION}" | cut -f2 -d"+") | |
# 10.0.2.13 | |
BUILD_VERSION="${SHORT_VERSION}.${BUILD}" | |
# 10.0 | |
PLATFORM_VERSION=$(echo "${VERSION}" | cut -f1-2 -d".") | |
# https://github.com/AdoptOpenJDK/openjdk10-releases/releases/download/jdk-10.0.2%2B13/OpenJDK10_x64_Mac_jdk-10.0.2.13.tar.gz | |
JDK_TARBALL_URL="https://github.com/AdoptOpenJDK/openjdk10-releases/releases/download/jdk-${SHORT_VERSION}%2B${BUILD}/OpenJDK10_x64_Mac_jdk-${BUILD_VERSION}.tar.gz" | |
INFO_PLIST_URL="https://gist.githubusercontent.com/nordligulv/765f4491956687fbed2e5948823d0a79/raw/c39efa7cbad5530598355efce2d26a97a7c053df/Info.plist" | |
WORKDIR=$(mktemp -d) | |
# Download latest jdk 10 and unzip it to Contents/Home | |
echo "Downloading ${JDK}" | |
mkdir -p "${WORKDIR}/Contents" | |
TARBALL="${WORKDIR}/jdk.tar.gz" | |
curl -L -o "${WORKDIR}/jdk.tar.gz" "${JDK_TARBALL_URL}" | |
tar xzf "${TARBALL}" -C "${WORKDIR}" | |
rm "${TARBALL}" | |
#JDK=$(find "${WORKDIR}" -type d -name "jdk-*") | |
mv "${WORKDIR}/${JDK}" "${WORKDIR}/Contents/Home" | |
# Download template Info.plist, populate it with jdk versions and save it to Contents/Info.plist | |
INFO_PLIST="${WORKDIR}/Contents/Info.plist" | |
wget -O "${INFO_PLIST}" "${INFO_PLIST_URL}" | |
eval "cat <<EOF | |
$(<"${INFO_PLIST}") | |
EOF | |
" 2> /dev/null > "${INFO_PLIST}" | |
# Link Contents/MacOS/libjli.dylib to Contents/Home/lib/jli/libjli.dylib | |
mkdir -p "${WORKDIR}/Contents/MacOS/" | |
cd "${WORKDIR}/Contents/MacOS/" | |
ln -s "../Home/lib/jli/libjli.dylib" "${WORKDIR}/Contents/MacOS/libjli.dylib" | |
cd - | |
echo "Installing AdoptOpenJDK ${SHORT_VERSION} to /Library/Java/JavaVirtualMachines" | |
sudo mv "${WORKDIR}" "/Library/Java/JavaVirtualMachines/adoptopenjdk-${SHORT_VERSION}.jdk" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment