2022-12-08 20:25:43 -08:00
|
|
|
#!/usr/bin/env bash
|
2023-04-11 20:26:25 -07:00
|
|
|
# @file SDKMAN Install
|
|
|
|
# @brief Ensures SDKMAN is installed.
|
|
|
|
# @description
|
|
|
|
# This script ensures SDKMAN (a Java version manager) is installed using the method recommended on [their
|
|
|
|
# website](https://sdkman.io/).
|
2022-12-08 20:25:43 -08:00
|
|
|
|
2022-12-25 00:30:40 -08:00
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
2022-12-08 20:25:43 -08:00
|
|
|
|
2023-11-27 02:12:13 -08:00
|
|
|
### Re-source ~/.bashrc
|
|
|
|
if [ -z "$SDKMAN_DIR" ]; then
|
|
|
|
logg info 'SDKMAN_DIR is undefined so ~/.bashrc is being re-sourced' && source ~/.bashrc
|
|
|
|
fi
|
|
|
|
|
2023-08-03 23:05:20 -07:00
|
|
|
### SDKMan ~/.bashrc settings
|
|
|
|
if command -v brew > /dev/null && command -v sdkman-cli > /dev/null; then
|
|
|
|
export SDKMAN_DIR="$(brew --prefix sdkman-cli)/libexec"
|
|
|
|
. "$SDKMAN_DIR/bin/sdkman-init.sh"
|
2023-11-27 02:12:13 -08:00
|
|
|
elif [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/sdkman" ]; then
|
2023-08-07 22:29:21 -07:00
|
|
|
export SDKMAN_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/sdkman"
|
2023-08-03 23:05:20 -07:00
|
|
|
. "$SDKMAN_DIR/bin/sdkman-init.sh"
|
2023-11-27 02:12:13 -08:00
|
|
|
else
|
2023-11-29 21:32:21 -08:00
|
|
|
logg logg 'Unable to find SDKMAN instance'
|
2023-08-03 23:05:20 -07:00
|
|
|
fi
|
|
|
|
|
2022-12-08 20:25:43 -08:00
|
|
|
### Ensure SDKMan is installed (https://sdkman.io/)
|
|
|
|
if [ ! -d "$SDKMAN_DIR" ]; then
|
2023-11-29 21:32:21 -08:00
|
|
|
logg info 'Installing SDKMan via curl -s https://get.sdkman.io?rcupdate=false'
|
2022-12-08 20:25:43 -08:00
|
|
|
logg info "Install directory: $SDKMAN_DIR"
|
2023-02-01 18:18:06 -08:00
|
|
|
curl -s "https://get.sdkman.io?rcupdate=false" | bash
|
2023-11-29 21:32:21 -08:00
|
|
|
if [ -f "$SDKMAN_DIR/bin/sdkman-init.sh" ]; then
|
|
|
|
. "$SDKMAN_DIR/bin/sdkman-init.sh"
|
|
|
|
logg info 'Running sdk install java' && sdk install java
|
|
|
|
else
|
|
|
|
logg warn 'SDKMAN_DIR/bin/sdkman-init.sh is missing'
|
|
|
|
fi
|
2022-12-08 20:25:43 -08:00
|
|
|
else
|
|
|
|
logg info 'SDKMan appears to already be installed.'
|
2023-11-29 21:32:21 -08:00
|
|
|
logg info 'Running sdk update'
|
2023-11-27 02:12:13 -08:00
|
|
|
if command -v sdk > /dev/null; then
|
2023-11-29 21:32:21 -08:00
|
|
|
sdk update
|
2023-11-27 02:12:13 -08:00
|
|
|
else
|
|
|
|
logg warn 'Unable to run sdk update because the sdk command is unavailable'
|
|
|
|
fi
|
2022-12-08 20:25:43 -08:00
|
|
|
fi
|