-
Notifications
You must be signed in to change notification settings - Fork 16
/
upgrade.sh
88 lines (70 loc) · 2.65 KB
/
upgrade.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
#!/bin/bash
cd /root/
if ! command -v zip &> /dev/null; then
apt install -y zip
fi
TEMP_DIR=$(mktemp -d)
FILES=(
"/etc/hysteria/ca.key"
"/etc/hysteria/ca.crt"
"/etc/hysteria/users.json"
"/etc/hysteria/traffic_data.json"
"/etc/hysteria/config.json"
"/etc/hysteria/core/scripts/telegrambot/.env"
"/etc/hysteria/core/scripts/singbox/.env"
"/etc/hysteria/core/scripts/normalsub/.env"
)
echo "Backing up files to $TEMP_DIR"
for FILE in "${FILES[@]}"; do
mkdir -p "$TEMP_DIR/$(dirname "$FILE")"
cp "$FILE" "$TEMP_DIR/$FILE"
done
echo "Removing /etc/hysteria directory"
rm -rf /etc/hysteria/
echo "Cloning Hysteria2 repository"
git clone https://github.com/ReturnFI/Hysteria2 /etc/hysteria
echo "Downloading geosite.dat and geoip.dat"
wget -O /etc/hysteria/geosite.dat https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat >/dev/null 2>&1
wget -O /etc/hysteria/geoip.dat https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat >/dev/null 2>&1
echo "Restoring backup files"
for FILE in "${FILES[@]}"; do
cp "$TEMP_DIR/$FILE" "$FILE"
done
echo "Merging traffic data into users.json"
if [ -f /etc/hysteria/traffic_data.json ]; then
jq -s '.[0] * .[1]' /etc/hysteria/users.json /etc/hysteria/traffic_data.json > /etc/hysteria/users_temp.json
mv /etc/hysteria/users_temp.json /etc/hysteria/users.json
# rm /etc/hysteria/traffic_data.json
else
echo "No traffic_data.json found to merge."
fi
if [ ! -f /etc/hysteria/.configs.env ]; then
echo ".configs.env not found, creating it with default SNI=bts.com"
echo "SNI=bts.com" > /etc/hysteria/.configs.env
else
echo ".configs.env already exists."
fi
echo "Setting ownership and permissions"
chown hysteria:hysteria /etc/hysteria/ca.key /etc/hysteria/ca.crt
chmod 640 /etc/hysteria/ca.key /etc/hysteria/ca.crt
chown -R hysteria:hysteria /etc/hysteria/core/scripts/singbox
chown -R hysteria:hysteria /etc/hysteria/core/scripts/telegrambot
echo "Setting execute permissions for user.sh and kick.sh"
chmod +x /etc/hysteria/core/scripts/hysteria2/user.sh
chmod +x /etc/hysteria/core/scripts/hysteria2/kick.sh
cd /etc/hysteria
python3 -m venv hysteria2_venv
source /etc/hysteria/hysteria2_venv/bin/activate
pip install -r requirements.txt
echo "Restarting hysteria services"
systemctl restart hysteria-server.service
systemctl restart hysteria-bot.service
systemctl restart singbox.service
echo "Checking hysteria-server.service status"
if systemctl is-active --quiet hysteria-server.service; then
echo "Upgrade completed successfully"
else
echo "Upgrade failed: hysteria-server.service is not active"
fi
chmod +x menu.sh
./menu.sh