diff --git a/README.md b/README.md index d796bb2..073468e 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,16 @@ more flexibility. ## Installation +As root, using sudo: + ```sh -curl -sSL https://raw.githubusercontent.com/soywod/himalaya/master/install.sh | sh +curl -sSL https://raw.githubusercontent.com/soywod/himalaya/master/install.sh | sudo sh +``` + +As a regular user: + +```sh +curl -sSL https://raw.githubusercontent.com/soywod/himalaya/master/install.sh | PREFIX=~/.local sh ``` Read the Nix section below for a Nix-based installation method. *See the [wiki section](https://github.com/soywod/himalaya/wiki/Installation) diff --git a/install.sh b/install.sh index 88cd81d..48b095b 100644 --- a/install.sh +++ b/install.sh @@ -2,6 +2,11 @@ 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" @@ -12,28 +17,20 @@ case $system in msys*|mingw*|cygwin*|win*) system=windows;; linux|freebsd) system=linux;; darwin) system=macos;; - *) echo "Error: Unsupported system: $system"; exit 1;; + *) die "Unsupported system: $system" ;; esac -if ! tmpdir=$(mktemp -d); then - echo "Error: Failed to create tmpdir" - exit 1 -else - trap "rm -rf $tmpdir" EXIT -fi +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" +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" -if [ -w "$PREFIX" ]; then - mkdir -p "$PREFIX/bin" - cp -f -- "$tmpdir/himalaya.exe" "$PREFIX/bin/himalaya" -else - sudo mkdir -p "$PREFIX/bin" - sudo cp -f -- "$tmpdir/himalaya.exe" "$PREFIX/bin/himalaya" -fi +mkdir -p "$PREFIX/bin" +cp -f -- "$tmpdir/himalaya.exe" "$PREFIX/bin/himalaya" -echo "$("$PREFIX/bin/himalaya" --version) installed!" +die "$("$PREFIX/bin/himalaya" --version) installed!" 0