2024-02-19 21:40:27 -08:00
|
|
|
#!/usr/bin/env sh
|
2020-02-20 06:32:06 -08:00
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
set -eu
|
2021-05-27 23:16:45 -07:00
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -n "${GITHUB_ACTIONS-}" ]; then
|
2021-05-27 23:16:45 -07:00
|
|
|
set -x
|
|
|
|
fi
|
2020-02-20 06:32:06 -08:00
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
# Check pipefail support in a subshell, ignore if unsupported
|
|
|
|
# shellcheck disable=SC3040
|
|
|
|
(set -o pipefail 2> /dev/null) && set -o pipefail
|
|
|
|
|
2020-02-20 06:32:06 -08:00
|
|
|
help() {
|
|
|
|
cat <<'EOF'
|
|
|
|
Install a binary release of a just hosted on GitHub
|
|
|
|
|
2021-05-27 23:16:45 -07:00
|
|
|
USAGE:
|
2024-07-01 11:36:14 -07:00
|
|
|
install.sh [options]
|
2020-02-20 06:32:06 -08:00
|
|
|
|
2021-05-27 23:16:45 -07:00
|
|
|
FLAGS:
|
2020-02-20 06:32:06 -08:00
|
|
|
-h, --help Display this message
|
|
|
|
-f, --force Force overwriting an existing binary
|
2021-05-27 23:16:45 -07:00
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--tag TAG Tag (version) of the crate to install, defaults to latest release
|
2023-01-24 13:54:01 -08:00
|
|
|
--to LOCATION Where to install the binary [default: ~/bin]
|
2021-05-27 23:16:45 -07:00
|
|
|
--target TARGET
|
2020-02-20 06:32:06 -08:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
crate=just
|
|
|
|
url=https://github.com/casey/just
|
|
|
|
releases=$url/releases
|
|
|
|
|
|
|
|
say() {
|
2024-02-19 21:40:27 -08:00
|
|
|
echo "install: $*" >&2
|
2020-02-20 06:32:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
err() {
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -n "${td-}" ]; then
|
2024-01-13 01:40:01 -08:00
|
|
|
rm -rf "$td"
|
2020-02-20 06:32:06 -08:00
|
|
|
fi
|
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
say "error: $*"
|
2020-02-20 06:32:06 -08:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
need() {
|
2024-02-19 21:40:27 -08:00
|
|
|
if ! command -v "$1" > /dev/null 2>&1; then
|
2020-02-20 06:32:06 -08:00
|
|
|
err "need $1 (command not found)"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-05-20 17:20:24 -07:00
|
|
|
download() {
|
|
|
|
url="$1"
|
|
|
|
output="$2"
|
|
|
|
|
|
|
|
if command -v curl > /dev/null; then
|
|
|
|
curl --proto =https --tlsv1.2 -sSfL "$url" "-o$output"
|
|
|
|
else
|
|
|
|
wget --https-only --secure-protocol=TLSv1_2 --quiet "$url" "-O$output"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-02-20 06:32:06 -08:00
|
|
|
force=false
|
|
|
|
while test $# -gt 0; do
|
|
|
|
case $1 in
|
|
|
|
--force | -f)
|
|
|
|
force=true
|
|
|
|
;;
|
|
|
|
--help | -h)
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--tag)
|
|
|
|
tag=$2
|
|
|
|
shift
|
|
|
|
;;
|
2021-05-27 23:16:45 -07:00
|
|
|
--target)
|
|
|
|
target=$2
|
|
|
|
shift
|
|
|
|
;;
|
2020-02-20 06:32:06 -08:00
|
|
|
--to)
|
|
|
|
dest=$2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2024-05-20 17:20:24 -07:00
|
|
|
say "error: unrecognized argument '$1'. Usage:"
|
|
|
|
help
|
|
|
|
exit 1
|
2020-02-20 06:32:06 -08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2024-05-20 17:20:24 -07:00
|
|
|
command -v curl > /dev/null 2>&1 ||
|
|
|
|
command -v wget > /dev/null 2>&1 ||
|
|
|
|
err "need wget or curl (command not found)"
|
|
|
|
|
2020-02-20 06:32:06 -08:00
|
|
|
need mkdir
|
|
|
|
need mktemp
|
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -z "${tag-}" ]; then
|
2024-01-13 01:40:01 -08:00
|
|
|
need grep
|
|
|
|
need cut
|
2023-01-04 11:12:19 -08:00
|
|
|
fi
|
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -z "${target-}" ]; then
|
2024-01-13 01:40:01 -08:00
|
|
|
need cut
|
2020-02-20 06:32:06 -08:00
|
|
|
fi
|
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -z "${dest-}" ]; then
|
2023-01-24 13:54:01 -08:00
|
|
|
dest="$HOME/bin"
|
2020-02-20 06:32:06 -08:00
|
|
|
fi
|
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -z "${tag-}" ]; then
|
2024-01-13 01:40:01 -08:00
|
|
|
tag=$(
|
2024-05-20 17:20:24 -07:00
|
|
|
download https://api.github.com/repos/casey/just/releases/latest - |
|
2022-05-02 20:49:46 -07:00
|
|
|
grep tag_name |
|
|
|
|
cut -d'"' -f4
|
|
|
|
)
|
2020-02-20 06:32:06 -08:00
|
|
|
fi
|
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -z "${target-}" ]; then
|
2024-01-24 16:03:18 -08:00
|
|
|
# bash compiled with MINGW (e.g. git-bash, used in github windows runners),
|
2023-01-04 11:12:19 -08:00
|
|
|
# unhelpfully includes a version suffix in `uname -s` output, so handle that.
|
|
|
|
# e.g. MINGW64_NT-10-0.19044
|
|
|
|
kernel=$(uname -s | cut -d- -f1)
|
2024-02-19 21:40:27 -08:00
|
|
|
uname_target="$(uname -m)-$kernel"
|
2021-05-27 23:16:45 -07:00
|
|
|
|
|
|
|
case $uname_target in
|
2024-07-01 11:36:14 -07:00
|
|
|
aarch64-Linux) target=aarch64-unknown-linux-musl;;
|
|
|
|
arm64-Darwin) target=aarch64-apple-darwin;;
|
|
|
|
armv6l-Linux) target=arm-unknown-linux-musleabihf;;
|
|
|
|
armv7l-Linux) target=armv7-unknown-linux-musleabihf;;
|
|
|
|
x86_64-Darwin) target=x86_64-apple-darwin;;
|
|
|
|
x86_64-Linux) target=x86_64-unknown-linux-musl;;
|
2023-01-04 11:12:19 -08:00
|
|
|
x86_64-MINGW64_NT) target=x86_64-pc-windows-msvc;;
|
2024-01-13 01:40:01 -08:00
|
|
|
x86_64-Windows_NT) target=x86_64-pc-windows-msvc;;
|
2021-05-27 23:16:45 -07:00
|
|
|
*)
|
2024-02-19 21:40:27 -08:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
err 'Could not determine target from output of `uname -m`-`uname -s`, please use `--target`:' "$uname_target"
|
2021-05-27 23:16:45 -07:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2023-01-04 11:12:19 -08:00
|
|
|
case $target in
|
2024-01-13 01:40:01 -08:00
|
|
|
x86_64-pc-windows-msvc) extension=zip; need unzip;;
|
2024-07-01 11:36:14 -07:00
|
|
|
*) extension=tar.gz; need tar;;
|
2023-01-04 11:12:19 -08:00
|
|
|
esac
|
|
|
|
|
|
|
|
archive="$releases/download/$tag/$crate-$tag-$target.$extension"
|
2020-02-20 06:32:06 -08:00
|
|
|
|
2024-01-13 01:40:01 -08:00
|
|
|
say "Repository: $url"
|
|
|
|
say "Crate: $crate"
|
|
|
|
say "Tag: $tag"
|
|
|
|
say "Target: $target"
|
|
|
|
say "Destination: $dest"
|
|
|
|
say "Archive: $archive"
|
2020-02-20 06:32:06 -08:00
|
|
|
|
|
|
|
td=$(mktemp -d || mktemp -d -t tmp)
|
2023-01-04 11:12:19 -08:00
|
|
|
|
|
|
|
if [ "$extension" = "zip" ]; then
|
2024-05-20 17:20:24 -07:00
|
|
|
download "$archive" "$td/just.zip"
|
2024-02-19 21:40:27 -08:00
|
|
|
unzip -d "$td" "$td/just.zip"
|
2023-01-04 11:12:19 -08:00
|
|
|
else
|
2024-05-20 17:20:24 -07:00
|
|
|
download "$archive" - | tar -C "$td" -xz
|
2023-01-04 11:12:19 -08:00
|
|
|
fi
|
2020-02-20 06:32:06 -08:00
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
if [ -e "$dest/just" ] && [ "$force" = false ]; then
|
2024-01-13 01:40:01 -08:00
|
|
|
err "\`$dest/just\` already exists"
|
|
|
|
else
|
2024-02-19 21:40:27 -08:00
|
|
|
mkdir -p "$dest"
|
2024-07-01 11:36:14 -07:00
|
|
|
cp "$td/just" "$dest/just"
|
|
|
|
chmod 755 "$dest/just"
|
2024-01-13 01:40:01 -08:00
|
|
|
fi
|
2020-02-20 06:32:06 -08:00
|
|
|
|
2024-02-19 21:40:27 -08:00
|
|
|
rm -rf "$td"
|