diff --git a/README.md b/README.md index 8a1740c..c44715d 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ more flexibility. ## Installation -```bash -curl -sSL https://raw.githubusercontent.com/soywod/himalaya/master/install.sh | bash +```sh +curl -sSL https://raw.githubusercontent.com/soywod/himalaya/master/install.sh | sh ``` *See the [wiki section](https://github.com/soywod/himalaya/wiki/Installation) diff --git a/install.sh b/install.sh index 065cbba..88cd81d 100644 --- a/install.sh +++ b/install.sh @@ -1,32 +1,39 @@ -#!/bin/bash +#!/bin/sh -get_os () { - if [[ "$OSTYPE" == "linux-gnu" ]]; then - echo "linux" - elif [[ "$OSTYPE" == "freebsd"* ]]; then - echo "linux" - elif [[ "$OSTYPE" == "darwin"* ]]; then - echo "macos" - elif [[ "$OSTYPE" == "cygwin" ]]; then - echo "windows" - elif [[ "$OSTYPE" == "msys" ]]; then - echo "windows" - elif [[ "$OSTYPE" == "win32" ]]; then - echo "windows" - else - return -1 - fi -} +set -eu -OS=`get_os` +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;; + *) echo "Error: Unsupported system: $system"; exit 1;; +esac + +if ! tmpdir=$(mktemp -d); then + echo "Error: Failed to create tmpdir" + exit 1 +else + trap "rm -rf $tmpdir" EXIT +fi + +echo "Downloading latest $system release…" +curl -sLo "$tmpdir/himalaya.tar.gz" "$RELEASES_URL/latest/download/himalaya-$system.tar.gz" -cd /tmp -echo "Downloading latest ${OS} release…" -curl -sLo himalaya.tar.gz "https://github.com/soywod/himalaya/releases/latest/download/himalaya-${OS}.tar.gz" echo "Installing binary…" -tar -xzf himalaya.tar.gz -rm himalaya.tar.gz -chmod u+x himalaya.exe -sudo mv himalaya.exe /usr/local/bin/himalaya +tar -xzf "$tmpdir/himalaya.tar.gz" -C "$tmpdir" -echo "$(himalaya --version) installed!" +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 + +echo "$("$PREFIX/bin/himalaya" --version) installed!"