-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.sh
executable file
·237 lines (190 loc) · 7.63 KB
/
run.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
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIRNAME=`basename ${DIR}`
DIRNAME_LW=`echo ${DIRNAME} | awk '{print tolower($0)}'`
NAME=`basename "${0}"`
#
# -> VARS
#
ALIAS="${DIRNAME_LW}"
#
# <- VARS
#
#
# -> FUNCTIONS
#
function print_usage() {
echo "Usage: ${0} -h | --help"
echo "Usage: ${0} <-r|--run> | <-s|--stop> | <-c|--clean> | <-l|--log>"
exit 0
}
function print_help(){
# http://patorjk.com/software/taag/#p=display&t=ACMbot
echo -e "\e[94m" '
█████╗ ██████╗███╗ ███╗██████╗ ██████╗ ████████╗
██╔══██╗██╔════╝████╗ ████║██╔══██╗██╔═══██╗╚══██╔══╝
███████║██║ ██╔████╔██║██████╔╝██║ ██║ ██║
██╔══██║██║ ██║╚██╔╝██║██╔══██╗██║ ██║ ██║
██║ ██║╚██████╗██║ ╚═╝ ██║██████╔╝╚██████╔╝ ██║
╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝
'"\e[0m"
# http://www.glassgiant.com/ascii/
echo -e "\e[94m" '
......................................MMN ......................................
....................................MMMMMMM ....................................
.......................... ........MMMMMMMMM....................................
................. ... ......... MMMMMMMMMMMMM ............... ..... .. . .. ..
................................MMMMMMMMMMMMMMM,..................... ..... .. .
..............................MMMMMMMMMMMMMMMMMMM ..............................
............................,MMMMMMMMMMMMMMMMMMMMM$.............................
...........................MMMMMMMMMMMMMMMMMMMMMMMMM............................
.........................MMMMMMMMMMMMMMMMMMMMMMMMMMMMM .........................
........................MMMMMMMMMMMM$. ..IMMMMMMMMMMMM.........................
......................MMMMMMMM,................. MMMMMMMM ......................
.... ..............MMMMMM .....DMMMMMMMMMMMM......MMMMMM,.....................
...................MMMMMM ...~MMMMMMMMMMMMMMMMMMMO... MMMMMM ...................
..................MMMMM... MMMMMMMMMMMMMMMMMMMMMMMMM....MMMMM$..................
............... MMMMM... MMMMMMMMMMMMMMMMMMMMMMMMMMMMM....MMMMM.................
..............7MMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM...MMMMMM ..............
.............MMMMMM.. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM...MMMMMM. ............
..... ... MMMMMMM ..MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . MMMMMMM ...........
..... ....MMMMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM...MMMMMMM, .........
..... MMMMMMMMM..MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM..7MMMMMMMM ........
..... ,MMMMMMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM ..MMMMMMMMM$ ......
.... MMMMMMMMMMM..MMMM: .. MMMMMMMMM....8MO::MM...$MMN...MMMM..DMMMMMMMMMM. ....
...$MMMMMMMMMMM...MMM.. .....MMMM.......NMM................MM...MMMMMMMMMMMM ...
. MMMMMMMMMMMMM.. MMMMMMMM....MM....MMMMMMM...MMM....MMD...MM:..MMMMMMMMMMMMM, .
MMMMMMMMMMMMMMM.. MMMO........MM...MMMMMMMM...MMM ...MMM...MMM..MMMMMMMMMMMMMMM.
MMMMMMMMMMMMMMM.. MM ...MM,...MM...MMMMMMMM...MMM ...MMM...MMM..MMMMMMMMMMMMMMM
. MMMMMMMMMMMMM.. MM...MMM....MM....MMMMMMM...MMM ...MMM...MM...MMMMMMMMMMMMM...
...:MMMMMMMMMMM...MM.... ....MMM.......?MM...MMM ...MMM...MM...MMMMMMMMMMMN....
.... MMMMMMMMMMM..MMMM ..MM~==MMMMMN....MMM===MMM:==+MMM===MM..NMMMMMMMMMM......
.......MMMMMMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM...MMMMMMMMM=.......
........MMMMMMMMM..MMMMMMMMMM.MMM..M....NMM..MMM..MMMMMMMMMM..OMMMMMMMM.........
..... ... MMMMMMM...MMMMMMMMM.MMM. M. MM.NM..8M.$.MMMMMMMMM...MMMMMMM...........
...........MMMMMMM ..MMMMMMMM.MMM. M..M. M$.I M M.MMMMMMMM.. MMMMMMM............
.............MMMMMM...MMMMMMM.MMM..M..MMMM..M..~M.MMMMMMM ..MMMMMM..............
..............,MMMMM...DMMMMM,....MM..MMMM..M..MM.MMMMMM...MMMMM8.. ............
.... ...........MMMMM... MMMMMMMMMMMMMMMMMMMMMMMMMMMMM,...MMMMM ................
..................MMMMM... MMMMMMMMMMMMMMMMMMMMMMMMM....MMMMM~..................
...................MMMMMM ....MMMMMMMMMMMMMMMMMMM~... MMMMMM....................
........ ........... MMMMMM .... +MMMMMMMMMMMZ......MMMMMM .....................
..... ..............MMMMMMMM$................ :MMMMMMMN.......................
........................MMMMMMMMMMMMM=. .:NMMMMMMMMMMMM.........................
.........................DMMMMMMMMMMMMMMMMMMMMMMMMMMMM..........................
...........................MMMMMMMMMMMMMMMMMMMMMMMMM............................
.............................MMMMMMMMMMMMMMMMMMMMM=.............................
..............................MMMMMMMMMMMMMMMMMMM...............................
.... ..........................MMMMMMMMMMMMMMM.................................
.... ...........................MMMMMMMMMMMMM..................................
... .. ...........................MMMMMMMMM....................................
.... . .............................8MMMMMM.....................................
......................................MMM.......................................
......................................,........................................
GlassGiant.com
'"\e[0m"
echo -e "\e[92m" '
USAGE:
./run_res.sh -h | --help
./run_res.sh <opt>
opt:
-r | --run Build and run bot inside container
-s | --stop Stop container bot and --clean
-c | --clean Remove image and container
-l | --log See running container log
'
exit 0
}
function _pick_log() {
_getAlias
docker cp ${ALIAS}:/logger.log ${DIR}
docker logs -f ${ALIAS} &>> ${DIR}/container.log
}
function _setAlias(){
export ALIAS=${1}
}
function _getAlias(){
export ALIAS=${ALIAS}
}
function _func_build(){
_getAlias
docker build \
--quiet \
--file Dockerfile \
--tag ${ALIAS} \
${DIR} > /dev/null 2>&1
echo "${NAME}: Build ${ALIAS}"
}
function _func_run(){
_getAlias
_func_stop
_func_build
docker run \
--detach \
--name ${ALIAS} \
--log-driver=json-file \
${ALIAS} > /dev/null 2>&1
echo "${NAME}: Running ${ALIAS} ..."
}
function _func_clean() {
_getAlias
docker rm ${ALIAS} > /dev/null 2>&1
docker rmi ${ALIAS} > /dev/null 2>&1
echo "${NAME}: Clean ${ALIAS}"
}
function _func_stop(){
_getAlias
docker stop ${ALIAS} > /dev/null 2>&1
echo "${NAME}: Stop ${ALIAS}"
_pick_log
_func_clean
}
function log() {
_getAlias
docker logs -f ${ALIAS}
}
function main() {
argc=$#
argv=( "$@" )
# check arguments
if [[ $# -eq 0 ]]; then
print_usage
exit 0
fi
TEMP=$(getopt -o rsclh --long run,stop,clean,log,h,help, -- "${argv[@]}")
ex=$?
[ ${ex} -eq 2 ] && echo "Parameter is not correct." && exit 1
[ ${ex} -ne 0 ] && echo "Error in getopt" && exit 1
eval set -- "${TEMP}"
while true ; do
case ${1} in
-a|--alias)
_setAlias ${1}
shift 2 ;;
-r|--run)
_func_run
shift 1 ;;
-s|--stop)
_func_stop
shift 1 ;;
-c|--clean)
_func_clean
shift 1 ;;
-h|-help|--h|--help )
print_help ; exit 0 ;;
--) shift ; break ;;
*) print_usage; exit 1 ;;
esac
done
}
#
# <- FUNCTIONS
#
#
# -> MAIN
#
main "$@"
exit $?
#
# <- MAIN
#