-
Notifications
You must be signed in to change notification settings - Fork 6
/
linux-install.sh
executable file
·109 lines (99 loc) · 3.06 KB
/
linux-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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh
# Copyright 2020 Soluble Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Defaults
soluble_exe=soluble
SOLUBLE_API_URL=${SOLUBLE_API_URL-"https://app.soluble.cloud"}
if [ "$(uname -s)" != "Linux" ]; then
echo "ERROR: not linux"
exit 1
fi
if curl --help > /dev/null 2>&1 ; then
http_get () {
echo $2
curl -L -H "$1" -s "$2"
}
http_download () {
curl -sL "$2"
}
else
http_get () {
wget -O - --header "$1" -q "$2"
}
http_download () {
wget -O - --header "$1" "$2"
}
fi
configure_cli () {
if [ -f "${HOME}/.soluble/cli-config.json" ]; then
echo "soluble config ${HOME}/.soluble/cli-config.json already exists"
elif [ -f "${HOME}/.config/lacework/cli-config.json" ]; then
echo "soluble config ${HOME}/.config/lacework/cli-config.json already exists"
else
if [ "${SOLUBLE_API_URL}" != "" ]; then
echo "Setting SOLUBLE_API_URL=${SOLUBLE_API_URL}"
${soluble_exe} config set APIServer "${SOLUBLE_API_URL}" >/dev/null
fi
if [ "${SOLUBLE_API_TOKEN}" != "" ]; then
echo "Setting SOLUBLE_TOKEN=*******"
${soluble_exe} config set APIToken "${SOLUBLE_API_TOKEN}" >/dev/null
fi
if [ "${SOLUBLE_ORG_ID}" != "" ]; then
echo "Setting SOLUBLE_ORG_ID=${SOLUBLE_ORG_ID}"
${soluble_exe} config set Organization "${SOLUBLE_ORG_ID}" >/dev/null
fi
fi
}
install_cli () {
if [ "$(whoami)" = "root" ]; then
cp ./soluble /usr/local/bin/soluble
chmod +x /usr/local/bin/soluble
else
if [ "$(sudo -n whoami)" = "root" ]; then
sudo -n cp ./soluble /usr/local/bin/soluble
chmod +x /usr/local/bin/soluble
else
echo "Could not install to /usr/local/bin/soluble"
fi
fi
if [ -x "/usr/local/bin/soluble" ]; then
soluble_exe=/usr/local/bin/soluble
fi
}
releases=https://github.com/soluble-ai/soluble-cli/releases
tag="$1"
if [ -z "$tag" ]; then
tag=$(http_get "Accept:application/json" "$releases/latest" | \
grep tag_name | sed 's/.*tag_name":"//' | sed 's/",.*//')
fi
if [ -z "$tag" ]; then
echo "Cannot find a release to install"
exit 1
fi
tarball="$releases/download/${tag}/soluble_${tag}_linux_amd64.tar.gz"
echo "Getting $tarball"
rm -f soluble
http_download "Accept:application/octet-stream" \
"$tarball" | tar zxf - soluble
if [ -f soluble ]; then
echo "Downloaded soluble executable"
chmod a+rx soluble
ls -l ./soluble
./soluble version
install_cli
configure_cli
else
echo "Download failed"
exit 1
fi