Skip to content

Commit

Permalink
upgrade asdf template to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
0ghny committed Jul 30, 2024
1 parent 08dbe0c commit 750ff0b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 69 deletions.
6 changes: 3 additions & 3 deletions bin/help.deps
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

cat <<-EOM
git
curl
sed
git
curl
sed
EOM
4 changes: 2 additions & 2 deletions bin/help.links
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

cat <<-EOM
Git Repository: https://github.com/gobackup/gobackup
Documentation: https://gobackup.github.io/
Git Repository: https://github.com/gobackup/gobackup
Documentation: https://gobackup.github.io/
EOM
2 changes: 1 addition & 1 deletion bin/help.overview
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

cat <<-EOM
Manage Backup Automation with GoBackup
Manage Backup Automation with GoBackup
EOM
126 changes: 63 additions & 63 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,112 +7,112 @@ TOOL_NAME="gobackup"
TOOL_TEST="gobackup --help"

fail() {
echo -e "asdf-$TOOL_NAME: $*"
exit 1
echo -e "asdf-$TOOL_NAME: $*"
exit 1
}

curl_opts=(-fsSL)

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//'
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//'
}

list_all_versions() {
list_github_tags
list_github_tags
}

download_release() {
local version filename url
local -r platform="$(get_platform)"
local -r arch="$(get_arch)"
version="$1"
filename="$2"
local version filename url
local -r platform="$(get_platform)"
local -r arch="$(get_arch)"
version="$1"
filename="$2"

# https://github.com/huacnlee/gobackup/releases/download/v1.2.0/gobackup-linux-amd64.tar.gz
url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}-${platform}-${arch}.tar.gz"
# https://github.com/huacnlee/gobackup/releases/download/v1.2.0/gobackup-linux-amd64.tar.gz
url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}-${platform}-${arch}.tar.gz"

echo "* Downloading $TOOL_NAME release $version ${platform}/${arch}..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
echo "* Downloading $TOOL_NAME release $version ${platform}/${arch}..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
}

install_version() {
local install_type="$1"
local version="$2"
local install_path="${3%/bin}/bin"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi

(
mkdir -p "$install_path"
echo "Installing from $ASDF_DOWNLOAD_PATH to $install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
test -x "$install_path/$TOOL_NAME" || fail "Expected $install_path/$TOOL_NAME binary not found."
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."

echo "$TOOL_NAME $version installation was successful!"
) || (
rm -rf "$install_path"
fail "An error occurred while installing $TOOL_NAME $version."
)
local install_type="$1"
local version="$2"
local install_path="${3%/bin}/bin"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi

(
mkdir -p "$install_path"
echo "Installing from $ASDF_DOWNLOAD_PATH to $install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
test -x "$install_path/$TOOL_NAME" || fail "Expected $install_path/$TOOL_NAME binary not found."
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."

echo "$TOOL_NAME $version installation was successful!"
) || (
rm -rf "$install_path"
fail "An error occurred while installing $TOOL_NAME $version."
)
}

# .............................................................................
# get_platform: determine platform of running machine
# .............................................................................
get_platform() {
local platform="Linux"
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
darwin) platform="darwin" ;;
linux) platform="linux" ;;
*) platform_not_supported ;;
esac

echo -n $platform
local platform="Linux"
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
darwin) platform="darwin" ;;
linux) platform="linux" ;;
*) platform_not_supported ;;
esac

echo -n $platform
}
# .............................................................................
# get_arch: determine architecture of running machine
# .............................................................................
get_arch() {
local arch="x86_64"
case "$(uname -m)" in
arm64 | aarch64) arch="arm64" ;;
x86_64 | amd64) arch="amd64" ;;
*) architecture_not_supported ;;
esac
echo -n "${arch}"
local arch="x86_64"
case "$(uname -m)" in
arm64 | aarch64) arch="arm64" ;;
x86_64 | amd64) arch="amd64" ;;
*) architecture_not_supported ;;
esac
echo -n "${arch}"
}
# .............................................................................
# get_file_ext: determine file extension based on platform
# .............................................................................
get_file_ext() {
local ext="tar.gz"
case "$(uname | tr '[:upper:]' '[:lower:]')" in
darwin) ext="tar.gz" ;;
linux) ext="tar.gz" ;;
*) platform_not_supported ;;
esac
echo -n "${ext}"
local ext="tar.gz"
case "$(uname | tr '[:upper:]' '[:lower:]')" in
darwin) ext="tar.gz" ;;
linux) ext="tar.gz" ;;
*) platform_not_supported ;;
esac
echo -n "${ext}"
}
# .............................................................................
# platform_not_supported: Raise a platform not supported exception
# .............................................................................
platform_not_supported() {
fail "Platform '$(uname)' not supported!"
fail "Platform '$(uname)' not supported!"
}
# .............................................................................
# architecture_not_supported: Raise an architecture not supported exception
# .............................................................................
architecture_not_supported() {
fail "Platform '$(uname -m)' not supported!"
fail "Platform '$(uname -m)' not supported!"
}

0 comments on commit 750ff0b

Please sign in to comment.