diff --git a/www/install.sh b/www/install.sh index f932554..a97fa3d 100755 --- a/www/install.sh +++ b/www/install.sh @@ -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,21 +76,19 @@ 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 @@ -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,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