forked from zaquestion/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·62 lines (51 loc) · 1.12 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
set -eu -o pipefail
if [[ ! -z ${DEBUG-} ]]; then
set -x
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
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"
;;
i386)
machine="386"
;;
*)
machine=""
;;
esac
case $(uname -s) in
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 -c 2-)"
curl -sL "https://github.com/zaquestion/lab/releases/download/v${latest}/lab_${latest}_${os}_${machine}.tar.gz" | tar -C /tmp/ -xzf -
install -m755 /tmp/lab $BINDIR/lab
echo "Successfully installed lab into $BINDIR/"