Skip to content

Commit

Permalink
install.sh script fixes (#263)
Browse files Browse the repository at this point in the history
* install.sh: allow user to customize install location

Fixes #262

* install.sh: verify that the install location can be used

* install.sh: don't invoke sudo if it isn't needed

* install.sh: make sure `lab` is executable

If /tmp is mounted with the noexec option, the execution bit is dropped.
Let's make sure to add it back in the install script.

* install.sh: error out if an unset variable is used

* install.sh: error out if part of a pipe chain fails

* install.sh: allow exact location of binary to be specified

By passing it as the first argument to the script.

Not that the argument overrides the environment, in case both are set.

* install.sh: replace `cp+chmod` with `install`
  • Loading branch information
1ace authored and zaquestion committed Dec 15, 2018
1 parent 751950f commit 396a7c2
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
#!/usr/bin/env bash

set -e
set -eu -o pipefail

if [[ ! -z $DEBUG ]]; then
if [[ ! -z ${DEBUG-} ]]; then
set -x
fi

if [[ $EUID != 0 ]]; then
: ${PREFIX:=/usr/local}
BINDIR="$PREFIX/bin"

if [[ $# -gt 0 ]]; then
BINDIR=$1
fi

_can_install() {
if [[ ! -d "$BINDIR" ]]; then
mkdir -p "$BINDIR" 2> /dev/null
fi
[[ -d "$BINDIR" && -w "$BINDIR" ]]
}

if ! _can_install && [[ $EUID != 0 ]]; then
sudo "$0" "$@"
exit "$?"
fi

if ! _can_install; then
echo "Can't install to $BINDIR"
exit 1
fi

case "$(uname -m)" in
x86_64)
machine="amd64"
Expand Down Expand Up @@ -39,5 +58,5 @@ esac
latest="$(curl -sL 'https://api.github.com/repos/zaquestion/lab/releases/latest' | grep 'tag_name' | grep --only 'v[0-9\.]\+' | cut -c 2-)"

curl -sL "https://github.com/zaquestion/lab/releases/download/v${latest}/lab_${latest}_${os}_${machine}.tar.gz" | tar -C /tmp/ -xzf -
cp /tmp/lab /usr/local/bin/lab
echo "Successfully installed lab into /usr/local/bin/"
install -m755 /tmp/lab $BINDIR/lab
echo "Successfully installed lab into $BINDIR/"

0 comments on commit 396a7c2

Please sign in to comment.