Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SRCFILES = $(shell git ls-files "bin/**" "lib/**" "spec/**" "test-fixtures/*.sh")
SHFMT_BASE_FLAGS = -s -i 2 -ci

format:
shfmt -w $(SHFMT_BASE_FLAGS) $(SRCFILES)
.PHONY: format

format-check:
shfmt -d $(SHFMT_BASE_FLAGS) $(SRCFILES)
.PHONY: format-check

lint:
shellcheck -x $(SRCFILES)
.PHONY: lint
76 changes: 38 additions & 38 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@ PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")/.."
source "$PLUGIN_DIR/lib/helpers.sh"

check_shasum() {
local archive_file_name=$1
local authentic_checksum_file=$2
local authentic_checksum=""

authentic_checksum=$(<"$authentic_checksum_file")

if command -v sha256sum >/dev/null 2>&1; then
sha256sum \
-c <(echo "$authentic_checksum $archive_file_name")
elif command -v shasum >/dev/null 2>&1; then
shasum \
-a 256 \
-c <(echo "$authentic_checksum $archive_file_name")
else
fail "sha256sum or shasum is not available for use"
fi
local archive_file_name=$1
local authentic_checksum_file=$2
local authentic_checksum=""

authentic_checksum=$(<"$authentic_checksum_file")

if command -v sha256sum >/dev/null 2>&1; then
sha256sum \
-c <(echo "$authentic_checksum $archive_file_name")
elif command -v shasum >/dev/null 2>&1; then
shasum \
-a 256 \
-c <(echo "$authentic_checksum $archive_file_name")
else
fail "sha256sum or shasum is not available for use"
fi
}

download_golang () {
local version=$1
local download_path=$2
local platform=""
local arch=""
download_golang() {
local version=$1
local download_path=$2
local platform=""
local arch=""

platform=$(get_platform)
arch=$(get_arch)
download_url="https://dl.google.com/go/go${version}.${platform}-${arch}.tar.gz"
platform=$(get_platform)
arch=$(get_arch)
download_url="https://dl.google.com/go/go${version}.${platform}-${arch}.tar.gz"

http_code=$(curl -I -w '%{http_code}' -s -o /dev/null "$download_url")
if [ "$http_code" -eq 404 ] || [ "$http_code" -eq 403 ]; then
fail "URL: ${download_url} returned status ${http_code}"
fi
http_code=$(curl -I -w '%{http_code}' -s -o /dev/null "$download_url")
if [ "$http_code" -eq 404 ] || [ "$http_code" -eq 403 ]; then
fail "URL: ${download_url} returned status ${http_code}"
fi

curl "$download_url" -o "${download_path}/archive.tar.gz"
curl "$download_url" -o "${download_path}/archive.tar.gz"

if [ "unset" = "${ASDF_GOLANG_SKIP_CHECKSUM:-unset}" ]; then
curl "${download_url}.sha256" -o "${download_path}/archive.tar.gz.sha256"
if [ "unset" = "${ASDF_GOLANG_SKIP_CHECKSUM:-unset}" ]; then
curl "${download_url}.sha256" -o "${download_path}/archive.tar.gz.sha256"

echo 'verifying checksum'
if ! check_shasum "${download_path}/archive.tar.gz" "${download_path}/archive.tar.gz.sha256"; then
fail "Authenticity of package archive can not be assured. Exiting."
else
msg "checksum verified"
fi
echo 'verifying checksum'
if ! check_shasum "${download_path}/archive.tar.gz" "${download_path}/archive.tar.gz.sha256"; then
fail "Authenticity of package archive can not be assured. Exiting."
else
err "checksum skipped"
msg "checksum verified"
fi
else
err "checksum skipped"
fi
}

download_golang "$ASDF_INSTALL_VERSION" "$ASDF_DOWNLOAD_PATH"
14 changes: 7 additions & 7 deletions bin/exec-env
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash

if [ "${ASDF_INSTALL_VERSION}" != 'system' ] ; then
if [[ "unset" == "${GOROOT:-unset}" ]] ; then
export GOROOT=$ASDF_INSTALL_PATH/go
fi
if [ "${ASDF_INSTALL_VERSION}" != 'system' ]; then
if [[ "unset" == "${GOROOT:-unset}" ]]; then
export GOROOT=$ASDF_INSTALL_PATH/go
fi

if [[ "unset" == "${GOPATH:-unset}" ]] ; then
export GOPATH=$ASDF_INSTALL_PATH/packages
fi
if [[ "unset" == "${GOPATH:-unset}" ]]; then
export GOPATH=$ASDF_INSTALL_PATH/packages
fi
fi
6 changes: 3 additions & 3 deletions bin/help.deps
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")/.."
source "$PLUGIN_DIR/lib/helpers.sh"

if [ "$(get_platform silent)" = "darwin" ]; then
echo "coreutils"
echo "coreutils"
else
echo "coreutils"
echo "curl"
echo "coreutils"
echo "curl"
fi
69 changes: 34 additions & 35 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")/.."
# shellcheck source=/dev/null
source "$PLUGIN_DIR/lib/helpers.sh"

install_golang () {
local version="$1"
local download_path="$2"
local install_path="$3"
created_tmp="0"

if [ -z "$download_path" ] ; then
download_path=$(mktemp -dt asdf-golang.XXXX)
created_tmp="1"
ASDF_INSTALL_VERSION="$version" ASDF_DOWNLOAD_PATH="$download_path" "$PLUGIN_DIR/bin/download"
fi

tar -C "$install_path" -xzf "${download_path}/archive.tar.gz"

if [ "1" = "$created_tmp" ]; then
rm -r "$download_path"
fi
install_golang() {
local version="$1"
local download_path="$2"
local install_path="$3"
created_tmp="0"

if [ -z "$download_path" ]; then
download_path=$(mktemp -dt asdf-golang.XXXX)
created_tmp="1"
ASDF_INSTALL_VERSION="$version" ASDF_DOWNLOAD_PATH="$download_path" "$PLUGIN_DIR/bin/download"
fi

tar -C "$install_path" -xzf "${download_path}/archive.tar.gz"

if [ "1" = "$created_tmp" ]; then
rm -r "$download_path"
fi
}

install_default_go_pkgs() {
Expand All @@ -33,40 +33,39 @@ install_default_go_pkgs() {

if [ ! -f "$default_go_pkgs" ]; then return; fi


while read -r line; do
name=$(echo "$line" | \
sed 's|\(.*\) //.*$|\1|' | \
name=$(echo "$line" |
sed 's|\(.*\) //.*$|\1|' |
sed -E 's|^[[:space:]]*//.*||') # the first sed is for comments after package names, the second for full line comments

# Skip empty lines
if [ -z "$name" ]; then continue ; fi
if [ -z "$name" ]; then continue; fi

echo -ne "\nInstalling \033[33m${name}\033[39m go pkg... " >&2

# if using go > 1.16 then use go install as the preferred donwload path
if [ "$go_major_version" -ge 2 ] || [ "${go_minor_version//[!0-9]*}" -ge 16 ]; then
if [[ "$name" != *"@"* ]]; then
name="${name}@latest"
fi

GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go install "$name" > /dev/null && rc=$? || rc=$?
if [ "$go_major_version" -ge 2 ] || [ "${go_minor_version//[!0-9]*/}" -ge 16 ]; then
if [[ $name != *"@"* ]]; then
name="${name}@latest"
fi

GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go install "$name" >/dev/null && rc=$? || rc=$?
else
GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go get -u "$name" > /dev/null && rc=$? || rc=$?
GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go get -u "$name" >/dev/null && rc=$? || rc=$?
fi

if [[ $rc -eq 0 ]]; then
msg "SUCCESS"
else
err "FAIL"
fi
done < "$default_go_pkgs"
done <"$default_go_pkgs"
}

install_golang "$ASDF_INSTALL_VERSION" "${ASDF_DOWNLOAD_PATH:-}" "$ASDF_INSTALL_PATH"
Expand Down
16 changes: 8 additions & 8 deletions bin/latest-stable
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")/.."
# shellcheck source=/dev/null
source "$PLUGIN_DIR/lib/helpers.sh"

command eval "VERSIONS=($("$PLUGIN_DIR"/bin/list-all | tr ' ' '\n' | grep -ivE "(^Available versions:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | grep "^$1" | sed 's/^[[:space:]]\+//'))"
command eval "VERSIONS=($("$PLUGIN_DIR"/bin/list-all | tr ' ' '\n' | grep -ivE '(^Available versions:|-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)' | grep "^$1" | sed 's/^[[:space:]]\+//'))"

platform=$(get_platform true)
arch=$(get_arch)
version=""

for (( i=${#VERSIONS[@]}-1; i>=0; i-- )); do
version="${VERSIONS[i]}"
download_url="https://dl.google.com/go/go${version}.${platform}-${arch}.tar.gz"
http_code=$(curl -I -w '%{http_code}' -s -o /dev/null "$download_url")
if [ "$http_code" -ne 404 ] && [ "$http_code" -ne 403 ]; then
break
fi
for ((i = ${#VERSIONS[@]} - 1; i >= 0; i--)); do
version="${VERSIONS[i]}"
download_url="https://dl.google.com/go/go${version}.${platform}-${arch}.tar.gz"
http_code=$(curl -I -w '%{http_code}' -s -o /dev/null "$download_url")
if [ "$http_code" -ne 404 ] && [ "$http_code" -ne 403 ]; then
break
fi
done

printf "%s" "${version}"
12 changes: 6 additions & 6 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
set -eu
[ "${BASH_VERSINFO[0]}" -ge 3 ] && set -o pipefail

git ls-remote --tags https://github.com/golang/go "go*" \
| awk -F/go '{ print $2 }' \
| uniq \
| sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n \
| grep -v '^1\($\|\.0\|\.0\.[0-9]\|\.1\|\.1rc[0-9]\|\.1\.[0-9]\|.2\|\.2rc[0-9]\|\.2\.1\|.8.5rc5\)$' \
| tr '\n' ' '
git ls-remote --tags https://github.com/golang/go "go*" |
awk -F/go '{ print $2 }' |
uniq |
sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n |
grep -v '^1\($\|\.0\|\.0\.[0-9]\|\.1\|\.1rc[0-9]\|\.1\.[0-9]\|.2\|\.2rc[0-9]\|\.2\.1\|.8.5rc5\)$' |
tr '\n' ' '
20 changes: 10 additions & 10 deletions bin/list-legacy-filenames
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash

case "${ASDF_GOLANG_MOD_VERSION_ENABLED:-}" in
true)
printf ".go-version go.mod go.work\n"
;;
false)
printf ".go-version\n"
;;
*)
cat >&2 <<-EOF
true)
printf ".go-version go.mod go.work\n"
;;
false)
printf ".go-version\n"
;;
*)
cat >&2 <<-EOF
Notice: Behaving like ASDF_GOLANG_MOD_VERSION_ENABLED=true
In the future this will have to be set to continue
reading from the go.mod and go.work files
EOF
printf ".go-version go.mod go.work\n"
;;
printf ".go-version go.mod go.work\n"
;;
esac
4 changes: 2 additions & 2 deletions bin/parse-legacy-file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Since the install path could contain a space, shouldn't this still be quoted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they normally shouldn't be needed here!

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ installed_versions() {

if [ -d "$plugin_installs_path" ]; then
for install in "${plugin_installs_path}"/*/; do
[[ -e "$install" ]] || break
[[ -e $install ]] || break
basename "$install" | sed 's/^ref-/ref:/'
done
fi
Expand All @@ -28,7 +28,7 @@ get_legacy_version() {
current_file="$1"
basename=$(basename -- "$current_file")

if [[ "$basename" =~ ^go.(mod|work)$ ]]; then
if [[ $basename =~ ^go.(mod|work)$ ]]; then
GOLANG_VERSION=$(
grep 'go\s*[0-9]' "$current_file" |
sed -E \
Expand Down
2 changes: 1 addition & 1 deletion bin/uninstall
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

if [ -d "${ASDF_INSTALL_PATH}/packages" ]; then
chmod -R u+wx "${ASDF_INSTALL_PATH}/packages"
chmod -R u+wx "${ASDF_INSTALL_PATH}/packages"
fi

rm -rf "${ASDF_INSTALL_PATH}"
Loading