Commit b9515499 authored by xiezhi's avatar xiezhi

Add Chinese mirror support for SDKMAN to improve download speed in China

parent 66385f3d
...@@ -97,6 +97,22 @@ ...@@ -97,6 +97,22 @@
], ],
"default": "latest", "default": "latest",
"description": "Select or enter a Groovy version" "description": "Select or enter a Groovy version"
},
"useChineseMirror": {
"type": "boolean",
"default": true,
"description": "Use Chinese mirrors (Aliyun) for faster download in China"
},
"mirrorSource": {
"type": "string",
"proposals": [
"aliyun",
"tencent",
"huawei",
"official"
],
"default": "aliyun",
"description": "Select mirror source for SDKMAN downloads"
} }
}, },
"customizations": { "customizations": {
......
...@@ -19,6 +19,8 @@ ANT_VERSION="${ANTVERSION:-"latest"}" ...@@ -19,6 +19,8 @@ ANT_VERSION="${ANTVERSION:-"latest"}"
INSTALL_GROOVY="${INSTALLGROOVY:-"false"}" INSTALL_GROOVY="${INSTALLGROOVY:-"false"}"
GROOVY_VERSION="${GROOVYVERSION:-"latest"}" GROOVY_VERSION="${GROOVYVERSION:-"latest"}"
JDK_DISTRO="${JDKDISTRO:-"ms"}" JDK_DISTRO="${JDKDISTRO:-"ms"}"
USE_CHINESE_MIRROR="${USECHINESEMIRROR:-"true"}"
MIRROR_SOURCE="${MIRRORSOURCE:-"aliyun"}"
export SDKMAN_DIR="${SDKMAN_DIR:-"/usr/local/sdkman"}" export SDKMAN_DIR="${SDKMAN_DIR:-"/usr/local/sdkman"}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
...@@ -310,6 +312,36 @@ if [ ! -d "${SDKMAN_DIR}" ]; then ...@@ -310,6 +312,36 @@ if [ ! -d "${SDKMAN_DIR}" ]; then
curl -sSL "https://get.sdkman.io?rcupdate=false" | bash curl -sSL "https://get.sdkman.io?rcupdate=false" | bash
chown -R "${USERNAME}:sdkman" ${SDKMAN_DIR} chown -R "${USERNAME}:sdkman" ${SDKMAN_DIR}
find ${SDKMAN_DIR} -type d -print0 | xargs -d '\n' -0 chmod g+s find ${SDKMAN_DIR} -type d -print0 | xargs -d '\n' -0 chmod g+s
# Configure SDKMAN to use Chinese mirrors for faster download
if [ "${USE_CHINESE_MIRROR}" = "true" ] && [ -f "${SDKMAN_DIR}/etc/config" ]; then
# Backup original config
cp "${SDKMAN_DIR}/etc/config" "${SDKMAN_DIR}/etc/config.backup"
# Configure mirror based on user selection
case "${MIRROR_SOURCE}" in
"aliyun")
mirror_url="https://mirrors.aliyun.com/sdkman/candidates"
echo "Configuring SDKMAN to use Aliyun mirrors for faster download in China"
;;
"tencent")
mirror_url="https://mirrors.cloud.tencent.com/sdkman/candidates"
echo "Configuring SDKMAN to use Tencent Cloud mirrors for faster download in China"
;;
"huawei")
mirror_url="https://mirrors.huaweicloud.com/sdkman/candidates"
echo "Configuring SDKMAN to use Huawei Cloud mirrors for faster download in China"
;;
"official"|*)
mirror_url="https://api.sdkman.io/2/candidates"
echo "Using official SDKMAN mirrors"
;;
esac
# Update the config file
sed -i "s|sdkman.candidates.api=https://api.sdkman.io/2/candidates|sdkman.candidates.api=${mirror_url}|g" "${SDKMAN_DIR}/etc/config"
fi
# Add sourcing of sdkman into bashrc/zshrc files (unless disabled) # Add sourcing of sdkman into bashrc/zshrc files (unless disabled)
updaterc "export SDKMAN_DIR=${SDKMAN_DIR}\n. \${SDKMAN_DIR}/bin/sdkman-init.sh" updaterc "export SDKMAN_DIR=${SDKMAN_DIR}\n. \${SDKMAN_DIR}/bin/sdkman-init.sh"
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment