forked from cyberark/summon
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·66 lines (51 loc) · 1.75 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
63
64
65
66
#!/usr/bin/env bash
set -e
ARCH=`uname -m`
if [ "${ARCH}" != "x86_64" ]; then
echo "summon only works on 64-bit systems"
echo "exiting installer"
exit 1
fi
DISTRO=`uname | tr "[:upper:]" "[:lower:]"`
if [ "${DISTRO}" != "linux" ] && [ "${DISTRO}" != "darwin" ]; then
echo "This installer only supports Linux and OSX"
echo "exiting installer"
exit 1
fi
if test "x$TMPDIR" = "x"; then
tmp="/tmp"
else
tmp=$TMPDIR
fi
# secure-ish temp dir creation without having mktemp available (DDoS-able but not expliotable)
tmp_dir="$tmp/install.sh.$$"
(umask 077 && mkdir $tmp_dir) || exit 1
# do_download URL DIR
function do_download(){
echo "Downloading $1"
if [[ $(type -t wget) ]]; then wget -q -c -O "$2" "$1" >/dev/null
elif [[ $(type -t curl) ]]; then curl -sSL -C -o "$2" "$1"
else
error "Could not find wget or curl"
return 1
fi
}
# get_latest_version URL
get_latest_version() {
versionloc=${tmp_dir}/summon.version
versionfile=$(do_download ${1} ${versionloc})
local version=$(cat ${versionloc} | grep -o -e "[[:digit:]].[[:digit:]]*.[[:digit:]]*")
echo "${version}"
}
LATEST_VERSION=$(get_latest_version 'https://raw.githubusercontent.com/conjurinc/summon/master/version.go')
BASEURL="https://github.com/conjurinc/summon/releases/download/"
URL=${BASEURL}"v${LATEST_VERSION}/summon_v${LATEST_VERSION}_${DISTRO}_amd64.tar.gz"
ZIP_PATH="${tmp_dir}/summon.tar.gz"
do_download ${URL} ${ZIP_PATH}
echo "Installing summon v${LATEST_VERSION} into /usr/local/bin"
sudo tar -C /usr/local/bin -zxvf ${ZIP_PATH}
if [ -d "/etc/bash_completion.d" ]; then
do_download "https://raw.githubusercontent.com/conjurinc/summon/master/script/complete_summon" "/etc/bash_completion.d/complete_summon"
fi
echo "Success!"
echo "Run summon -h for usage"