Last active
April 1, 2024 00:02
-
-
Save redpeacock78/2f0cc6e75a39809a2ad4f0ea25abcf26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # shellcheck disable=SC1009,SC1072,SC1073 | |
| set -eEu | |
| function install_bin() { | |
| function catch() { | |
| echo "" | |
| echo "Interrupting the bin command installation process..." | |
| [[ -f ./bin ]] && rm -rf ./bin | |
| exit 1 | |
| } | |
| trap catch 1 2 3 15 | |
| declare json | |
| declare url | |
| declare name | |
| declare kernel_name | |
| declare hardware_name | |
| kernel_name="$(uname)" | |
| hardware_name="$(uname -m)" | |
| json="$(curl -sL https://api.github.com/repos/marcosnils/bin/releases | jq -r '.[0].assets')" | |
| url="" | |
| name="" | |
| # MacOS | |
| if [[ "${kernel_name}" == "Darwin" ]]; then | |
| # x86_64 | |
| if [[ "${hardware_name}" == "x86_64" ]]; then | |
| url="$(jq -r '.[0].browser_download_url' <<<"${json}")" | |
| name="$(jq -r '.[0].name' <<<"${json}")" | |
| # arm64 | |
| elif [[ "${hardware_name}" == "arm64" ]]; then | |
| url="$(jq -r '.[1].browser_download_url' <<<"${json}")" | |
| name="$(jq -r '.[1].name' <<<"${json}")" | |
| fi | |
| # Linux | |
| elif [[ "${kernel_name}" == "Linux" ]]; then | |
| # x86_64 | |
| if [[ "${hardware_name}" == "x86_64" ]]; then | |
| url="$(jq -r '.[3].browser_download_url' <<<"${json}")" | |
| name="$(jq -r '.[3].name' <<<"${json}")" | |
| elif [[ "${hardware_name}" == "aarch64" ]]; then | |
| url="$(jq -r '.[4].browser_download_url' <<<"${json}")" | |
| name="$(jq -r '.[4].name' <<<"${json}")" | |
| fi | |
| fi | |
| { | |
| echo "==> Downloading ${url}" | |
| curl -L# "${url}" -o "${name}" | |
| mv "${name}" bin | |
| chmod +x bin | |
| ./bin install github.com/marcosnils/bin | |
| bin ls | |
| rm -rf ./bin | |
| } || catch | |
| } | |
| install_bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment