From 1e7613a06d8d049f597071ba64d1091db00a60e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 22 Nov 2018 03:30:33 +0100 Subject: [PATCH] Prettify install script (#248) @zaquestion --- install.sh | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/install.sh b/install.sh index 443f8f6e..ea848d7c 100755 --- a/install.sh +++ b/install.sh @@ -1,27 +1,43 @@ #!/usr/bin/env bash set -e -[[ -z $DEBUG ]] || set -x -if [ $EUID != 0 ]; then +if [[ ! -z $DEBUG ]]; then + set -x +fi + +if [[ $EUID != 0 ]]; then sudo "$0" "$@" - exit $? + exit "$?" fi -machine="" -case $(uname -m) in -x86_64) machine="amd64";; -i386) machine="386";; +case "$(uname -m)" in + x86_64) + machine="amd64" + ;; + i386) + machine="386" + ;; + *) + machine="" + ;; esac -os="" case $(uname -s) in -Linux) os="linux";; -Darwin) os="darwin";; -*) echo "OS not supported" && exit 1;; + Linux) + os="linux" + ;; + Darwin) + os="darwin" + ;; + *) + echo "OS not supported" + exit 1 + ;; esac -latest=$(curl -sL 'https://api.github.com/repos/zaquestion/lab/releases/latest' | grep tag_name | grep --only 'v[0-9\.]\+' | cut -c2-) +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/"