Skip to content

Commit

Permalink
Merge pull request #9 from CramBL/better-install-script
Browse files Browse the repository at this point in the history
Better install script
  • Loading branch information
CramBL authored Jul 1, 2024
2 parents 2b01fef + ca82568 commit 0b26270
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions scripts/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ need() {
fi
}

need_one_of() {
has_one="false"
for cmd in "$@"; do
if command -v "$cmd" > /dev/null 2>&1; then
has_one="true"
break
fi
done
if [ $has_one = "false" ]; then
err "need one of $* (none of the commands were found)"
fi
}

download() {
url="$1"
output="$2"
Expand All @@ -66,6 +79,17 @@ download() {
fi
}

install_bin() {
src="$1"
dst="$2"
if command -v install > /dev/null; then
install -m 755 "$src" "$dest"
else
cp "$src" "$dst"
chmod 755 "$dst"
fi
}

force=false
while test $# -gt 0; do
case $1 in
Expand Down Expand Up @@ -94,11 +118,10 @@ while test $# -gt 0; do
shift
done

need curl
need install
need_one_of curl wget
need_one_of tar unzip
need mkdir
need mktemp
need tar

if [ -z "${tag-}" ]; then
need grep
Expand Down Expand Up @@ -130,6 +153,8 @@ if [ -z "${target-}" ]; then

case $uname_target in
aarch64-Linux) target=aarch64-unknown-linux-musl;;
armv7l-Linux) target=armv7-unknown-linux-musleabihf;;
armv6l-Linux) target=arm-unknown-linux-musleabihf;;
arm64-Darwin) target=aarch64-apple-darwin;;
x86_64-Darwin) target=x86_64-apple-darwin;;
x86_64-Linux) target=x86_64-unknown-linux-musl;;
Expand All @@ -143,8 +168,8 @@ if [ -z "${target-}" ]; then
fi

case $target in
x86_64-pc-windows-msvc) extension=zip; need unzip;;
*) extension=tar.gz;;
x86_64-pc-windows-msvc) extension=zip; need unzip;;
*) extension=tar.gz; need tar;;
esac

archive="$RELEASES/download/$tag/$BIN_NAME-$tag-$target.$extension"
Expand All @@ -170,7 +195,7 @@ if [ -e "$dest/${BIN_NAME}" ] && [ "$force" = false ]; then
err "\`$dest/${BIN_NAME}\` already exists"
else
mkdir -p "$dest"
install -m 755 "$td/${BIN_NAME}" "$dest"
install_bin "$td/${BIN_NAME}" "$dest"
fi

rm -rf "$td"

0 comments on commit 0b26270

Please sign in to comment.