forked from dcamarmas/creator
-
Notifications
You must be signed in to change notification settings - Fork 6
/
container_start.sh
executable file
·77 lines (59 loc) · 1.73 KB
/
container_start.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
#!/bin/bash
#
# Default values
#
TARGET_BOARD=esp32c3
TARGET_PORT=/dev/ttyUSB0
#
# Auxiliar functions
#
intro() {
echo ""
echo " CREATOR Gateway"
echo " ---------------"
echo ""
}
usage() {
echo " Usage: $0 [--target_board esp32c3] \\"
echo " [--target_port /dev/ttyUSB0] \\"
echo ""
}
info() {
echo " * Target Board: "${TARGET_BOARD}
echo " * Target Port: "${TARGET_PORT}
echo ""
}
get_opts() {
# Taken the general idea from https://stackoverflow.com/questions/70951038/how-to-use-getopt-long-option-in-bash-script
name=$(basename "$0")
short_opt=b:,p:,h
long_opt=target_board:,target_port:,help
TEMP=$(getopt -o $short_opt --long $long_opt --name "$name" -- "$@")
eval set -- "${TEMP}"
while :; do
case "${1}" in
-b | --target_board ) TARGET_BOARD=$2; shift 2 ;;
-p | --target_port ) TARGET_PORT=$2; shift 2 ;;
-h | --help ) intro; usage; exit 0 ;;
-- ) shift; break ;;
* ) intro; echo " > ERROR: parsing arguments found an error :-/"; usage; exit 1 ;;
esac
done
}
#
# Main
#
# Check arguments, and print it
get_opts $@
intro
info
docker pull creatorsim/creator_gateway
if [[ -n $(docker container ls -q --filter name=creator_gateway) ]]; then
docker container stop $(docker container ls -q --filter name=creator_gateway)
fi
docker container rm creator_gateway
if [ $# -ne 0 ]; then
docker build -t creatorsim/creator_gateway . --build-arg TARGET_BOARD=${TARGET_BOARD}
fi
docker run --init -it --device=${TARGET_PORT} -p 8080:8080 --name creator_gateway creatorsim/creator_gateway /bin/bash
echo " Done."