-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·73 lines (61 loc) · 2.43 KB
/
update.sh
File metadata and controls
executable file
·73 lines (61 loc) · 2.43 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
#!/usr/bin/env bash
set -e
# Colors
BOLD='\033[1m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Move to repo root (directory of this script)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo -e "${CYAN}${BOLD}============================================${NC}"
echo -e "${CYAN}${BOLD} Edge Mining — Update${NC}"
echo -e "${CYAN}${BOLD}============================================${NC}"
echo ""
echo -e "Current branch: ${BOLD}$BRANCH${NC}"
echo ""
# Check if containers are running and stop them
echo -e "${YELLOW}>> Checking for running containers...${NC}"
RUNNING_CONTAINERS=$(docker compose ps --services --filter "status=running" 2>/dev/null || true)
if [ -n "$RUNNING_CONTAINERS" ]; then
echo -e "${YELLOW}${BOLD}⚠ Running containers detected:${NC}"
echo "$RUNNING_CONTAINERS"
echo ""
echo -e "${YELLOW}${BOLD}>> Stopping containers...${NC}"
docker compose down
echo -e "${GREEN}✓ Containers stopped successfully${NC}"
echo ""
fi
# Pull latest changes and update submodules (--init handles newly added submodules)
echo -e "${YELLOW}>> Pulling latest changes...${NC}"
git pull
echo -e "${YELLOW}>> Updating submodules...${NC}"
git submodule update --init --recursive
# Initialize user_data structure and default files
echo -e "${YELLOW}>> Initializing user data...${NC}"
./init_user_data.sh
echo ""
echo -e "${BOLD}Do you want to rebuild and restart the Docker application? (recommended)${NC}"
read -rp "Rebuild and restart? [Y/n] " CONFIRM
if [[ "$CONFIRM" =~ ^[Nn]$ ]]; then
echo ""
echo -e "${YELLOW}Note: the Docker image may have changed with this update.${NC}"
echo -e "${YELLOW}To rebuild and restart manually, run:${NC}"
echo ""
echo -e " ${BOLD}docker compose up -d --build${NC}"
echo ""
echo -e "${GREEN}${BOLD}============================================${NC}"
echo -e "${GREEN}${BOLD} Update completed (without rebuild).${NC}"
echo -e "${GREEN}${BOLD}============================================${NC}"
exit 0
fi
# Rebuild and restart the application stack
echo ""
echo -e "${YELLOW}>> Rebuilding and restarting the application...${NC}"
docker compose up -d --build
echo ""
echo -e "${GREEN}${BOLD}============================================${NC}"
echo -e "${GREEN}${BOLD} Update completed!${NC}"
echo -e "${GREEN}${BOLD}============================================${NC}"