-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·77 lines (68 loc) · 2.1 KB
/
setup.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
#!/usr/bin/env bash
# Output coloring
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Check if docker is installed and working
if ! command -v docker &> /dev/null
then
echo -e "${RED}ERROR: Docker is not installed or not in the system path${NC}"
exit 1
fi
if ! docker ps &> /dev/null
then
echo -e "${RED}ERROR: Docker is installed but not working properly${NC}"
exit 1
fi
# Check if docker-compose is installed and working
if ! command -v docker-compose &> /dev/null
then
echo -e "${RED}ERROR: Docker Compose is not installed or not in the system path${NC}"
exit 1
fi
if ! docker-compose ps &> /dev/null
then
echo -e "${RED}ERROR: Docker Compose is installed but not working properly${NC}"
exit 1
fi
# Check if at least one argument is given
if [[ $# -lt 1 ]]; then
echo -e "${RED}Error: at least one argument, 'start' or 'stop' is required!${NC}"
exit 1
fi
# Check if the first argument is start or stop
if [[ "$1" != "start" && "$1" != "stop" ]]; then
echo -e "${RED}Error: the first argument must be 'start' or 'stop'!${NC}"
exit 1
fi
# Check if there is no second argument for stop
if [[ "$1" == "stop" ]] && [[ $# -gt 1 ]]; then
echo -e "${RED}Error: 'stop' do not accept a second argument!${NC}"
exit 1
fi
# Check if there is a second argument for start
if [[ "$1" == "start" && $# -lt 2 ]]; then
echo -e "${RED}Error: 'start' requires a second argument ('client', 'server', 'database')!${NC}"
exit 1
fi
# Check if the second argument is client, server, or database for start
if [[ "$1" == "start" && "$2" != "client" && "$2" != "server" && "$2" != "database" ]]; then
echo -e "${RED}Error: the second argument must be 'client', 'server', or 'database' for 'start'!${NC}"
exit 1
fi
# Start or stop the service according to the first argument
case "$1" in
start)
if [[ "$2" == "database" ]]; then
service="database mailhog"
else
service="$2"
fi
echo -e "${GREEN}Starting $service...${NC}"
eval "docker-compose up -d --build $service"
;;
stop)
echo -e "${GREEN}Stopping all services...${NC}"
docker-compose down
;;
esac