How to build a localized sdkman mirror service
- 概述
- 想法
概述
从官方给出的安装说明,我们可以知道,官方给出的安装脚本是基于脚本https://get.sdkman.io/进行安装的,下面是该脚本的全部内容。
#!/bin/bash
#
# Copyright 2017 Marco Vermeulen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
## install:- channel: stable; cliVersion: 5.18.2; cliNativeVersion: 0.4.6; api: https://api.sdkman.io/2set -etrack_last_command() {last_command=$current_commandcurrent_command=$BASH_COMMAND
}
trap track_last_command DEBUGecho_failed_command() {local exit_code="$?"if [[ "$exit_code" != "0" ]]; thenecho "'$last_command': command failed with exit code $exit_code."fi
}
trap echo_failed_command EXIT# Global variables
export SDKMAN_SERVICE="https://api.sdkman.io/2"
export SDKMAN_VERSION="5.18.2"
export SDKMAN_NATIVE_VERSION="0.4.6"if [ -z "$SDKMAN_DIR" ]; thenSDKMAN_DIR="$HOME/.sdkman"SDKMAN_DIR_RAW='$HOME/.sdkman'
elseSDKMAN_DIR_RAW="$SDKMAN_DIR"
fi
export SDKMAN_DIR# Local variables
sdkman_src_folder="${SDKMAN_DIR}/src"
sdkman_libexec_folder="${SDKMAN_DIR}/libexec"
sdkman_tmp_folder="${SDKMAN_DIR}/tmp"
sdkman_ext_folder="${SDKMAN_DIR}/ext"
sdkman_etc_folder="${SDKMAN_DIR}/etc"
sdkman_var_folder="${SDKMAN_DIR}/var"
sdkman_candidates_folder="${SDKMAN_DIR}/candidates"
sdkman_config_file="${sdkman_etc_folder}/config"
sdkman_platform_file="${sdkman_var_folder}/platform"
sdkman_bash_profile="${HOME}/.bash_profile"
sdkman_profile="${HOME}/.profile"
sdkman_bashrc="${HOME}/.bashrc"
sdkman_zshrc="${ZDOTDIR:-${HOME}}/.zshrc"sdkman_init_snippet=$( cat << EOF
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$SDKMAN_DIR_RAW"
[[ -s "${SDKMAN_DIR_RAW}/bin/sdkman-init.sh" ]] && source "${SDKMAN_DIR_RAW}/bin/sdkman-init.sh"
EOF
)# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
solaris=false;
freebsd=false;
case "$(uname)" inCYGWIN*)cygwin=true;;Darwin*)darwin=true;;SunOS*)solaris=true;;FreeBSD*)freebsd=true
esacecho ''
echo ' -+syyyyyyys:'
echo ' `/yho:` -yd.'
echo ' `/yh/` +m.'
echo ' .oho. hy .`'
echo ' .sh/` :N` `-/o` `+dyyo:.'
echo ' .yh:` `M- `-/osysoym :hs` `-+sys: hhyssssssssy+'
echo ' .sh:` `N: ms/-`` yy.yh- -hy. `.N-````````+N.'
echo ' `od/` `N- -/oM- ddd+` `sd: hNNm -N:'
echo ' :do` .M. dMMM- `ms. /d+` `NMMs `do'
echo ' .yy- :N` ```mMMM. - -hy. /MMM: yh'
echo ' `+d+` `:/oo/` `-/osyh/ossssssdNMM` .sh: yMMN` /m.'
echo ' -dh- :ymNMMMMy `-/shmNm-`:N/-.`` `.sN /N- `NMMy .m/'
echo ' `oNs` -hysosmMMMMydmNmds+-.:ohm : sd` :MMM/ yy'
echo ' .hN+ /d: -MMMmhs/-.` .MMMh .ss+- `yy` sMMN` :N.'
echo ' :mN/ `N/ `o/-` :MMMo +MMMN- .` `ds mMMh do'
echo ' /NN/ `N+....--:/+oooosooo+:sMMM: hMMMM: `my .m+ -MMM+ :N.'
echo ' /NMo -+ooooo+/:-....`...:+hNMN. `NMMMd` .MM/ -m: oMMN. hs'
echo ' -NMd` :mm -MMMm- .s/ -MMm. /m- mMMd -N.'
echo ' `mMM/ .- /MMh. -dMo -MMMy od. .MMMs..---yh'
echo ' +MMM. sNo`.sNMM+ :MMMM/ sh`+MMMNmNm+++-'
echo ' mMMM- /--ohmMMM+ :MMMMm. `hyymmmdddo'
echo ' MMMMh. `````-+yy/`yMMM/ :MMMMMy -sm:.``..-:-.`'
echo ' dMMMMmo-.``````..-:/osyhddddho. `+shdh+. hMMM: :MmMMMM/ ./yy/` `:sys+/+sh/'
echo ' .dMMMMMMmdddddmmNMMMNNNNNMMMMMs sNdo- dMMM- `-/yd/MMMMm-:sy+. :hs- /N`'
echo ' `/ymNNNNNNNmmdys+/::----/dMMm: +m- mMMM+ohmo/.` sMMMMdo- .om: `sh'
echo ' `.-----+/.` `.-+hh/` `od. NMMNmds/ `mmy:` +mMy `:yy.'
echo ' /moyso+//+ossso:. .yy` `dy+:` .. :MMMN+---/oys:'
echo ' /+m: `.-:::-` /d+ +MMMMMMMNh:`'
echo ' +MN/ -yh. `+hddhy+.'
echo ' /MM+ .sh:'
echo ' :NMo -sh/'
echo ' -NMs `/yy:'
echo ' .NMy `:sh+.'
echo ' `mMm` ./yds-'
echo ' `dMMMmyo:-.````.-:oymNy:`'
echo ' +NMMMMMMMMMMMMMMMMms:`'
echo ' -+shmNMMMNmdy+:`'
echo ''
echo ''
echo ' Now attempting installation...'
echo ''
echo ''# Sanity checksecho "Looking for a previous installation of SDKMAN..."
if [ -d "$SDKMAN_DIR" ]; thenecho "SDKMAN found."echo ""echo "======================================================================================================"echo " You already have SDKMAN installed."echo " SDKMAN was found at:"echo ""echo " ${SDKMAN_DIR}"echo ""echo " Please consider running the following if you need to upgrade."echo ""echo " $ sdk selfupdate force"echo ""echo "======================================================================================================"echo ""exit 0
fiecho "Looking for unzip..."
if ! command -v unzip > /dev/null; thenecho "Not found."echo "======================================================================================================"echo " Please install unzip on your system using your favourite package manager."echo ""echo " Restart after installing unzip."echo "======================================================================================================"echo ""exit 1
fiecho "Looking for zip..."
if ! command -v zip > /dev/null; thenecho "Not found."echo "======================================================================================================"echo " Please install zip on your system using your favourite package manager."echo ""echo " Restart after installing zip."echo "======================================================================================================"echo ""exit 1
fiecho "Looking for curl..."
if ! command -v curl > /dev/null; thenecho "Not found."echo ""echo "======================================================================================================"echo " Please install curl on your system using your favourite package manager."echo ""echo " Restart after installing curl."echo "======================================================================================================"echo ""exit 1
fiif [[ "$solaris" == true ]]; thenecho "Looking for gsed..."if [ -z $(which gsed) ]; thenecho "Not found."echo ""echo "======================================================================================================"echo " Please install gsed on your solaris system."echo ""echo " SDKMAN uses gsed extensively."echo ""echo " Restart after installing gsed."echo "======================================================================================================"echo ""exit 1fi
elseecho "Looking for sed..."if [ -z $(command -v sed) ]; thenecho "Not found."echo ""echo "======================================================================================================"echo " Please install sed on your system using your favourite package manager."echo ""echo " Restart after installing sed."echo "======================================================================================================"echo ""exit 1fi
fiecho "Installing SDKMAN scripts..."# Create directory structureecho "Create distribution directories..."
mkdir -p "$sdkman_tmp_folder"
mkdir -p "$sdkman_ext_folder"
mkdir -p "$sdkman_etc_folder"
mkdir -p "$sdkman_var_folder"
mkdir -p "$sdkman_candidates_folder"echo "Getting available candidates..."
SDKMAN_CANDIDATES_CSV=$(curl -s "${SDKMAN_SERVICE}/candidates/all")
echo "$SDKMAN_CANDIDATES_CSV" > "${SDKMAN_DIR}/var/candidates"echo "Prime platform file..."
# infer platform
function infer_platform() {local kernellocal machinekernel="$(uname -s)"machine="$(uname -m)"case $kernel inLinux)case $machine ini686)echo "linuxx32";;x86_64)echo "linuxx64";;armv6l)echo "linuxarm32hf";;armv7l)echo "linuxarm32hf";;armv8l)echo "linuxarm32hf";;aarch64)echo "linuxarm64";;*)echo "exotic";;esac;;Darwin)case $machine inx86_64)echo "darwinx64";;arm64)echo "darwinarm64";;*)echo "darwinx64";;esac;;MSYS*|MINGW*)case $machine inx86_64)echo "windowsx64";;*)echo "exotic";;esac;;*)echo "exotic"esac
}export SDKMAN_PLATFORM="$(infer_platform)"echo "$SDKMAN_PLATFORM" > "$sdkman_platform_file"echo "Prime the config file..."
touch "$sdkman_config_file"
echo "sdkman_auto_answer=false" >> "$sdkman_config_file"
if [ -z "$ZSH_VERSION" -a -z "$BASH_VERSION" ]; thenecho "sdkman_auto_complete=false" >> "$sdkman_config_file"
elseecho "sdkman_auto_complete=true" >> "$sdkman_config_file"
fi
echo "sdkman_auto_env=false" >> "$sdkman_config_file"
echo "sdkman_beta_channel=false" >> "$sdkman_config_file"
echo "sdkman_checksum_enable=true" >> "$sdkman_config_file"
echo "sdkman_colour_enable=true" >> "$sdkman_config_file"
echo "sdkman_curl_connect_timeout=7" >> "$sdkman_config_file"
echo "sdkman_curl_max_time=10" >> "$sdkman_config_file"
echo "sdkman_debug_mode=false" >> "$sdkman_config_file"
echo "sdkman_insecure_ssl=false" >> "$sdkman_config_file"
echo "sdkman_selfupdate_feature=true" >> "$sdkman_config_file"# script cli distribution
echo "Installing script cli archive..."
# fetch distribution
sdkman_zip_file="${sdkman_tmp_folder}/sdkman-${SDKMAN_VERSION}.zip"
echo "* Downloading..."
curl --fail --location --progress-bar "${SDKMAN_SERVICE}/broker/download/sdkman/install/${SDKMAN_VERSION}/${SDKMAN_PLATFORM}" > "$sdkman_zip_file"# check integrity
echo "* Checking archive integrity..."
ARCHIVE_OK=$(unzip -qt "$sdkman_zip_file" | grep 'No errors detected in compressed data')
if [[ -z "$ARCHIVE_OK" ]]; thenecho "Downloaded zip archive corrupt. Are you connected to the internet?"echo ""echo "If problems persist, please ask for help on our Slack:"echo "* easy sign up: https://slack.sdkman.io/"echo "* report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"exit
fi# extract archive
echo "* Extracting archive..."
if [[ "$cygwin" == 'true' ]]; thensdkman_tmp_folder=$(cygpath -w "$sdkman_tmp_folder")sdkman_zip_file=$(cygpath -w "$sdkman_zip_file")
fi
unzip -qo "$sdkman_zip_file" -d "$sdkman_tmp_folder"# copy in place
echo "* Copying archive contents..."
rm -f "$sdkman_src_folder"/*
cp -rf "${sdkman_tmp_folder}"/sdkman-*/* "$SDKMAN_DIR"# clean up
echo "* Cleaning up..."
rm -rf "$sdkman_tmp_folder"/sdkman-*
rm -rf "$sdkman_zip_file"echo ""# native cli distribution
if [[ "$SDKMAN_PLATFORM" != "exotic" ]]; then
echo "Installing script cli archive..."
# fetch distribution
sdkman_zip_file="${sdkman_tmp_folder}/sdkman-native-${SDKMAN_NATIVE_VERSION}.zip"
echo "* Downloading..."
curl --fail --location --progress-bar "${SDKMAN_SERVICE}/broker/download/native/install/${SDKMAN_NATIVE_VERSION}/${SDKMAN_PLATFORM}" > "$sdkman_zip_file"# check integrity
echo "* Checking archive integrity..."
ARCHIVE_OK=$(unzip -qt "$sdkman_zip_file" | grep 'No errors detected in compressed data')
if [[ -z "$ARCHIVE_OK" ]]; thenecho "Downloaded zip archive corrupt. Are you connected to the internet?"echo ""echo "If problems persist, please ask for help on our Slack:"echo "* easy sign up: https://slack.sdkman.io/"echo "* report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"exit
fi# extract archive
echo "* Extracting archive..."
if [[ "$cygwin" == 'true' ]]; thensdkman_tmp_folder=$(cygpath -w "$sdkman_tmp_folder")sdkman_zip_file=$(cygpath -w "$sdkman_zip_file")
fi
unzip -qo "$sdkman_zip_file" -d "$sdkman_tmp_folder"# copy in place
echo "* Copying archive contents..."
rm -f "$sdkman_libexec_folder"/*
cp -rf "${sdkman_tmp_folder}"/sdkman-*/* "$SDKMAN_DIR"# clean up
echo "* Cleaning up..."
rm -rf "$sdkman_tmp_folder"/sdkman-*
rm -rf "$sdkman_zip_file"echo ""
fiecho "Set version to $SDKMAN_VERSION ..."
echo "$SDKMAN_VERSION" > "${SDKMAN_DIR}/var/version"echo "Set native version to $SDKMAN_NATIVE_VERSION ..."
echo "$SDKMAN_NATIVE_VERSION" > "${SDKMAN_DIR}/var/version_native"if [[ $darwin == true ]]; thentouch "$sdkman_bash_profile"echo "Attempt update of login bash profile on OSX..."if [[ -z $(grep 'sdkman-init.sh' "$sdkman_bash_profile") ]]; thenecho -e "\n$sdkman_init_snippet" >> "$sdkman_bash_profile"echo "Added sdkman init snippet to $sdkman_bash_profile"fi
elseecho "Attempt update of interactive bash profile on regular UNIX..."touch "${sdkman_bashrc}"if [[ -z $(grep 'sdkman-init.sh' "$sdkman_bashrc") ]]; thenecho -e "\n$sdkman_init_snippet" >> "$sdkman_bashrc"echo "Added sdkman init snippet to $sdkman_bashrc"fi
fiecho "Attempt update of zsh profile..."
touch "$sdkman_zshrc"
if [[ -z $(grep 'sdkman-init.sh' "$sdkman_zshrc") ]]; thenecho -e "\n$sdkman_init_snippet" >> "$sdkman_zshrc"echo "Updated existing ${sdkman_zshrc}"
fiecho -e "\n\n\nAll done!\n\n"echo "You are subscribed to the STABLE channel."echo ""
echo "Please open a new terminal, or run the following in the existing one:"
echo ""
echo " source \"${SDKMAN_DIR}/bin/sdkman-init.sh\""
echo ""
echo "Then issue the following command:"
echo ""
echo " sdk help"
echo ""
echo "Enjoy!!!"
在这里,我们看到,要完成脚本的安装,需要从服务器下载两个文件,生成一个文件的内容。
- 第一个文件,即
export SDKMAN_SERVICE="https://api.sdkman.io/2"
export SDKMAN_VERSION="5.18.2"
export SDKMAN_NATIVE_VERSION="0.4.6"# ...# script cli distribution
echo "Installing script cli archive..."
# fetch distribution
sdkman_zip_file="${sdkman_tmp_folder}/sdkman-${SDKMAN_VERSION}.zip"
echo "* Downloading..."
curl --fail --location --progress-bar "${SDKMAN_SERVICE}/broker/download/sdkman/install/${SDKMAN_VERSION}/${SDKMAN_PLATFORM}" > "$sdkman_zip_file"# check integrity
echo "* Checking archive integrity..."
ARCHIVE_OK=$(unzip -qt "$sdkman_zip_file" | grep 'No errors detected in compressed data')
if [[ -z "$ARCHIVE_OK" ]]; thenecho "Downloaded zip archive corrupt. Are you connected to the internet?"echo ""echo "If problems persist, please ask for help on our Slack:"echo "* easy sign up: https://slack.sdkman.io/"echo "* report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"exit
fi# extract archive
echo "* Extracting archive..."
if [[ "$cygwin" == 'true' ]]; thensdkman_tmp_folder=$(cygpath -w "$sdkman_tmp_folder")sdkman_zip_file=$(cygpath -w "$sdkman_zip_file")
fi
unzip -qo "$sdkman_zip_file" -d "$sdkman_tmp_folder"# copy in place
echo "* Copying archive contents..."
rm -f "$sdkman_src_folder"/*
cp -rf "${sdkman_tmp_folder}"/sdkman-*/* "$SDKMAN_DIR"# clean up
echo "* Cleaning up..."
rm -rf "$sdkman_tmp_folder"/sdkman-*
rm -rf "$sdkman_zip_file"echo ""
脚本下载文件https://api.sdkman.io/2/broker/download/sdkman/install/5.18.2/linuxx64
后重命名为sdkman-版本号.zip,比如sdkman-5.18.2.zip,将其解压后的内容复制放到~/.sdkman目录。
- 第二个文件,即
export SDKMAN_SERVICE="https://api.sdkman.io/2"
export SDKMAN_VERSION="5.18.2"
export SDKMAN_NATIVE_VERSION="0.4.6"# ...# native cli distribution
if [[ "$SDKMAN_PLATFORM" != "exotic" ]]; then
echo "Installing script cli archive..."
# fetch distribution
sdkman_zip_file="${sdkman_tmp_folder}/sdkman-native-${SDKMAN_NATIVE_VERSION}.zip"
echo "* Downloading..."
curl --fail --location --progress-bar "${SDKMAN_SERVICE}/broker/download/native/install/${SDKMAN_NATIVE_VERSION}/${SDKMAN_PLATFORM}" > "$sdkman_zip_file"# check integrity
echo "* Checking archive integrity..."
ARCHIVE_OK=$(unzip -qt "$sdkman_zip_file" | grep 'No errors detected in compressed data')
if [[ -z "$ARCHIVE_OK" ]]; thenecho "Downloaded zip archive corrupt. Are you connected to the internet?"echo ""echo "If problems persist, please ask for help on our Slack:"echo "* easy sign up: https://slack.sdkman.io/"echo "* report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"exit
fi# extract archive
echo "* Extracting archive..."
if [[ "$cygwin" == 'true' ]]; thensdkman_tmp_folder=$(cygpath -w "$sdkman_tmp_folder")sdkman_zip_file=$(cygpath -w "$sdkman_zip_file")
fi
unzip -qo "$sdkman_zip_file" -d "$sdkman_tmp_folder"# copy in place
echo "* Copying archive contents..."
rm -f "$sdkman_libexec_folder"/*
cp -rf "${sdkman_tmp_folder}"/sdkman-*/* "$SDKMAN_DIR"# clean up
echo "* Cleaning up..."
rm -rf "$sdkman_tmp_folder"/sdkman-*
rm -rf "$sdkman_zip_file"echo ""
fi
脚本下载文件https://api.sdkman.io/2/broker/download/native/install/0.4.6/linuxx64
重命名为sdkman-native-版本号.zip,比如sdkman-native-0.4.6.zip,将其解压后的内容复制放到~/.sdkman目录。
- 生成一个文件内容
export SDKMAN_SERVICE="https://api.sdkman.io/2"
export SDKMAN_VERSION="5.18.2"
export SDKMAN_NATIVE_VERSION="0.4.6"
# ...
echo "Getting available candidates..."
SDKMAN_CANDIDATES_CSV=$(curl -s "${SDKMAN_SERVICE}/candidates/all")
echo "$SDKMAN_CANDIDATES_CSV" > "${SDKMAN_DIR}/var/candidates"
脚本访问服务https://api.sdkman.io/2/candidates/all
,将其返回值用于生成文件~/.sdkman/var/candidates
想法
考虑到sdkman官方服务部署在海外,有时候访问不了,我们这里可以通过其他手段将这三个文件提前下载下来,基于nginx部署为本地服务,并将服务地址指向本地服务,这样后续安装的时候,就不在受到海外服务卡顿带来的影响了。
下面是我基于官方脚本重新修改后的安装脚本,内容如下
#!/bin/bash
#
# Copyright 2017 Marco Vermeulen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
## install:- channel: stable; cliVersion: 5.18.2; cliNativeVersion: 0.4.6; api: https://api.sdkman.io/2set -etrack_last_command() {last_command=$current_commandcurrent_command=$BASH_COMMAND
}
trap track_last_command DEBUGecho_failed_command() {local exit_code="$?"if [[ "$exit_code" != "0" ]]; thenecho "'$last_command': command failed with exit code $exit_code."fi
}
trap echo_failed_command EXIT# Global variables
export SDKMAN_SERVICE="https://api.sdkman.io/2"
export SDKMAN_VERSION="5.18.2"
export SDKMAN_NATIVE_VERSION="0.4.6"if [ -z "$SDKMAN_DIR" ]; thenSDKMAN_DIR="$HOME/.sdkman"SDKMAN_DIR_RAW='$HOME/.sdkman'
elseSDKMAN_DIR_RAW="$SDKMAN_DIR"
fi
export SDKMAN_DIR# Local variables#sdkman_download_dir=~/Download/sdkman
sdkman_download_dir=$(pwd)sdkman_src_folder="${SDKMAN_DIR}/src"
sdkman_libexec_folder="${SDKMAN_DIR}/libexec"
sdkman_tmp_folder="${SDKMAN_DIR}/tmp"
sdkman_ext_folder="${SDKMAN_DIR}/ext"
sdkman_etc_folder="${SDKMAN_DIR}/etc"
sdkman_var_folder="${SDKMAN_DIR}/var"
sdkman_candidates_folder="${SDKMAN_DIR}/candidates"
sdkman_config_file="${sdkman_etc_folder}/config"
sdkman_platform_file="${sdkman_var_folder}/platform"
sdkman_bash_profile="${HOME}/.bash_profile"
sdkman_profile="${HOME}/.profile"
sdkman_bashrc="${HOME}/.bashrc"
sdkman_zshrc="${ZDOTDIR:-${HOME}}/.zshrc"sdkman_init_snippet=$( cat << EOF
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$SDKMAN_DIR_RAW"
[[ -s "${SDKMAN_DIR_RAW}/bin/sdkman-init.sh" ]] && source "${SDKMAN_DIR_RAW}/bin/sdkman-init.sh"
EOF
)# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
solaris=false;
freebsd=false;
case "$(uname)" inCYGWIN*)cygwin=true;;Darwin*)darwin=true;;SunOS*)solaris=true;;FreeBSD*)freebsd=true
esacecho ''
echo ' -+syyyyyyys:'
echo ' `/yho:` -yd.'
echo ' `/yh/` +m.'
echo ' .oho. hy .`'
echo ' .sh/` :N` `-/o` `+dyyo:.'
echo ' .yh:` `M- `-/osysoym :hs` `-+sys: hhyssssssssy+'
echo ' .sh:` `N: ms/-`` yy.yh- -hy. `.N-````````+N.'
echo ' `od/` `N- -/oM- ddd+` `sd: hNNm -N:'
echo ' :do` .M. dMMM- `ms. /d+` `NMMs `do'
echo ' .yy- :N` ```mMMM. - -hy. /MMM: yh'
echo ' `+d+` `:/oo/` `-/osyh/ossssssdNMM` .sh: yMMN` /m.'
echo ' -dh- :ymNMMMMy `-/shmNm-`:N/-.`` `.sN /N- `NMMy .m/'
echo ' `oNs` -hysosmMMMMydmNmds+-.:ohm : sd` :MMM/ yy'
echo ' .hN+ /d: -MMMmhs/-.` .MMMh .ss+- `yy` sMMN` :N.'
echo ' :mN/ `N/ `o/-` :MMMo +MMMN- .` `ds mMMh do'
echo ' /NN/ `N+....--:/+oooosooo+:sMMM: hMMMM: `my .m+ -MMM+ :N.'
echo ' /NMo -+ooooo+/:-....`...:+hNMN. `NMMMd` .MM/ -m: oMMN. hs'
echo ' -NMd` :mm -MMMm- .s/ -MMm. /m- mMMd -N.'
echo ' `mMM/ .- /MMh. -dMo -MMMy od. .MMMs..---yh'
echo ' +MMM. sNo`.sNMM+ :MMMM/ sh`+MMMNmNm+++-'
echo ' mMMM- /--ohmMMM+ :MMMMm. `hyymmmdddo'
echo ' MMMMh. `````-+yy/`yMMM/ :MMMMMy -sm:.``..-:-.`'
echo ' dMMMMmo-.``````..-:/osyhddddho. `+shdh+. hMMM: :MmMMMM/ ./yy/` `:sys+/+sh/'
echo ' .dMMMMMMmdddddmmNMMMNNNNNMMMMMs sNdo- dMMM- `-/yd/MMMMm-:sy+. :hs- /N`'
echo ' `/ymNNNNNNNmmdys+/::----/dMMm: +m- mMMM+ohmo/.` sMMMMdo- .om: `sh'
echo ' `.-----+/.` `.-+hh/` `od. NMMNmds/ `mmy:` +mMy `:yy.'
echo ' /moyso+//+ossso:. .yy` `dy+:` .. :MMMN+---/oys:'
echo ' /+m: `.-:::-` /d+ +MMMMMMMNh:`'
echo ' +MN/ -yh. `+hddhy+.'
echo ' /MM+ .sh:'
echo ' :NMo -sh/'
echo ' -NMs `/yy:'
echo ' .NMy `:sh+.'
echo ' `mMm` ./yds-'
echo ' `dMMMmyo:-.````.-:oymNy:`'
echo ' +NMMMMMMMMMMMMMMMMms:`'
echo ' -+shmNMMMNmdy+:`'
echo ''
echo ''
echo ' Now attempting installation...'
echo ''
echo ''# Sanity checks#echo "Looking for a previous installation of SDKMAN..."
#if [ -d "$SDKMAN_DIR" ]; then
# echo "SDKMAN found."
# echo ""
# echo "======================================================================================================"
# echo " You already have SDKMAN installed."
# echo " SDKMAN was found at:"
# echo ""
# echo " ${SDKMAN_DIR}"
# echo ""
# echo " Please consider running the following if you need to upgrade."
# echo ""
# echo " $ sdk selfupdate force"
# echo ""
# echo "======================================================================================================"
# echo ""
# exit 0
#fiecho "Looking for unzip..."
if ! command -v unzip > /dev/null; thenecho "Not found."echo "======================================================================================================"echo " Please install unzip on your system using your favourite package manager."echo ""echo " Restart after installing unzip."echo "======================================================================================================"echo ""exit 1
fiecho "Looking for zip..."
if ! command -v zip > /dev/null; thenecho "Not found."echo "======================================================================================================"echo " Please install zip on your system using your favourite package manager."echo ""echo " Restart after installing zip."echo "======================================================================================================"echo ""exit 1
fiecho "Looking for curl..."
if ! command -v curl > /dev/null; thenecho "Not found."echo ""echo "======================================================================================================"echo " Please install curl on your system using your favourite package manager."echo ""echo " Restart after installing curl."echo "======================================================================================================"echo ""exit 1
fiif [[ "$solaris" == true ]]; thenecho "Looking for gsed..."if [ -z $(which gsed) ]; thenecho "Not found."echo ""echo "======================================================================================================"echo " Please install gsed on your solaris system."echo ""echo " SDKMAN uses gsed extensively."echo ""echo " Restart after installing gsed."echo "======================================================================================================"echo ""exit 1fi
elseecho "Looking for sed..."if [ -z $(command -v sed) ]; thenecho "Not found."echo ""echo "======================================================================================================"echo " Please install sed on your system using your favourite package manager."echo ""echo " Restart after installing sed."echo "======================================================================================================"echo ""exit 1fi
fiecho "Installing SDKMAN scripts..."# Create directory structureecho "Create distribution directories..."
mkdir -p "$sdkman_tmp_folder"
mkdir -p "$sdkman_ext_folder"
mkdir -p "$sdkman_etc_folder"
mkdir -p "$sdkman_var_folder"
mkdir -p "$sdkman_candidates_folder"echo "Getting available candidates..."
#SDKMAN_CANDIDATES_CSV=$(curl -s "${SDKMAN_SERVICE}/candidates/all")
#echo "$SDKMAN_CANDIDATES_CSV" > "${SDKMAN_DIR}/var/candidates"cat $sdkman_download_dir/candidates > "${SDKMAN_DIR}/var/candidates"echo "Prime platform file..."
# infer platform
function infer_platform() {local kernellocal machinekernel="$(uname -s)"machine="$(uname -m)"case $kernel inLinux)case $machine ini686)echo "linuxx32";;x86_64)echo "linuxx64";;armv6l)echo "linuxarm32hf";;armv7l)echo "linuxarm32hf";;armv8l)echo "linuxarm32hf";;aarch64)echo "linuxarm64";;*)echo "exotic";;esac;;Darwin)case $machine inx86_64)echo "darwinx64";;arm64)echo "darwinarm64";;*)echo "darwinx64";;esac;;MSYS*|MINGW*)case $machine inx86_64)echo "windowsx64";;*)echo "exotic";;esac;;*)echo "exotic"esac
}export SDKMAN_PLATFORM="$(infer_platform)"echo "$SDKMAN_PLATFORM" > "$sdkman_platform_file"echo "Prime the config file..."
touch "$sdkman_config_file"
echo "sdkman_auto_answer=false" >> "$sdkman_config_file"
if [ -z "$ZSH_VERSION" -a -z "$BASH_VERSION" ]; thenecho "sdkman_auto_complete=false" >> "$sdkman_config_file"
elseecho "sdkman_auto_complete=true" >> "$sdkman_config_file"
fi
echo "sdkman_auto_env=false" >> "$sdkman_config_file"
echo "sdkman_beta_channel=false" >> "$sdkman_config_file"
echo "sdkman_checksum_enable=true" >> "$sdkman_config_file"
echo "sdkman_colour_enable=true" >> "$sdkman_config_file"
echo "sdkman_curl_connect_timeout=7" >> "$sdkman_config_file"
echo "sdkman_curl_max_time=10" >> "$sdkman_config_file"
echo "sdkman_debug_mode=false" >> "$sdkman_config_file"
echo "sdkman_insecure_ssl=false" >> "$sdkman_config_file"
echo "sdkman_selfupdate_feature=true" >> "$sdkman_config_file"# script cli distribution
echo "Installing script cli archive..."
# fetch distribution
sdkman_main_zip_file="${sdkman_tmp_folder}/sdkman_main_${SDKMAN_VERSION}.zip"
echo "* Downloading..."
#curl --fail --location --progress-bar "${SDKMAN_SERVICE}/broker/download/sdkman/install/${SDKMAN_VERSION}/${SDKMAN_PLATFORM}" > "$sdkman_zip_file"rm -rf $sdkman_main_zip_file
cp $sdkman_download_dir/sdkman_main_*.zip $sdkman_main_zip_file# check integrity
echo "* Checking archive integrity..."
ARCHIVE_OK=$(unzip -qt "$sdkman_main_zip_file" | grep 'No errors detected in compressed data')
if [[ -z "$ARCHIVE_OK" ]]; thenecho "Downloaded zip archive corrupt. Are you connected to the internet?"echo ""echo "If problems persist, please ask for help on our Slack:"echo "* easy sign up: https://slack.sdkman.io/"echo "* report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"exit
fi# extract archive
echo "* Extracting archive..."
if [[ "$cygwin" == 'true' ]]; thensdkman_tmp_folder=$(cygpath -w "$sdkman_tmp_folder")sdkman_main_zip_file=$(cygpath -w "$sdkman_main_zip_file")
fiunzip -qo "$sdkman_main_zip_file" -d "$sdkman_tmp_folder"# copy in place
echo "* Copying archive contents..."rm -f "$sdkman_src_folder"/*
cp -rf "${sdkman_tmp_folder}"/sdkman_main_*/* "$SDKMAN_DIR"# clean up
echo "* Cleaning up..."
rm -rf "$sdkman_tmp_folder"/sdkman_main_*
#rm -rf "$sdkman_zip_file"echo ""# native cli distribution
if [[ "$SDKMAN_PLATFORM" != "exotic" ]]; then
echo "Installing script cli archive..."
# fetch distribution
sdkman_native_zip_file="${sdkman_tmp_folder}/sdkman_native_${SDKMAN_NATIVE_VERSION}.zip"
echo "* Downloading..."
#curl --fail --location --progress-bar "${SDKMAN_SERVICE}/broker/download/native/install/${SDKMAN_NATIVE_VERSION}/${SDKMAN_PLATFORM}" > "$sdkman_zip_file"rm -rf $sdkman_native_zip_file
cp $sdkman_download_dir/sdkman_native_*.zip $sdkman_native_zip_file# check integrity
echo "* Checking archive integrity..."
ARCHIVE_OK=$(unzip -qt "$sdkman_native_zip_file" | grep 'No errors detected in compressed data')
if [[ -z "$ARCHIVE_OK" ]]; thenecho "Downloaded zip archive corrupt. Are you connected to the internet?"echo ""echo "If problems persist, please ask for help on our Slack:"echo "* easy sign up: https://slack.sdkman.io/"echo "* report on channel: https://sdkman.slack.com/app_redirect?channel=user-issues"exit
fi# extract archive
echo "* Extracting archive..."
if [[ "$cygwin" == 'true' ]]; thensdkman_tmp_folder=$(cygpath -w "$sdkman_tmp_folder")sdkman_native_zip_file=$(cygpath -w "$sdkman_native_zip_file")
fi
unzip -qo "$sdkman_native_zip_file" -d "$sdkman_tmp_folder"# copy in place
echo "* Copying archive contents..."
rm -f "$sdkman_libexec_folder"/*
cp -rf "${sdkman_tmp_folder}"/sdkman_native_*/* "$SDKMAN_DIR"# clean up
echo "* Cleaning up..."
rm -rf "$sdkman_tmp_folder"/sdkman_native_*
#rm -rf "$sdkman_native_zip_file"
echo ""
fiecho "Set version to $SDKMAN_VERSION ..."
echo "$SDKMAN_VERSION" > "${SDKMAN_DIR}/var/version"echo "Set native version to $SDKMAN_NATIVE_VERSION ..."
echo "$SDKMAN_NATIVE_VERSION" > "${SDKMAN_DIR}/var/version_native"if [[ $darwin == true ]]; thentouch "$sdkman_bash_profile"echo "Attempt update of login bash profile on OSX..."if [[ -z $(grep 'sdkman-init.sh' "$sdkman_bash_profile") ]]; thenecho -e "\n$sdkman_init_snippet" >> "$sdkman_bash_profile"echo "Added sdkman init snippet to $sdkman_bash_profile"fi
elseecho "Attempt update of interactive bash profile on regular UNIX..."touch "${sdkman_bashrc}"if [[ -z $(grep 'sdkman-init.sh' "$sdkman_bashrc") ]]; thenecho -e "\n$sdkman_init_snippet" >> "$sdkman_bashrc"echo "Added sdkman init snippet to $sdkman_bashrc"fi
fiecho "Attempt update of zsh profile..."
touch "$sdkman_zshrc"
if [[ -z $(grep 'sdkman-init.sh' "$sdkman_zshrc") ]]; thenecho -e "\n$sdkman_init_snippet" >> "$sdkman_zshrc"echo "Updated existing ${sdkman_zshrc}"
fiecho -e "\n\n\nAll done!\n\n"echo "You are subscribed to the STABLE channel."echo ""
echo "Please open a new terminal, or run the following in the existing one:"
echo ""
echo " source \"${SDKMAN_DIR}/bin/sdkman-init.sh\""
echo ""
echo "Then issue the following command:"
echo ""
echo " sdk help"
echo ""
echo "Enjoy!!!"
完整的脚本及相关文件,我已经放在码云代码仓库sdkman-localized中了,需要的小伙伴可以前去下载。进入目录,执行如下命令即可安装:
cat sdkman.sh | bash