-
Notifications
You must be signed in to change notification settings - Fork 0
/
decipher-install.sh
executable file
·86 lines (78 loc) · 2.27 KB
/
decipher-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
cdcdbin/bash
INFO=1
DEBUG=1
FLD=".decipher"
CURDIR=`pwd`
# add_api function
add_api () {
echo "[ACTION] Do you already have your API token ready? (y/n)?"
unset READY
read READY
while [[ ! ${READY} =~ ^(y|n)$ ]]; do
[[ $INFO -eq 1 ]] && echo "[ERROR] Cannot recognise input; accepting y or n"
read READY
done
if [ ${READY} = "n" ]; then
echo "[INFO] In order to get your API token, follow these instructions
1.) go/okta
2.) Select decipher
3.) Click your profile on the top right
4.) Click API access in the drop down menu
5.) Hit 'Create new API key'
6.) Copy this to your clipboard (CMD+C)
7.) Paste this value in the next step"
fi
echo "[ACTION] Please enter your API token"
unset TOKEN
read -s TOKEN
while [[ ! ${#TOKEN} -eq 64 ]]; do
echo "[ERROR] Token must be 64 characters long"
read -s TOKEN
done
echo "[INFO] Token accepted"
echo "APITOKEN=${TOKEN}" >> config
}
cd ~
# Checking if folder exists
[[ $INFO -eq 1 ]] && echo "[INFO] Checking if ${FLD} exists"
if [ ! -d "${FLD}" ]; then
[[ $INFO -eq 1 ]] && echo "[INFO] Creating ${FLD} in ~"
mkdir "${FLD}"
else
[[ $INFO -eq 1 ]] && echo "[INFO] OK"
fi
# Checking if conifg file exists
cd ${FLD}
[[ $INFO -eq 1 ]] && echo "[INFO] Checking if config file exists"
if [ ! -f "config" ]; then
[[ $INFO -eq 1 ]] && echo "[INFO] Creating config file"
touch "config"
else
[[ $INFO -eq 1 ]] && echo "[INFO] OK"
fi
# Checking if api-token is present
[[ $INFO -eq 1 ]] && echo "[INFO] Checking API token presence"
if grep -q APITOKEN "config"; then
[[ $INFO -eq 1 ]] && echo "[ACTION] An api-token was found. Do you want to update it (y/n)?"
unset UPDATE
read UPDATE
while [[ ! ${UPDATE} =~ ^(y|n)$ ]]; do
[[ $INFO -eq 1 ]] && echo "[ERROR] Cannot recognise input; accepting y or n"
read UPDATE
done
if [ ${UPDATE} = "y" ]; then
sed -i '' '/^APITOKEN/d' config
add_api
else
[[ $INFO -eq 1 ]] && echo "[INFO] Not making any changes"
fi
else
add_api
fi
# Decipher login attempt
[[ $INFO -eq 1 ]] && echo "[INFO] Attempt to log-in with API key"
[[ $INFO -eq 1 ]] && echo "[INFO] Advise: use option 1 (64-character API key) which should be in your clipboard"
beacon login
# Create link
sudo ln -s "python ${CURDIR}/main.py" /usr/local/bin/dtk
echo "\nDone!\n\nNow run 'dtk' in terminal to activate the program\n\n"