Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix install script #1844

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 27 additions & 37 deletions www/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -80,29 +76,29 @@ 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
need grep
need cut
fi

if [ -z ${target-} ]; then
need cut
need cut
fi

if [ -z ${dest-} ]; then
dest="$HOME/bin"
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
)
Expand All @@ -120,48 +116,42 @@ 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;;
x86_64-pc-windows-msvc) extension=zip; need unzip;;
*) extension=tar.gz;;
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
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
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"
else
mkdir -p $dest
install -m 755 $td/$f $dest
fi
done
if [ -e "$dest/just" ] && [ $force = false ]; then
err "\`$dest/just\` already exists"
else
mkdir -p $dest
install -m 755 "$td/just" $dest
fi

rm -rf $td