make install script posix compliant (#53)

* Make install script POSIX compliant

* Update installation docs

* make script more compact

Co-authored-by: Clément DOUIN <soywod@users.noreply.github.com>
This commit is contained in:
Dario Vladović 2021-04-16 10:14:15 +02:00 committed by GitHub
parent 2f018889e0
commit dd45b4bbc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 29 deletions

View file

@ -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)

View file

@ -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"
set -eu
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
return -1
trap "rm -rf $tmpdir" EXIT
fi
}
OS=`get_os`
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!"