Merge pull request #19 from skull-squadron/patch-2

[install] Epic refactor
This commit is contained in:
R. Francis Smith 2024-09-01 11:16:51 -05:00 committed by GitHub
commit dd1eccee58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,97 +1,90 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -Eeuo pipefail
export GRADLE_DISTRIBUTION_URL=${GRADLE_DISTRIBUTION_URL:=https://services.gradle.org/distributions} export GRADLE_DISTRIBUTION_URL=${GRADLE_DISTRIBUTION_URL:-https://services.gradle.org/distributions}
checkShasum () has_command() {
{ command -v "$1" >&/dev/null
}
log() {
echo >&2 "asdf-gradle: $@"
}
die() {
log "$@"
exit 1
}
ensure_command() {
local cmd="$1"
[ -z "${2-}" ] || shift
if ! has_command "$cmd"; then
die "$cmd is missing. Please install it and try again."
fi
"$cmd" "$@"
}
checkShasum() {
local archive_file_name="${1}" local archive_file_name="${1}"
local authentic_checksum="${2}" local authentic_checksum="${2}"
if $(command -v sha256sum >/dev/null 2>&1); then log 'check sha256sum'
sha256sum \ if has_command sha256sum; then
-c <<<"$authentic_checksum $archive_file_name" sha256sum -c <<<"$authentic_checksum $archive_file_name"
elif $(command -v shasum >/dev/null 2>&1); then elif has_command shasum; then
shasum \ shasum -a 256 -c <<<"$authentic_checksum $archive_file_name"
-a 256 \
-c <<<"$authentic_checksum $archive_file_name"
else else
echo "sha256sum or shasum is not available for use" >&2 die 'sha256sum and shasum commands missing'
return 1
fi fi
} }
# instructions taken straight from https://gradle.org/install/#manually # instructions taken straight from https://gradle.org/install/#manually
installGradleSig() installGradleRef() {
{ log "clone $ASDF_INSTALL_VERSION"
if [ "$ASDF_INSTALL_TYPE" = "ref" ] ensure_command git clone "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" --depth 1
then }
echo "start clone $ASDF_INSTALL_VERSION"
git clone "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" installGradleSig() {
else log "install $ASDF_INSTALL_VERSION"
echo "start install $ASDF_INSTALL_VERSION" mkdir -p "$ASDF_INSTALL_PATH"
mkdir -p "$ASDF_INSTALL_PATH" cd "$ASDF_INSTALL_PATH"
cd "$ASDF_INSTALL_PATH" || exit 1 ensure_command curl -OJfSL ${GRADLE_DISTRIBUTION_URL}/gradle-${ASDF_INSTALL_VERSION}-bin.zip
curl -OJL ${GRADLE_DISTRIBUTION_URL}/gradle-${ASDF_INSTALL_VERSION}-bin.zip curl -OJfSL ${GRADLE_DISTRIBUTION_URL}/gradle-${ASDF_INSTALL_VERSION}-bin.zip.sha256
curl -OJL ${GRADLE_DISTRIBUTION_URL}/gradle-${ASDF_INSTALL_VERSION}-bin.zip.sha256 local archive_file_name=$PWD/gradle-${ASDF_INSTALL_VERSION}-bin.zip
archive_file_name=$PWD/gradle-${ASDF_INSTALL_VERSION}-bin.zip local authentic_checksum_file=$archive_file_name.sha256
authentic_checksum_file=$archive_file_name.sha256 local authentic_checksum=$(cat "$authentic_checksum_file")
authentic_checksum=$(cat $authentic_checksum_file)
echo 'start check sha256sum'
if ! checkShasum "$archive_file_name" "$authentic_checksum"; then if ! checkShasum "$archive_file_name" "$authentic_checksum"; then
echo "Authenticity of package archive can not be assured. Exiting." >&2 die 'Authenticity of package archive can not be assured. Exiting.'
exit 1
fi fi
echo 'start unzip check' ensure_command unzip "gradle-${ASDF_INSTALL_VERSION}-bin.zip"
if ! command -v unzip &> /dev/null; then rm -f "gradle-${ASDF_INSTALL_VERSION}-bin.zip"
echo "Unzip is not installed. Please install unzip and try again." mv "gradle-${ASDF_INSTALL_VERSION}"/* .
exit 1
fi
unzip gradle-${ASDF_INSTALL_VERSION}-bin.zip
rm gradle-${ASDF_INSTALL_VERSION}-bin.zip
mv gradle-${ASDF_INSTALL_VERSION}/* .
rm -rf gradle-${ASDF_INSTALL_VERSION} rm -rf gradle-${ASDF_INSTALL_VERSION}
rm $authentic_checksum_file rm -f "$authentic_checksum_file"
fi
} }
installGradleNoSign() installGradleNoSign() {
{ log "install (SECURITY WARNING! not checking signatures) $ASDF_INSTALL_VERSION"
if [ "$ASDF_INSTALL_TYPE" = "ref" ]
then
git clone "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
else
mkdir -p "$ASDF_INSTALL_PATH" mkdir -p "$ASDF_INSTALL_PATH"
cd "$ASDF_INSTALL_PATH" || exit 1 cd "$ASDF_INSTALL_PATH"
curl -OJL ${GRADLE_DISTRIBUTION_URL}/gradle-${ASDF_INSTALL_VERSION}-bin.zip ensure_command curl -OJfSL "${GRADLE_DISTRIBUTION_URL}/gradle-${ASDF_INSTALL_VERSION}-bin.zip"
echo 'start unzip check' ensure_command unzip "gradle-${ASDF_INSTALL_VERSION}-bin.zip"
if ! command -v unzip &> /dev/null; then rm -r "gradle-${ASDF_INSTALL_VERSION}-bin.zip"
echo "Unzip is not installed. Please install unzip and try again." mv "gradle-${ASDF_INSTALL_VERSION}"/* .
exit 1 rm -rf "gradle-${ASDF_INSTALL_VERSION}"
fi
unzip gradle-${ASDF_INSTALL_VERSION}-bin.zip
rm gradle-${ASDF_INSTALL_VERSION}-bin.zip
mv gradle-${ASDF_INSTALL_VERSION}/* .
rm -rf gradle-${ASDF_INSTALL_VERSION}
fi
} }
if [ ! -z GRADLE_SIGNATURE_CHECK -a "$GRADLE_SIGNATURE_CHECK" = "yes" ] if [ "${ASDF_INSTALL_TYPE-}" = ref ]; then
then installGradleRef
## check if GRADLE_SIGNATURE_CHECK and its "yes" elif [ "${GRADLE_SIGNATURE_CHECK-}" = no ]; then
installGradleSig
elif [ ! -z GRADLE_SIGNATURE_CHECK -a "$GRADLE_SIGNATURE_CHECK" = "no" ]
then
## check if GRADLE_SIGNATURE_CHECK and its "no" ## check if GRADLE_SIGNATURE_CHECK and its "no"
installGradleNoSign installGradleNoSign
else else
## only install with sign check ## only install with sign check: default, and when GRADLE_SIGNATURE_CHECK == 'yes'
installGradleSig installGradleSig
fi fi