-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupgrade_en.sh
More file actions
171 lines (169 loc) · 6.27 KB
/
Copy pathupgrade_en.sh
File metadata and controls
171 lines (169 loc) · 6.27 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
#!/bin/sh
# AppleAutoPro-Personal Upgrade Script
IFS=$'\n\t'
if [ -t 0 ]; then stty erase ^H; fi
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
repo="SideCloudGroup/AppleAutoPro-Personal"
filename="AppleAutoPro-Personal"
check_docker_permission() {
current_user=$(whoami)
if [ "$current_user" != "root" ]; then
if [ "$(uname)" = "Darwin" ]; then
echo -e "${BLUE}Detected system: ${YELLOW}macOS${NC}"
if ! docker info &>/dev/null; then
echo -e "${RED}Unable to connect to Docker daemon${NC}"
echo -e "${YELLOW}Please check if Docker Desktop is installed and if Docker Desktop service is running!${NC}"
echo -e "${RED}If you are sure Docker Desktop is running, please try running this script with root(sudo)!${NC}"
exit 1
fi
else
echo -e "${BLUE}Detected system: ${YELLOW}Linux${NC}"
if ! id -nG "$current_user" | grep -qw docker; then
echo -e "${RED}Current user is not root and not in docker group, no permission to use docker${NC}"
echo -e "${YELLOW}Solutions:${NC}"
echo -e "1.${BLUE}Add current user to docker group and re-enter terminal${YELLOW}(sudo gpasswd -a username docker)${NC}"
echo -e "2.${BLUE}Run this script directly with root(sudo)!${NC}"
exit 1
fi
fi
else
echo -e "${BLUE}Detected current user: ${YELLOW}root${NC}"
fi
}
check_docker_permission
check_docker_compose() {
if [ ! -f "docker-compose.yml" ]; then
echo -e "${RED}docker-compose.yml file not found${NC}"
echo -e "${YELLOW}Please run this script from the program root directory!${NC}"
exit 1
fi
}
check_docker_compose
if ! command -v unzip &> /dev/null || ! command -v curl &> /dev/null || ! command -v wget &> /dev/null || ! command -v rsync &> /dev/null; then
echo -e "${YELLOW}Missing necessary tools, installing...${NC}"
if [ -f /etc/debian_version ]; then
apt update
apt -y install unzip curl wget jq rsync
elif [ -f /etc/redhat-release ]; then
yum -y install unzip curl wget jq rsync
else
echo -e "${RED}Unable to detect current system, exiting${NC}"
exit;
fi
fi
geo_check() {
api_list=(
"https://cloudflare.com/cdn-cgi/trace"
"https://blog.cloudflare.com/cdn-cgi/trace"
"https://dash.cloudflare.com/cdn-cgi/trace"
"https://developers.cloudflare.com/cdn-cgi/trace"
)
ua="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"
isCN="false"
for url in "${api_list[@]}"; do
text="$(curl -A "$ua" -m 10 -sSL "$url" 2>/dev/null)" || continue
[ -z "$text" ] && continue
location="$(echo "$text" | grep '^loc=' | cut -d'=' -f2)"
if [ -n "$location" ]; then
if [ "$location" = "CN" ]; then
isCN="true"
else
isCN="false"
fi
break
else
if echo "$text" | grep -q 'loc=CN'; then
isCN="true"
break
fi
fi
done
}
self_update_script() {
script_name=$(basename "$0")
tmp=$(mktemp) || return 0
if [ "$isCN" = "true" ]; then
url="https://ghfast.top/https://raw.githubusercontent.com/$repo/v4/$script_name"
else
url="https://raw.githubusercontent.com/$repo/v4/$script_name"
fi
if ! curl -m 10 -sSL "$url" -o "$tmp" || [ ! -s "$tmp" ]; then
rm -f "$tmp"
return 0
fi
if command -v sha256sum >/dev/null 2>&1; then
remote_hash=$(sha256sum "$tmp" | awk '{print $1}')
local_hash=$(sha256sum "$0" | awk '{print $1}')
else
remote_hash=$(shasum -a 256 "$tmp" | awk '{print $1}')
local_hash=$(shasum -a 256 "$0" | awk '{print $1}')
fi
if [ "$remote_hash" != "$local_hash" ]; then
cp "$tmp" "$0" && chmod +x "$0"
rm -f "$tmp"
echo -e "${YELLOW}Upgrade script has been updated, please re-run: ./$script_name${NC}"
exit 0
fi
rm -f "$tmp"
}
geo_check
self_update_script
LATEST_TAG=$(curl -m 10 -s "https://api.github.com/repos/$repo/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_TAG" ]; then
echo -e "${RED}Failed to get version number or timeout, please manually enter version number (e.g.: 4.0.0):${NC}"
read manual_tag
if [[ "$manual_tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
LATEST_TAG="$manual_tag"
else
echo -e "${RED}Version number format is incorrect, exiting script${NC}"
exit 1
fi
fi
echo -e "${BLUE}If there are changes in the file, it will be replaced with the latest version after one-click update, and the changes will disappear. Please backup.${NC}"
echo -e "${GREEN}Current latest version: $LATEST_TAG${NC}"
echo -e "${YELLOW}Press enter to continue...${NC}"
read
echo -e "${GREEN}Upgrading to latest version: $LATEST_TAG${NC}"
if [ "$isCN" = "true" ]; then
wget -T 20 -q "https://ghfast.top/github.com/$repo/archive/refs/heads/v4.zip" -O "v4.zip"
wget -T 20 -q "https://ghfast.top/github.com/$repo/releases/download/$LATEST_TAG/$filename.zip" -O "$filename.zip"
else
wget -T 20 -q "https://github.com/$repo/archive/refs/heads/v4.zip" -O "v4.zip"
wget -T 20 -q "https://github.com/$repo/releases/download/$LATEST_TAG/$filename.zip" -O "$filename.zip"
fi
if [ $? -ne 0 ]; then
echo -e "${RED}wget failed or timeout, exiting program${NC}"
exit 1
fi
unzip -q -o "v4.zip"
rsync -av --remove-source-files --exclude 'docker-compose.yml' --exclude 'Caddyfile' "$filename-4"/ ./
rm -rf "$filename-4"
rm -rf "v4.zip"
unzip -q -o "$filename.zip"
if [ ! -d "$filename" ]; then
echo -e "${RED}$filename directory does not exist, exiting update...${NC}"
exit 1
fi
rm -rf ./web/app
rsync -aq --remove-source-files "$filename/" ./web/
rm -rf "$filename"
rm -rf "$filename.zip"
docker compose pull
chmod +x ./data/entrypoint.sh
echo -e "${GREEN}Update completed, please check the update log, check if frontend configuration file needs changes.${NC}"
docker compose down
docker compose up -d
echo -e "${YELLOW}Do you want to clean old images? (y/n)${NC}"
read prune_choice
if [ "$prune_choice" = "y" ]; then
docker image prune -f
echo -e "${GREEN}Old images cleaned${NC}"
else
echo -e "${YELLOW}Skipping old image cleanup${NC}"
fi
echo -e "${GREEN}Upgrade completed!${NC}"
exit 0