mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 09:05:13 +00:00
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
This commit is contained in:
parent
c405280c92
commit
82ce67f572
10
README.md
10
README.md
|
@ -50,8 +50,16 @@ more flexibility.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
As root, using sudo:
|
||||||
|
|
||||||
```sh
|
```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)
|
Read the Nix section below for a Nix-based installation method. *See the [wiki section](https://github.com/soywod/himalaya/wiki/Installation)
|
||||||
|
|
29
install.sh
29
install.sh
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
die() {
|
||||||
|
printf '%s\n' "$1" >&2
|
||||||
|
exit "${2-1}"
|
||||||
|
}
|
||||||
|
|
||||||
DESTDIR="${DESTDIR:-/}"
|
DESTDIR="${DESTDIR:-/}"
|
||||||
PREFIX="${PREFIX:-"$DESTDIR/usr/local"}"
|
PREFIX="${PREFIX:-"$DESTDIR/usr/local"}"
|
||||||
RELEASES_URL="https://github.com/soywod/himalaya/releases"
|
RELEASES_URL="https://github.com/soywod/himalaya/releases"
|
||||||
|
@ -12,28 +17,20 @@ case $system in
|
||||||
msys*|mingw*|cygwin*|win*) system=windows;;
|
msys*|mingw*|cygwin*|win*) system=windows;;
|
||||||
linux|freebsd) system=linux;;
|
linux|freebsd) system=linux;;
|
||||||
darwin) system=macos;;
|
darwin) system=macos;;
|
||||||
*) echo "Error: Unsupported system: $system"; exit 1;;
|
*) die "Unsupported system: $system" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if ! tmpdir=$(mktemp -d); then
|
tmpdir=$(mktemp -d) || die "Failed to create tmpdir"
|
||||||
echo "Error: Failed to create tmpdir"
|
trap "rm -rf $tmpdir" EXIT
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
trap "rm -rf $tmpdir" EXIT
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Downloading latest $system release…"
|
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…"
|
echo "Installing binary…"
|
||||||
tar -xzf "$tmpdir/himalaya.tar.gz" -C "$tmpdir"
|
tar -xzf "$tmpdir/himalaya.tar.gz" -C "$tmpdir"
|
||||||
|
|
||||||
if [ -w "$PREFIX" ]; then
|
mkdir -p "$PREFIX/bin"
|
||||||
mkdir -p "$PREFIX/bin"
|
cp -f -- "$tmpdir/himalaya.exe" "$PREFIX/bin/himalaya"
|
||||||
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!"
|
die "$("$PREFIX/bin/himalaya" --version) installed!" 0
|
||||||
|
|
Loading…
Reference in a new issue