From 750ff0bd50b8150ff7ad0714042e07a8b08b49db Mon Sep 17 00:00:00 2001 From: 0ghny <6640409+0ghny@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:37:32 +0200 Subject: [PATCH] upgrade asdf template to latest version --- bin/help.deps | 6 +-- bin/help.links | 4 +- bin/help.overview | 2 +- lib/utils.bash | 126 +++++++++++++++++++++++----------------------- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/bin/help.deps b/bin/help.deps index 9eed179..4ddeab1 100644 --- a/bin/help.deps +++ b/bin/help.deps @@ -1,7 +1,7 @@ #!/usr/bin/env bash cat <<-EOM -git -curl -sed + git + curl + sed EOM diff --git a/bin/help.links b/bin/help.links index d6cf414..fca9936 100644 --- a/bin/help.links +++ b/bin/help.links @@ -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 diff --git a/bin/help.overview b/bin/help.overview index 542dc06..b23d5d3 100644 --- a/bin/help.overview +++ b/bin/help.overview @@ -1,5 +1,5 @@ #!/usr/bin/env bash cat <<-EOM -Manage Backup Automation with GoBackup + Manage Backup Automation with GoBackup EOM diff --git a/lib/utils.bash b/lib/utils.bash index 7b359e3..b1bd3d4 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -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!" }