Skip to content

Commit c5f632e

Browse files
committed
Merge pull request #3 from CoScale/feature/install-script
Feature/install script
2 parents 1b01d5b + 3347d6b commit c5f632e

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

install.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
3+
4+
#
5+
# Show url after getting latest version
6+
# Improve output formatting
7+
#
8+
9+
set -u
10+
set -e
11+
12+
echo
13+
echo "## Checking configuration and environment"
14+
echo
15+
16+
if [ -z ${COSCALE_APPID+x} ] || [ -z ${COSCALE_TOKEN+x} ]; then
17+
echo "### Configuration"
18+
echo
19+
# Check command arguments
20+
if [ -z ${COSCALE_APPID+x} ]; then
21+
echo "Please enter your app id:"
22+
read -e -r COSCALE_APPID
23+
fi
24+
echo
25+
26+
if [ -z ${COSCALE_TOKEN+x} ]; then
27+
echo "Please enter your access token:"
28+
read -e -r COSCALE_TOKEN
29+
fi
30+
echo
31+
fi
32+
33+
# Detect operation system
34+
echo "### Detecting operating system"
35+
echo
36+
os=$(uname -o | awk '{split($0,a,"/"); print tolower(a[2])}')
37+
echo "Operation system: $os"
38+
echo
39+
40+
# Fetch latest release list from Github
41+
echo
42+
echo "## Getting latest release information"
43+
echo
44+
github_data=$(curl -s -L https://api.github.com/repos/CoScale/coscale-cli/releases/latest | grep "browser_download_url" | awk '{ print $2; }' | sed 's/"//g')
45+
46+
# Select correct release
47+
release=`echo "$github_data" | grep "$os"`
48+
echo "### Latest release: $release"
49+
50+
# Start install
51+
echo
52+
echo "## Installing CoScale CLI tool"
53+
echo
54+
55+
# Create dirs
56+
echo "### Creating directories /opt/coscale/cli"
57+
echo
58+
mkdir -v -p /opt/coscale/cli
59+
pushd /opt/coscale/cli
60+
echo
61+
62+
# Install client
63+
echo "### Downloading client to /opt/coscale/cli/coscale-cli"
64+
curl -L "$release" > coscale-cli
65+
chmod -v +x coscale-cli
66+
echo
67+
68+
# Create symlink from /usr/bin/coscale-cli to /opt/coscale/cli/coscale-cli
69+
echo "### Creating symlink"
70+
ln -v -s /opt/coscale/cli/coscale-cli /usr/bin/coscale-cli
71+
echo
72+
73+
# Create config
74+
echo "Generating config"
75+
echo "{\"baseurl\":\"https://api.coscale.com\", \"appid\":\"$COSCALE_APPID\", \"accesstoken\":\"$COSCALE_TOKEN\"}" | gzip -c > /opt/coscale/cli/api.conf
76+
echo
77+
78+
# Test config
79+
echo "Testing configuration"
80+
./coscale-cli check-config | sed -e 's/[{}]//g' | awk --field-separator=":" '{print $2 }'
81+
echo
82+
83+
# Done
84+
echo "Done, you can now start using the CoScale CLI tool."
85+
popd

0 commit comments

Comments
 (0)