2021-04-16 08:14:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2021-04-18 09:00:06 +00:00
|
|
|
die() {
|
|
|
|
printf '%s\n' "$1" >&2
|
|
|
|
exit "${2-1}"
|
|
|
|
}
|
|
|
|
|
2021-05-08 20:52:43 +00:00
|
|
|
DESTDIR="${DESTDIR:-}"
|
2021-04-16 08:14:15 +00:00
|
|
|
PREFIX="${PREFIX:-"$DESTDIR/usr/local"}"
|
|
|
|
RELEASES_URL="https://github.com/soywod/himalaya/releases"
|
|
|
|
|
|
|
|
system=$(uname -s | tr [:upper:] [:lower:])
|
|
|
|
case $system in
|
2021-05-08 20:52:43 +00:00
|
|
|
msys*|mingw*|cygwin*|win*) system=windows; binary=himalaya.exe;;
|
|
|
|
linux|freebsd) system=linux; binary=himalaya;;
|
|
|
|
darwin) system=macos; binary=himalaya;;
|
2021-04-18 09:00:06 +00:00
|
|
|
*) die "Unsupported system: $system" ;;
|
2021-04-16 08:14:15 +00:00
|
|
|
esac
|
|
|
|
|
2021-04-18 09:00:06 +00:00
|
|
|
tmpdir=$(mktemp -d) || die "Failed to create tmpdir"
|
|
|
|
trap "rm -rf $tmpdir" EXIT
|
2021-04-16 08:14:15 +00:00
|
|
|
|
|
|
|
echo "Downloading latest $system release…"
|
2021-04-18 09:00:06 +00:00
|
|
|
curl -sLo "$tmpdir/himalaya.tar.gz" \
|
|
|
|
"$RELEASES_URL/latest/download/himalaya-$system.tar.gz"
|
2021-04-16 08:14:15 +00:00
|
|
|
|
2021-01-17 15:03:38 +00:00
|
|
|
echo "Installing binary…"
|
2021-04-16 08:14:15 +00:00
|
|
|
tar -xzf "$tmpdir/himalaya.tar.gz" -C "$tmpdir"
|
|
|
|
|
2021-04-18 09:00:06 +00:00
|
|
|
mkdir -p "$PREFIX/bin"
|
2021-05-08 20:52:43 +00:00
|
|
|
cp -f -- "$tmpdir/$binary" "$PREFIX/bin/$binary"
|
2021-01-17 15:03:38 +00:00
|
|
|
|
2024-03-07 17:41:56 +00:00
|
|
|
# See User Unit Search Path in `man systemd.unit(5)`
|
|
|
|
if [ "$system" = "linux" ] && [ "$PREFIX" = "/usr" ]; then
|
|
|
|
mkdir -p "$PREFIX/lib/systemd/user"
|
|
|
|
sed "s:%install_dir%:$PREFIX/bin:" "$tmpdir/assets/himalaya-watch@.service" \
|
|
|
|
> "$PREFIX/lib/systemd/user/himalaya-watch@.service"
|
|
|
|
fi
|
|
|
|
|
2021-05-08 20:52:43 +00:00
|
|
|
die "$("$PREFIX/bin/$binary" --version) installed!" 0
|