This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.sh
executable file
·161 lines (148 loc) · 3.52 KB
/
bot.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
#!/bin/bash
# setup
tmux_session_bot=dcUniverseBot
repository_url=https://github.com/FHA-FB5/DC-Universe.git
# get applicatio dir and switch to it
application_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $application_dir
# check for test mode
if [ -f "testMode" ]
then
test_mode=true
echo "Info: Script is executed in test mode"
else
test_mode=false
fi
# all functions
start() {
echo "Start bot..."
tmux new-session -d -s $tmux_session_bot \; send-keys "cd $application_dir ;python3 run.py" Enter
}
stop() {
echo "Stop bot..."
tmux kill-session -t $tmux_session_bot
}
restart() {
stop
sleep 5
start
}
# functions
function update_files {
# start
echo "Update files..."
if [ $test_mode == true ]
then
echo "Info: Download is not executed (test mode activated)"
else
cd $application_dir
git clone $repository_url tmp
cp -a tmp/* $application_dir
chmod +x bot.sh
rm -rf tmp
fi
# end
echo "Success: Update completed"
}
function update_requirements {
# start
echo "Update requirements..."
# install all requirements
pip3 install -r requirements.txt
# end
echo "Success: Update completed"
}
function update_database {
# start
echo "Update database..."
# update database
alembic upgrade head
# end
echo "Success: Update completed"
}
function update_all {
update_files
update_requirements
update_database
}
function test_mode {
# check if config file exist
if [ $test_mode == true ]
then
echo "Info: Test mode file was found"
else
echo "Info: Test mode file was not found"
# create test mode file
echo "Create test mode file..."
touch testMode
echo "Success: Creation completed"
fi
}
# check command
case $1 in
"--start" )
start
;;
"--stop" )
stop
;;
"--restart" )
restart
;;
"--update" )
# check mode
case $2 in
"--files"|"-f" )
stop
sleep 2
update_files
sleep 3
start
;;
"--requirements"|"-r" )
stop
sleep 2
update_requirements
sleep 3
start
;;
"--database"|"-db" )
stop
sleep 2
update_database
sleep 3
start
;;
"--all"|"-a" )
stop
sleep 2
update_all
sleep 3
start
;;
*)
echo "Error: Your input was incorrect, please have a look at the list of all commands here: https://github.com/FHA-FB5/DC-Universe/wiki/bot.sh"
exit 1
;;
esac
;;
"--dev" )
# check mode
case $2 in
"--testmode" )
test_mode
;;
*)
echo "Error: Your input was incorrect, please have a look at the list of all commands here: https://github.com/FHA-FB5/DC-Universe/wiki/bot.sh"
exit 1
;;
esac
;;
"--test" )
#does nothing
;;
*)
echo "Error: Your input was incorrect, please have a look at the list of all commands here: https://github.com/FHA-FB5/DC-Universe/wiki/bot.sh"
exit 1
;;
esac