|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +# stop on error |
| 21 | +set -e |
| 22 | + |
| 23 | +# Check if running as root |
| 24 | +if [[ ${EUID} -ne 0 ]]; then |
| 25 | + echo "Sorry, this script must be run as root." |
| 26 | + echo "Try: sudo $0 $*" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +ZULU_VSN="$CLOUSEAUJDKVERSION" |
| 31 | + |
| 32 | +if [[ -z "$ZULU_VSN" ]]; then |
| 33 | + echo "No Zulu JDK version is set." |
| 34 | + echo "Try setting the CLOUSEAUJDKVERSION environment variable." |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 39 | + |
| 40 | +. ${SCRIPTPATH}/detect-arch.sh |
| 41 | +. ${SCRIPTPATH}/detect-os.sh |
| 42 | + |
| 43 | +case "${OSTYPE}/${ARCH}" in |
| 44 | + linux*/x86_64) ZULU_PLATFORM="linux_x64" ;; |
| 45 | + linux*/aarch64) ZULU_PLATFORM="linux_aarch64" ;; |
| 46 | + *) |
| 47 | + echo "Unsupported platform for the Zulu JDK: ${OSTYPE}/${ARCH}." |
| 48 | + exit 1 |
| 49 | + ;; |
| 50 | +esac |
| 51 | + |
| 52 | +ZULU_DIST=https://cdn.azul.com/zulu/bin/"${ZULU_VSN}"-"${ZULU_PLATFORM}".tar.gz |
| 53 | + |
| 54 | +function ensure_tool() { |
| 55 | + _tool="$1" |
| 56 | + |
| 57 | + if ! type "${_tool}" > /dev/null 2>&1; then |
| 58 | + echo "Please install `${_tool}`" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +ensure_tool tar |
| 64 | +ensure_tool curl |
| 65 | + |
| 66 | +echo "==> Installing Zulu JDK from $ZULU_DIST" |
| 67 | + |
| 68 | +mkdir -p /opt/java/clouseaujdk/ |
| 69 | + |
| 70 | +if ! curl -sSL --max-redirs 1 -o - "$ZULU_DIST" \ |
| 71 | + | (tar -xzf - --strip-component 1 -C /opt/java/clouseaujdk/ 2> /dev/null); then |
| 72 | + echo "===> Could not install the Zulu JDK distribution" |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +echo "===> DONE" |
0 commit comments