Skip to content

Instantly share code, notes, and snippets.

@hustlyt
Last active January 14, 2025 07:00
Show Gist options
  • Save hustlyt/e89f6509db737deb12a35b2864d3c243 to your computer and use it in GitHub Desktop.
Save hustlyt/e89f6509db737deb12a35b2864d3c243 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Install JDK with url for use with SDKMAN
#
set -eu
# This URL can be discovered using https://d.injdk.cn/download
DOWNLOAD_URL=$1
TARBALL=$(basename "$DOWNLOAD_URL")
SDK_ID=$2
if [[ -z ${SDKMAN_DIR:-} ]]; then
echo 'Error: ${SDKMAN_DIR} not defined'
exit 1
fi
mkdir -p "$SDKMAN_DIR/candidates/java" "/tmp"
SDK_DIR="$SDKMAN_DIR/candidates/java/$SDK_ID"
if [[ -e "$SDK_DIR" ]]; then
echo "$SDK_ID already installed"
exit 0
fi
cd "/tmp"
wget "$DOWNLOAD_URL"
#tar xzf "$TARBALL"
unzip "$TARBALL"
# 使用find命令查找第一个包含bin目录的路径
result=$(dirname "$(find /tmp -type d -name "bin" -print -quit)")
echo "downloaded to $result"
mv -f "$result" "$SDK_DIR"
rm -rf /tmp/*
echo "$SDK_ID installed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment