mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-19 12:08:43 +00:00
Make install-from-binstall-release
work with POSIX sh (#1984)
This script would be useful to run in Docker containers, which don't always have `bash` available (e.g. Alpine). It just needs a few small adjustments to make this work, so apply those changes here. Tested this script in an Alpine container.
This commit is contained in:
parent
ec715d4202
commit
fc2684f0d9
1 changed files with 22 additions and 12 deletions
|
@ -1,35 +1,40 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
set -euxo pipefail
|
set -eux
|
||||||
|
|
||||||
if [[ -n "${BINSTALL_VERSION:-}" && "$BINSTALL_VERSION" != v* ]]; then
|
# Set pipefail if it works in a subshell, disregard if unsupported
|
||||||
# prefix version with v
|
# shellcheck disable=SC3040
|
||||||
BINSTALL_VERSION="v$BINSTALL_VERSION"
|
(set -o pipefail 2> /dev/null) && set -o pipefail
|
||||||
fi
|
|
||||||
|
case "${BINSTALL_VERSION:-}" in
|
||||||
|
"") ;; # unset
|
||||||
|
v*) ;; # already includes the `v`
|
||||||
|
*) BINSTALL_VERSION="v$BINSTALL_VERSION" ;; # Add a leading `v`
|
||||||
|
esac
|
||||||
|
|
||||||
cd "$(mktemp -d)"
|
cd "$(mktemp -d)"
|
||||||
|
|
||||||
# Fetch binaries from `[..]/releases/latest/download/[..]` if _no_ version is
|
# Fetch binaries from `[..]/releases/latest/download/[..]` if _no_ version is
|
||||||
# given, otherwise from `[..]/releases/download/VERSION/[..]`. Note the shifted
|
# given, otherwise from `[..]/releases/download/VERSION/[..]`. Note the shifted
|
||||||
# location of '/download'.
|
# location of '/download'.
|
||||||
if [[ -z "${BINSTALL_VERSION:-}" ]]; then
|
if [ -z "${BINSTALL_VERSION:-}" ]; then
|
||||||
base_url="https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-"
|
base_url="https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-"
|
||||||
else
|
else
|
||||||
base_url="https://github.com/cargo-bins/cargo-binstall/releases/download/${BINSTALL_VERSION}/cargo-binstall-"
|
base_url="https://github.com/cargo-bins/cargo-binstall/releases/download/${BINSTALL_VERSION}/cargo-binstall-"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
os="$(uname -s)"
|
os="$(uname -s)"
|
||||||
if [ "$os" == "Darwin" ]; then
|
if [ "$os" = "Darwin" ]; then
|
||||||
url="${base_url}universal-apple-darwin.zip"
|
url="${base_url}universal-apple-darwin.zip"
|
||||||
curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -LO --proto '=https' --tlsv1.2 -sSf "$url"
|
curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -LO --proto '=https' --tlsv1.2 -sSf "$url"
|
||||||
unzip cargo-binstall-universal-apple-darwin.zip
|
unzip cargo-binstall-universal-apple-darwin.zip
|
||||||
elif [ "$os" == "Linux" ]; then
|
elif [ "$os" = "Linux" ]; then
|
||||||
machine="$(uname -m)"
|
machine="$(uname -m)"
|
||||||
if [ "$machine" == "armv7l" ]; then
|
if [ "$machine" = "armv7l" ]; then
|
||||||
machine="armv7"
|
machine="armv7"
|
||||||
fi
|
fi
|
||||||
target="${machine}-unknown-linux-musl"
|
target="${machine}-unknown-linux-musl"
|
||||||
if [ "$machine" == "armv7" ]; then
|
if [ "$machine" = "armv7" ]; then
|
||||||
target="${target}eabihf"
|
target="${target}eabihf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -50,7 +55,12 @@ fi
|
||||||
|
|
||||||
CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
|
CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
|
||||||
|
|
||||||
if ! [[ ":$PATH:" == *":$CARGO_HOME/bin:"* ]]; then
|
case ":$PATH:" in
|
||||||
|
*":$CARGO_HOME/bin:"*) ;; # Cargo home is already in path
|
||||||
|
*) needs_cargo_home=1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -n "${needs_cargo_home:-}" ]; then
|
||||||
if [ -n "${CI:-}" ] && [ -n "${GITHUB_PATH:-}" ]; then
|
if [ -n "${CI:-}" ] && [ -n "${GITHUB_PATH:-}" ]; then
|
||||||
echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
|
echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue