Skip to content

install.sh script fixes #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/"