Fix install script (#1844)

This commit is contained in:
Casey Rodarmor 2024-01-13 01:40:01 -08:00 committed by GitHub
parent 639ed74c23
commit 22d462bd55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,19 +30,15 @@ url=https://github.com/casey/just
releases=$url/releases
say() {
echo "install: $@"
}
say_err() {
say "$@" >&2
echo "install: $@" >&2
}
err() {
if [ ! -z ${td-} ]; then
rm -rf $td
rm -rf "$td"
fi
say_err "error: $@"
say "error: $@"
exit 1
}
@ -80,14 +76,12 @@ while test $# -gt 0; do
shift
done
# Dependencies
need curl
need install
need mkdir
need mktemp
need tar
# Optional dependencies
if [ -z ${tag-} ]; then
need grep
need cut
@ -102,7 +96,9 @@ if [ -z ${dest-} ]; then
fi
if [ -z ${tag-} ]; then
tag=$(curl --proto =https --tlsv1.2 -sSf https://api.github.com/repos/casey/just/releases/latest |
tag=$(
curl --proto =https --tlsv1.2 -sSf \
https://api.github.com/repos/casey/just/releases/latest |
grep tag_name |
cut -d'"' -f4
)
@ -120,15 +116,14 @@ if [ -z ${target-} ]; then
arm64-Darwin) target=aarch64-apple-darwin;;
x86_64-Darwin) target=x86_64-apple-darwin;;
x86_64-Linux) target=x86_64-unknown-linux-musl;;
x86_64-Windows_NT) target=x86_64-pc-windows-msvc;;
x86_64-MINGW64_NT) target=x86_64-pc-windows-msvc;;
x86_64-Windows_NT) target=x86_64-pc-windows-msvc;;
*)
err 'Could not determine target from output of `uname -m`-`uname -s`, please use `--target`:' $uname_target
;;
esac
fi
# windows archives are zips, not tarballs
case $target in
x86_64-pc-windows-msvc) extension=zip; need unzip;;
*) extension=tar.gz;;
@ -136,32 +131,27 @@ esac
archive="$releases/download/$tag/$crate-$tag-$target.$extension"
say_err "Repository: $url"
say_err "Crate: $crate"
say_err "Tag: $tag"
say_err "Target: $target"
say_err "Destination: $dest"
say_err "Archive: $archive"
say "Repository: $url"
say "Crate: $crate"
say "Tag: $tag"
say "Target: $target"
say "Destination: $dest"
say "Archive: $archive"
td=$(mktemp -d || mktemp -d -t tmp)
if [ "$extension" = "zip" ]; then
# unzip on windows cannot always handle stdin, so download first.
curl --proto =https --tlsv1.2 -sSfL $archive > $td/just.zip
unzip -d $td $td/just.zip
else
curl --proto =https --tlsv1.2 -sSfL $archive | tar -C $td -xz
fi
for f in $(ls $td); do
test -x $td/$f || continue
if [ -e "$dest/$f" ] && [ $force = false ]; then
err "$f already exists in $dest"
if [ -e "$dest/just" ] && [ $force = false ]; then
err "\`$dest/just\` already exists"
else
mkdir -p $dest
install -m 755 $td/$f $dest
install -m 755 "$td/just" $dest
fi
done
rm -rf $td