Repository navigation
Expand file tree
/
Copy pathstart.local.sh
More file actions
219 lines (178 loc) Β· 5.74 KB
/
Copy pathstart.local.sh
File metadata and controls
219 lines (178 loc) Β· 5.74 KB
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
#!/bin/bash
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
COMPOSE_FILE="docker-compose.local.yml"
print_info() { echo -e "${BLUE}βΉ${NC} $1"; }
print_success() { echo -e "${GREEN}β${NC} $1"; }
print_warning() { echo -e "${YELLOW}β ${NC} $1"; }
print_error() { echo -e "${RED}β${NC} $1"; }
get_version_parts() {
local version="${1#v}"
IFS='.' read -r -a parts <<< "$version"
echo "${parts[0]} ${parts[1]} ${parts[2]}"
}
is_version_newer() {
local v1="${1#v}"
local v2="${2#v}"
IFS='.' read -r -a v1_parts <<< "$v1"
IFS='.' read -r -a v2_parts <<< "$v2"
for i in 0 1 2; do
local num1=${v1_parts[$i]:-0}
local num2=${v2_parts[$i]:-0}
[ "$num1" -lt "$num2" ] && return 0
[ "$num1" -gt "$num2" ] && return 1
done
return 1
}
prompt_yes_no() {
local prompt="$1"
while true; do
read -p "$prompt (yes/no): " response
case "$response" in
[Yy][Ee][Ss]|[Yy]) return 0 ;;
[Nn][Oo]|[Nn]) return 1 ;;
*) print_error "Please answer yes or no" ;;
esac
done
}
detect_docker_compose() {
if docker compose version &> /dev/null; then
echo "docker compose"
elif command -v docker-compose &> /dev/null && docker-compose version &> /dev/null; then
echo "docker-compose"
else
echo ""
fi
}
run_docker_compose() {
if [[ "$DOCKER_COMPOSE_CMD" == "docker compose" ]]; then
docker compose -f "$COMPOSE_FILE" "$@"
else
docker-compose -f "$COMPOSE_FILE" "$@"
fi
}
check_version() {
set +e
if ! command -v git &> /dev/null; then
set -e
return 0
fi
if [ ! -d ".git" ]; then
set -e
return 0
fi
print_info "Checking for updates..."
git fetch --tags --quiet 2>/dev/null
CURRENT_TAG=$(git describe --tags --exact-match HEAD 2>/dev/null || git describe --tags --abbrev=0 HEAD 2>/dev/null || echo "")
ALL_TAGS=($(git tag -l "v*" 2>/dev/null | sort -V 2>/dev/null || true))
if [ ${#ALL_TAGS[@]} -eq 0 ]; then
set -e
return 0
fi
LATEST_TAG="${ALL_TAGS[${#ALL_TAGS[@]}-1]}"
if [ -z "$CURRENT_TAG" ]; then
print_warning "New version available: (no version) -> ${LATEST_TAG#v}"
set -e
return 0
fi
if is_version_newer "$CURRENT_TAG" "$LATEST_TAG"; then
print_warning "New version available: ${CURRENT_TAG#v} -> ${LATEST_TAG#v}"
fi
set -e
}
MISSING_FILES=()
MISSING_TOOLS=()
print_info "Starting with local compose file: $COMPOSE_FILE"
echo ""
print_info "Checking for required files..."
if [ ! -f ".env" ]; then
MISSING_FILES+=(".env")
print_warning ".env file not found"
else
print_success ".env file exists"
fi
if [ ! -f "Sunrise.Config.Production.json" ]; then
MISSING_FILES+=("Sunrise.Config.Production.json")
print_warning "Sunrise.Config.Production.json file not found"
else
print_success "Sunrise.Config.Production.json file exists"
fi
if [ ! -f "$COMPOSE_FILE" ]; then
MISSING_FILES+=("$COMPOSE_FILE")
print_warning "$COMPOSE_FILE file not found"
else
print_success "$COMPOSE_FILE file exists"
fi
print_info "Checking for required tools..."
if ! command -v git &> /dev/null; then
MISSING_TOOLS+=("git")
print_error "Git is not installed"
print_info "Please install Git from: https://git-scm.com/"
else
print_success "Git is installed"
fi
if ! command -v docker &> /dev/null; then
MISSING_TOOLS+=("docker")
print_error "Docker is not installed"
print_info "Please install Docker from: https://www.docker.com/get-started/"
else
print_success "Docker is installed"
fi
DOCKER_COMPOSE_CMD=""
if command -v docker &> /dev/null; then
DOCKER_COMPOSE_CMD=$(detect_docker_compose)
if [ -z "$DOCKER_COMPOSE_CMD" ]; then
print_error "Docker Compose is not available"
print_info "Please install Docker Compose from: https://www.docker.com/get-started/"
MISSING_TOOLS+=("docker-compose")
else
print_success "Docker Compose is available ($DOCKER_COMPOSE_CMD)"
fi
fi
echo ""
if [ ${#MISSING_FILES[@]} -gt 0 ]; then
print_warning "Some required files are missing:"
for file in "${MISSING_FILES[@]}"; do
echo -e " ${YELLOW}- $file${NC}"
done
echo ""
if [[ " ${MISSING_FILES[@]} " =~ " .env " ]]; then
print_info "You can create .env by running: cp .env.example .env"
fi
if [[ " ${MISSING_FILES[@]} " =~ " Sunrise.Config.Production.json " ]]; then
print_info "You can create Sunrise.Config.Production.json by running: cp Sunrise.Config.Production.json.example Sunrise.Config.Production.json"
fi
echo ""
fi
if [ ${#MISSING_TOOLS[@]} -gt 0 ]; then
print_error "Some required tools are missing. Please install them before continuing."
exit 1
fi
if [ ${#MISSING_FILES[@]} -gt 0 ]; then
print_error "Please create the missing files before starting the setup."
exit 1
fi
check_version
echo ""
print_info "Do you want to build the setup?"
print_info "Note: You should run this if you updated .env, config, or any other configuration files."
echo ""
if prompt_yes_no "Do you want to build and start the Docker containers?"; then
print_info "Building and starting Docker containers..."
run_docker_compose up -d --build || {
print_error "Failed to build and start Docker containers"
exit 1
}
print_success "Docker containers built and started successfully!"
else
print_info "Starting Docker containers without rebuild..."
run_docker_compose up -d || {
print_error "Failed to start Docker containers"
exit 1
}
print_success "Docker containers started successfully!"
fi