himalaya/install.sh
Gregory Chamberlain 82ce67f572
improve portability of install.sh (#107)
* Replace echo with printf

The echo(1) command varies among sh implementations.  Some interpret
hyphen command-line options.

It would be unusual, but in theory if $PREFIX began with a hyphen or
two then this usage of echo might cause an error or unknown behaviour
in such implementations.

The printf(1) command is consistent across shell implementations.

* Leave privilege elevation to the user

* Add die function

* Break long line
2021-04-18 11:00:06 +02:00

36 lines
850 B
Bash

#!/bin/sh
set -eu
die() {
printf '%s\n' "$1" >&2
exit "${2-1}"
}
DESTDIR="${DESTDIR:-/}"
PREFIX="${PREFIX:-"$DESTDIR/usr/local"}"
RELEASES_URL="https://github.com/soywod/himalaya/releases"
system=$(uname -s | tr [:upper:] [:lower:])
case $system in
msys*|mingw*|cygwin*|win*) system=windows;;
linux|freebsd) system=linux;;
darwin) system=macos;;
*) die "Unsupported system: $system" ;;
esac
tmpdir=$(mktemp -d) || die "Failed to create tmpdir"
trap "rm -rf $tmpdir" EXIT
echo "Downloading latest $system release…"
curl -sLo "$tmpdir/himalaya.tar.gz" \
"$RELEASES_URL/latest/download/himalaya-$system.tar.gz"
echo "Installing binary…"
tar -xzf "$tmpdir/himalaya.tar.gz" -C "$tmpdir"
mkdir -p "$PREFIX/bin"
cp -f -- "$tmpdir/himalaya.exe" "$PREFIX/bin/himalaya"
die "$("$PREFIX/bin/himalaya" --version) installed!" 0