forked from webvirtcloud/webvirtcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebvirtcloud.sh
executable file
·138 lines (118 loc) · 3.21 KB
/
webvirtcloud.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
#!/usr/bin/env bash
set -e
cat << "EOF"
__ __ _ __ ___ _ ____ _ _
\ \ / ___| |_\ \ / (_)_ __| |_ / ___| | ___ _ _ __| |
\ \ /\ / / _ | '_ \ \ / /| | '__| __| | | |/ _ \| | | |/ _` |
\ V V | __| |_) \ V / | | | | |_| |___| | (_) | |_| | (_| |
\_/\_/ \___|_.__/ \_/ |_|_| \__|\____|_|\___/ \__,_|\__,_|
EOF
# Start docker compose
function start_webvirtcloud() {
ININT_DB=false
# Check if custom.env exists
if [ ! -f custom.env ]; then
echo "File custom.env not found!"
echo -e "\nRun '$0 env' first\n"
exit 1
fi
# Check submodules
if [ -z "$(ls -A "webvirtbackend")" ]; then
init_submodules
fi
# Check if .mysql directory exists
if [ ! -d ".mysql" ]; then
ININT_DB=true
fi
echo "Building WebVirtCloud..."
docker compose build backend --no-cache
echo "Start WebVirtCloud..."
docker compose up -d
# Init database
if [ "$ININT_DB" = true ]; then
load_initial_data
fi
}
# Load initial data
function load_initial_data() {
echo "Loading initial data..."
docker compose exec backend python manage.py loaddata initial_data
}
# Init and update submodules
function init_submodules() {
echo "Init submodules..."
git submodule update --init --recursive
}
# Restart docker compose
function restart_webvirtcloud() {
echo "Restarting WebVirtCloud..."
docker compose restart
}
# Stop docker compose
function stop_webvirtcloud() {
echo "Stop WebVirtCloud..."
docker compose down
}
# Pull latest changes
function git_pull() {
echo "Pulling latest changes..."
git pull
git submodule update
}
# Add base domain to custom.env
function add_to_custom_env() {
echo -e "Enter your wildcard domain. Example: webvirt.local"
read -p "Enter: " domain_name
echo "BASE_DOMAIN=${domain_name}" > custom.env
echo "API_DOMAIN=api.${domain_name}" >> custom.env
echo "ASSETS_DOMAIN=assets.${domain_name}" >> custom.env
echo "CLIENT_DOMAIN=client.${domain_name}" >> custom.env
echo "MANAGE_DOMAIN=manage.${domain_name}" >> custom.env
echo "CONSOLE_DOMAIN=console.${domain_name}" >> custom.env
echo -e "\nWildcard domain: "${domain_name}" added to custom.env\n"
}
# Show help function
function show_help() {
cat << "EOF"
Available commands:
env Configure custom.env
start Start WebVirtCloud
restart Restart WebVirtCloud
stop Stop WebVirtCloud
update Update WebVirtCloud
help Show this message
EOF
}
# Check if docker installed
if ! command -v docker &> /dev/null; then
echo -e "\nDocker not found! Please install docker first\n"
exit 1
fi
# Run functions
case "$1" in
"help")
show_help
;;
"env")
add_to_custom_env
;;
"start")
start_webvirtcloud
;;
"stop")
stop_webvirtcloud
;;
"update")
stop_webvirtcloud
git_pull
start_webvirtcloud
;;
"restart")
restart_webvirtcloud
;;
*)
echo "No command found."
echo
show_help
;;
esac