This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 155
/
installer.sh
executable file
·367 lines (310 loc) · 12.4 KB
/
installer.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/bash
# === Description ======================================================================================================
#
# This file contains the installation procedure to get up and running with Freqtrade and the MoniGoMani HyperStrategy.
#
# === Requirements =====================================================================================================
#
# - UNIX Distro, macOS, or a POSIX compliant WSL Distro (sh, bash, command, mktemp, pwd, rm, /dev/null)
# - Python 3 (ttps://realpython.com/installing-python/)
# - Pip3 (https://pypi.org/project/pip/)
# - Pyenv (https://github.com/pyenv/pyenv-installer#pyenv-installer/)
# - Git (https://gist.github.com/derhuerst/1b15ff4652a867391f03)
# - cURL (https://www.tecmint.com/install-curl-in-linux/)
# - Expect (https://core.tcl-lang.org/expect/index)
#
# Ubuntu Specific Notes:
# - Python-venv (The installer will prompt you how to install)
#
# Windows Specific Notes:
# This script has been made with the intention to run on UNIX systems and it makes use of UNIX command line tools..
# However if you really have no other option, it should also be able to run under WSL (Windows Subsystem for Linux)!
# - See for installation: https://docs.microsoft.com/en-us/windows/wsl/install-win10
# - Then change 'sh' to 'bash': https://unix.stackexchange.com/a/442517
#
# === Usage ============================================================================================================
#
# /usr/bin/env sh <(curl -s "https://raw.githubusercontent.com/Rikj000/MoniGoMani/development/installer.sh")
#
# === Settings =========================================================================================================
INSTALL_FOLDER_NAME="Freqtrade-MGM" # By default the folder will be created under the current working directory
MGM_REPO_URL="https://github.com/Rikj000/MoniGoMani.git"
MGM_BRANCH="development"
MGM_COMMIT=""
SHELL_CONFIGS=(
~/.bashrc
~/.config/fish/config.fish
~/.zshrc
)
# ======================================================================================================================
usage() {
cat << EOF
Usage:
/usr/bin/env sh installer.sh [options]
Example:
/usr/bin/env sh installer.sh --dir="./targetdir" --mgm_branch="feature/xyz" --mgm_commit="abcd1337"
Optional options:
-h, --help Show this help.
--dir=<path> Path to directory to install Freqtrade with MoniGoMani.
Will be created or overwritten when it's existing.
--mgm_url=<url> URL to Git repository. (eg. https://github.com/Rikj000/MoniGoMani.git)
--mgm_branch=<branch> Specific branch to checkout from Git repository. (eg. development)
--mgm_commit=<commit hash> Specific commit hash to checkout from Git repository.
(Note: will skip --mgm_branch if set)
--dev-break Break before launching MGM-Hurry
EOF
exit 0
}
CURRENT_DIR=$(pwd)
INSTALL_DIR="$CURRENT_DIR/$INSTALL_FOLDER_NAME"
# ANSI text coloring
BLUE='\033[94m'
CYAN='\033[0;36m'
DARKCYAN='\033[36m'
GREEN='\033[0;32m'
PURPLE='\033[95m'
RED='\033[0;31m'
WHITE='\033[1;37m'
YELLOW='\033[1;33m'
NOCOLOR='\033[0m'
UNDERLINE='\033[4m'
ITALIC="\e[3m"
BOLD='\033[1m'
END='\033[m'
# Loop through arguments and process them
DEV_BREAK="false"
for arg in "$@"
do
case $arg in
--dir=*)
INSTALL_DIR="${arg#*=}"
shift
;;
--mgm_url=*)
MGM_REPO_URL="${arg#*=}"
shift
;;
--mgm_branch=*)
MGM_BRANCH="${arg#*=}"
shift
;;
--mgm_commit=*)
MGM_COMMIT="${arg#*=}"
shift
;;
--dev-break)
DEV_BREAK="true"
shift
;;
-h|--help)
usage
shift
;;
*)
echo ""
echo -e "${RED} 🙉 installer.sh - Illegal argument(s) used!${END}"
echo ""
echo " Please see the 'installer.sh --help' output below for the correct usage:"
usage
shift # Remove generic argument from processing
;;
esac
done
##################
confirm() {
local _prompt _default _response
_prompt="Are you sure?"
if [ "$1" ]; then _prompt="$1"; fi
_prompt2="$_prompt [y/n]"
if [ "$2" ]; then _prompt2="$_prompt $2"; fi
# Loop forever until the user enters a valid response (Y/N or Yes/No).
while true; do
read -r -p " $_prompt2
" _response
case "$_response" in
[Yy][Ee][Ss]|[Yy]) # Yes or Y (case-insensitive).
REPLY="0"
return $REPLY
;;
[Nn][Oo]|[Nn]) # No or N.
REPLY="1"
return $REPLY
;;
[Hh]) # H or h. H stands for Half.
REPLY="2"
return $REPLY
;;
*) # Anything else (including a blank) is invalid.
;;
esac
done
}
do_exit() {
echo " cancel."
echo ""
echo -e "${WHITE} 😽 KTHXBAI ${END}"
echo ""
exit 1
}
trap do_exit SIGINT
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
echo -e "${WHITE} ⛱️ Welcome aboard! Let's get started ...${END}"
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
echo ""
confirm "👉 MoniGoMani will automatically share test results created with it's community, are you okay with this?" "(y/n)"
if [ "$REPLY" == "1" ] # 1 = False, why shell why..
then
echo -e "${RED} Aborting installation... (This project is only intended for users who seek to contribute to the MGM community)${END}"
do_exit
exit 1
fi
echo ""
echo -e "${WHITE} 🚦 Requirements check${END}"
echo -e "${WHITE} ======================${END}"
echo ""
# Ensure that python3 is installed
command -v python3 >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED} 🙉 Python3 is not installed. Can't proceed. See: https://realpython.com/installing-python/${END}"
exit 1
fi
echo -e "${GREEN} ✅ Python3 is installed.${END}"
# Ensure that pip3 is installed
command -v pip3 >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED} 🙉 Pip3 is not installed. Can't proceed. See: https://pypi.org/project/pip/${END}"
exit 1
fi
echo -e "${GREEN} ✅ Pip3 is installed.${END}"
# Ensure that pyenv is installed
command -v pyenv >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED} 🙉 Pyenv is not installed. Can't proceed. See: https://github.com/pyenv/pyenv-installer#pyenv-installer/${END}"
exit 1
fi
echo -e "${GREEN} ✅ Pyenv is installed.${END}"
# Ensure that python3-venv is installed
OS=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
if [ "$OS" == "\"Ubuntu\"" -o "$OS" == "\"Debian\"" ]; then
VENV_PACKAGE_NAME="`readlink -f $(which python3) | awk -F'/' '{print $NF}'`-venv"
dpkg -s $VENV_PACKAGE_NAME | grep "ok installed" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED} 🙉 Python3-venv is not installed. Can't proceed. install it with: sudo apt install ${VENV_PACKAGE_NAME}${END}"
exit 1
fi
echo -e "${GREEN} ✅ Python3-venv is installed.${END}"
fi
# Ensure that git is installed
command -v git >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED} 🙉 Git is not installed. Can't proceed. See: https://gist.github.com/derhuerst/1b15ff4652a867391f03${END}"
exit 1
fi
echo -e "${GREEN} ✅ Git is installed.${END}"
# Ensure that cURL is installed
command -v curl >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED} 🙉 cURL is not installed. Can't proceed. See: https://www.tecmint.com/install-curl-in-linux/${END}"
exit 1
fi
echo -e "${GREEN} ✅ cURL is installed.${END}"
# Ensure that expect is installed
command -v expect >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED} 🙉 Expect is not installed. Can't proceed. See: https://core.tcl-lang.org/expect/index${END}"
exit 1
fi
echo -e "${GREEN} ✅ Expect is installed.${END}"
echo ""
confirm "👉 Are you ready to proceed?" "(y/n)"
if [ "$REPLY" == "1" ] # 1 = False, why shell why..
then
do_exit
exit 1
fi
echo ""
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo -e "${WHITE} ⚙️ Downloading required files...${END}"
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
git clone -n "$MGM_REPO_URL" "$INSTALL_DIR/monigomani"
if [ "$MGM_COMMIT" != "" ]; then
cd "$INSTALL_DIR/monigomani" && git checkout -b "detached_by_installer" "$MGM_COMMIT"
else
cd "$INSTALL_DIR/monigomani" && git checkout "$MGM_BRANCH"
fi
if [ "$DEV_BREAK" == "true" ]; then
echo ""
echo "⚙️ Dev break - Waiting to allow replacement of modified MGM files before launching MGM-Hurry..."
confirm "👉 Are you ready to proceed?" "(y/n)"
if [ "$REPLY" == "1" ] # 1 = False, why shell why..
then
do_exit
exit 1
fi
fi
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo -e "${WHITE} ⚙️ Installing pipenv...${END}"
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
echo -e "${ITALIC}(Some errors which are usually safe to ignore might occur during the installation of pip & pipenv)${END}"
echo ""
python3 -m pip install --upgrade pip
if [ "$OS" == "\"Ubuntu\"" ]; then
sudo apt install -y libffi-dev
fi
cd "$INSTALL_DIR" && python3 -m pip install pipenv
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo -e "${WHITE} ⚙️ Setting up virtual environment with python dependency packages...${END}"
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
cp "$INSTALL_DIR/monigomani/Pipfile" "$INSTALL_DIR/" # && cp "$INSTALL_DIR/monigomani/Pipfile.lock" "$INSTALL_DIR/"
cd "$INSTALL_DIR" && python3 -m pipenv install
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo -e "${WHITE} ⚙️ Proceeding to Freqtrade & MoniGoMani installation...${END}"
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
cd "$INSTALL_DIR" && python3 -m pipenv run python3 "$INSTALL_DIR"/monigomani/mgm-hurry up
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo -e "${WHITE} ⚙️ Setting up shell alias...${END}"
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
echo "You can now run MGM-hurry commands with: 'python3 -m pipenv run python3 ./mgm-hurry ...' only from inside: $INSTALL_DIR"
echo ""
confirm "👉 Do you want to add a shell alias so you can run MGM-hurry commands more easily from all over your system as 'mgm-hurry ...'?" "(y/n)"
if [ "$REPLY" == "0" ] # 1 = False, why shell why..
then
for SHELL_CONFIG in "${SHELL_CONFIGS[@]}"; do
# Make sure all Shell config files exist
touch "$SHELL_CONFIG"
if [ "$SHELL_CONFIG" != ~/.config/fish/config.fish ]; then
echo "" >> "$SHELL_CONFIG"
echo "# MGM-Hurry shell alias" >> "$SHELL_CONFIG"
echo "mgm-hurry() { pushd "$INSTALL_DIR" &> /dev/null; python3 -m pipenv run python3 ./mgm-hurry '\$@'; popd &> /dev/null; }" >> "$SHELL_CONFIG"
else
FISH_FUNCTION=~/.config/fish/functions/mgm-hurry.fish
mkdir -p ~/.config/fish/functions/; touch "$FISH_FUNCTION";
echo "function mgm-hurry" >> "$FISH_FUNCTION"
echo "pushd "$INSTALL_DIR" &> /dev/null; python3 -m pipenv run python3 ./mgm-hurry \$argv; popd &> /dev/null;" >> "$FISH_FUNCTION"
echo "end" >> "$FISH_FUNCTION"
fi
done
echo -e "${CYAN}🎉 Shell aliases have been set! Please close & re-open your terminal for the aliases to become active!"${END}
fi
echo ""
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""
echo -e "${CYAN} 🎉 You are all set! We hope you enjoy your ride.${END}"
echo ""
echo -e "${WHITE}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${END}"
echo ""