From ff682b2f54d8148f95bbe24242ff3bc6033f5373 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 11:41:21 +0000 Subject: [PATCH 1/8] install.sh: allow user to customize install location Fixes #262 --- install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index ea848d7c..0b29ea4e 100755 --- a/install.sh +++ b/install.sh @@ -6,6 +6,9 @@ if [[ ! -z $DEBUG ]]; then set -x fi +: ${PREFIX:=/usr/local} +BINDIR="$PREFIX/bin" + if [[ $EUID != 0 ]]; then sudo "$0" "$@" exit "$?" @@ -39,5 +42,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/" +cp /tmp/lab $BINDIR/lab +echo "Successfully installed lab into $BINDIR/" From ac34b507e5e6cc66c8a694742646a8b5a55d6c3a Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 11:44:17 +0000 Subject: [PATCH 2/8] install.sh: verify that the install location can be used --- install.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/install.sh b/install.sh index 0b29ea4e..23ef2bfe 100755 --- a/install.sh +++ b/install.sh @@ -9,11 +9,23 @@ fi : ${PREFIX:=/usr/local} BINDIR="$PREFIX/bin" +_can_install() { + if [[ ! -d "$BINDIR" ]]; then + mkdir -p "$BINDIR" 2> /dev/null + fi + [[ -d "$BINDIR" && -w "$BINDIR" ]] +} + if [[ $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" From ba666c77b6bdc77ebed2b5f2d1e97763df857a5c Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 11:44:49 +0000 Subject: [PATCH 3/8] install.sh: don't invoke sudo if it isn't needed --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 23ef2bfe..b9f8d0a2 100755 --- a/install.sh +++ b/install.sh @@ -16,7 +16,7 @@ _can_install() { [[ -d "$BINDIR" && -w "$BINDIR" ]] } -if [[ $EUID != 0 ]]; then +if ! _can_install && [[ $EUID != 0 ]]; then sudo "$0" "$@" exit "$?" fi From 19e4d77aba238ef8503c2e53ab0ced6f152f8ade Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 11:45:30 +0000 Subject: [PATCH 4/8] 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index b9f8d0a2..996e63ad 100755 --- a/install.sh +++ b/install.sh @@ -55,4 +55,5 @@ latest="$(curl -sL 'https://api.github.com/repos/zaquestion/lab/releases/latest' curl -sL "https://github.com/zaquestion/lab/releases/download/v${latest}/lab_${latest}_${os}_${machine}.tar.gz" | tar -C /tmp/ -xzf - cp /tmp/lab $BINDIR/lab +chmod +x $BINDIR/lab echo "Successfully installed lab into $BINDIR/" From 8edc2918ef0dd3541f399273272d51656754628d Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 11:58:20 +0000 Subject: [PATCH 5/8] install.sh: error out if an unset variable is used --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 996e63ad..0c02163d 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -set -e +set -eu -if [[ ! -z $DEBUG ]]; then +if [[ ! -z ${DEBUG-} ]]; then set -x fi From 560aa3c10d968c6a9c3ba5db010fb683a6751b2e Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 11:59:07 +0000 Subject: [PATCH 6/8] install.sh: error out if part of a pipe chain fails --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 0c02163d..00065167 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eu +set -eu -o pipefail if [[ ! -z ${DEBUG-} ]]; then set -x From 75042785118371f45a93b515377977c83b030586 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 12:10:11 +0000 Subject: [PATCH 7/8] 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/install.sh b/install.sh index 00065167..600f2785 100755 --- a/install.sh +++ b/install.sh @@ -9,6 +9,10 @@ fi : ${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 From ec5ffe7edd1cf577412f8b22dd366543251e3346 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Thu, 13 Dec 2018 12:13:43 +0000 Subject: [PATCH 8/8] install.sh: replace `cp+chmod` with `install` --- install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 600f2785..6a724182 100755 --- a/install.sh +++ b/install.sh @@ -58,6 +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 $BINDIR/lab -chmod +x $BINDIR/lab +install -m755 /tmp/lab $BINDIR/lab echo "Successfully installed lab into $BINDIR/"