-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_bot.sh
executable file
·111 lines (93 loc) · 2.25 KB
/
start_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
#!/usr/bin/env bash
set -e
set -o pipefail
CONTAINER_PREFIX="hbot-"
COMPOSE_FILE_NAME="hbot.compose.yml"
ENV_FILE=".env"
help()
{
echo "
Usage: ./start_bot.sh [ -n | --id ]
[ -p | --psk ]
[ -f | --strategy-file ]
[ -d | --detach ]
[ -h | --help ]"
exit 2
}
SHORT=n:,p:,f:,d:,h
LONG=id:,psk:,strategy-file:,detach,help
OPTS=$(getopt -a -n start_bot.sh --options $SHORT --longoptions $LONG -- "$@")
VALID_ARGUMENTS=$# # Returns the count of arguments that are in short or long options
if [ "$VALID_ARGUMENTS" -eq 0 ]; then
help
fi
eval set -- "$OPTS"
while :
do
case "$1" in
-n | --id )
HBOT_ID="$2"
shift 2
;;
-p | --psk )
HBOT_PSK="$2"
shift 2
;;
-f | --strategy-file )
HBOT_FILE="$2"
shift 2
;;
-d | --detach )
DETACH=1
shift;
;;
-h | --help)
help
;;
--)
shift;
break
;;
*)
echo "Unexpected option: $1"
help
;;
esac
done
if [ -z $HBOT_ID ]; then
HBOT_ID=$(python -c 'import uuid; print(uuid.uuid4())')
fi
if [ "$HBOT_ID" == "" ]; then
HBOT_ID=$(python -c 'import uuid; print(uuid.uuid4())')
fi
CONTAINER_NAME=${CONTAINER_PREFIX}${HBOT_ID}
set -o allexport
source $ENV_FILE
set +o allexport
echo """
Creating hbot container with
Bot Parameters:
- Id: ${HBOT_ID}
- Passphrase: ${HBOT_PSK}
- Strategy file: ${HBOT_FILE}
- Detach: ${DETACH}
Deployment Parameters:
- Image: ${HBOT_IMAGE}
- Memory Limit (Mb): ${HBOT_MEM_LIMIT}
- Memory Reservation (Mb): ${HBOT_MEM_RESERVATION}
"""
if [ "$(docker ps -q -f name=${CONTAINER_NAME})" ]; then
echo "[*] Instance ${CONTAINER_NAME} already running."
fi
if [ ! -z $DETACH ]; then
DETACH_CONTAINER="--detach"
else
DETACH_CONTAINER=""
fi
HBOT_ID=${HBOT_ID} HBOT_PSK=${HBOT_PSK} HBOT_FILE=${HBOT_FILE} \
HBOT_IMAGE=${HBOT_IMAGE} \
docker compose -f ${COMPOSE_FILE_NAME} run \
--rm \
${DETACH_CONTAINER} \
--name ${CONTAINER_NAME} \
hbot