@@ -6,9 +6,6 @@ trap 'echo -e "\n❌ An error occurred. Aborting."; exit 1' ERR
66# ========== Variables ==========
77HYSTERIA_INSTALL_DIR=" /etc/hysteria"
88HYSTERIA_VENV_DIR=" $HYSTERIA_INSTALL_DIR /hysteria2_venv"
9- AUTH_BINARY_DIR=" $HYSTERIA_INSTALL_DIR /core/scripts/auth"
10- REPO_URL=" https://github.com/ReturnFI/Blitz"
11- REPO_BRANCH=" main"
129GEOSITE_URL=" https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat"
1310GEOIP_URL=" https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat"
1411MIGRATE_SCRIPT_PATH=" $HYSTERIA_INSTALL_DIR /core/scripts/db/migrate_users.py"
@@ -81,6 +78,44 @@ migrate_json_to_mongo() {
8178 fi
8279}
8380
81+ download_and_extract_latest_release () {
82+ local arch
83+ case $( uname -m) in
84+ x86_64) arch=" amd64" ;;
85+ aarch64) arch=" arm64" ;;
86+ * )
87+ error " Unsupported architecture: $( uname -m) "
88+ exit 1
89+ ;;
90+ esac
91+ info " Detected architecture: $arch "
92+
93+ local zip_name=" Blitz-${arch} .zip"
94+ local download_url=" https://github.com/ReturnFI/Blitz/releases/latest/download/${zip_name} "
95+ local temp_zip=" /tmp/${zip_name} "
96+
97+ info " Downloading latest release from ${download_url} ..."
98+ if ! curl -sL -o " $temp_zip " " $download_url " ; then
99+ error " Failed to download the release asset. Please check the URL and your connection."
100+ exit 1
101+ fi
102+ success " Download complete."
103+
104+ info " Removing old installation directory..."
105+ rm -rf " $HYSTERIA_INSTALL_DIR "
106+ mkdir -p " $HYSTERIA_INSTALL_DIR "
107+
108+ info " Extracting to ${HYSTERIA_INSTALL_DIR} ..."
109+ if ! unzip -q " $temp_zip " -d " $HYSTERIA_INSTALL_DIR " ; then
110+ error " Failed to extract the archive."
111+ exit 1
112+ fi
113+ success " Extracted successfully."
114+
115+ rm " $temp_zip "
116+ info " Cleaned up temporary file."
117+ }
118+
84119# ========== Capture Active Services ==========
85120declare -a ACTIVE_SERVICES_BEFORE_UPGRADE=()
86121ALL_SERVICES=(
@@ -106,36 +141,6 @@ done
106141# ========== Install MongoDB Prerequisite ==========
107142install_mongodb
108143
109- # ========== Install Go and Compile Auth Binary ==========
110- install_go_and_compile_auth () {
111- info " Checking for Go and compiling authentication binary..."
112- if ! command -v go & > /dev/null; then
113- warn " Go is not installed. Attempting to install..."
114- apt-get install -y golang-go
115- success " Go installed successfully."
116- else
117- success " Go is already installed."
118- fi
119-
120- if [[ -f " $AUTH_BINARY_DIR /user_auth.go" ]]; then
121- info " Found auth binary source. Compiling..."
122- (
123- cd " $AUTH_BINARY_DIR "
124- go mod init hysteria_auth > /dev/null 2>&1
125- go mod tidy > /dev/null 2>&1
126- if go build -o user_auth . ; then
127- chmod +x user_auth
128- success " Authentication binary compiled successfully."
129- else
130- error " Failed to compile the authentication binary."
131- exit 1
132- fi
133- )
134- else
135- warn " Authentication binary source not found. Skipping compilation."
136- fi
137- }
138-
139144# ========== Backup Files ==========
140145cd /root
141146TEMP_DIR=$( mktemp -d)
@@ -165,12 +170,8 @@ for FILE in "${FILES[@]}"; do
165170 fi
166171done
167172
168- # ========== Replace Installation ==========
169- info " Removing old hysteria directory..."
170- rm -rf " $HYSTERIA_INSTALL_DIR "
171-
172- info " Cloning Blitz repository (branch: $REPO_BRANCH )..."
173- git clone -q -b " $REPO_BRANCH " " $REPO_URL " " $HYSTERIA_INSTALL_DIR "
173+ # ========== Download and Replace Installation ==========
174+ download_and_extract_latest_release
174175
175176# ========== Download Geo Data ==========
176177info " Downloading geosite.dat and geoip.dat..."
202203
203204# ========== Permissions ==========
204205info " Setting ownership and permissions..."
205- chown hysteria:hysteria " $HYSTERIA_INSTALL_DIR /ca.key" " $HYSTERIA_INSTALL_DIR /ca.crt"
206- chmod 640 " $HYSTERIA_INSTALL_DIR /ca.key" " $HYSTERIA_INSTALL_DIR /ca.crt"
207- chown -R hysteria:hysteria " $HYSTERIA_INSTALL_DIR /core/scripts/telegrambot"
206+ if id -u hysteria > /dev/null 2>&1 ; then
207+ chown hysteria:hysteria " $HYSTERIA_INSTALL_DIR /ca.key" " $HYSTERIA_INSTALL_DIR /ca.crt" 2> /dev/null || true
208+ chmod 640 " $HYSTERIA_INSTALL_DIR /ca.key" " $HYSTERIA_INSTALL_DIR /ca.crt" 2> /dev/null || true
209+ chown -R hysteria:hysteria " $HYSTERIA_INSTALL_DIR /core/scripts/telegrambot" 2> /dev/null || true
210+ fi
208211chmod +x " $HYSTERIA_INSTALL_DIR /core/scripts/hysteria2/kick.py"
212+ chmod +x " $HYSTERIA_INSTALL_DIR /core/scripts/auth/user_auth"
213+ success " Permissions updated."
209214
210215# ========== Virtual Environment ==========
211216info " Setting up virtual environment and installing dependencies..."
@@ -219,9 +224,6 @@ success "Python environment ready."
219224# ========== Data Migration ==========
220225migrate_json_to_mongo
221226
222- # ========== Compile Go Binary ==========
223- install_go_and_compile_auth
224-
225227# ========== Systemd Services ==========
226228info " Ensuring systemd services are configured..."
227229if source " $HYSTERIA_INSTALL_DIR /core/scripts/scheduler.sh" ; then
261263fi
262264
263265# ========== Launch Menu ==========
264- # sleep 10
266+ info " Upgrade process finished. Launching menu..."
267+ cd " $HYSTERIA_INSTALL_DIR "
265268chmod +x menu.sh
266- ./menu.sh
269+ ./menu.sh
0 commit comments