Skip to content

Commit 82c50ca

Browse files
authored
Merge pull request #269 from ReturnFI/beta
Streamlined Installation & CI Improvements
2 parents d137c99 + afa89a0 commit 82c50ca

File tree

5 files changed

+165
-98
lines changed

5 files changed

+165
-98
lines changed

.github/workflows/release.yml

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,84 @@ on:
66
- 'VERSION'
77

88
jobs:
9-
create-release:
9+
build-and-release:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout repository
1313
uses: actions/checkout@v4
1414

15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: '1.22.x'
19+
cache-dependency-path: core/scripts/auth/go.sum
20+
1521
- name: Read version from VERSION file
16-
run: |
17-
version=$(cat VERSION)
18-
echo "version=${version}" >> $GITHUB_OUTPUT
1922
id: get_version
23+
run: echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT
24+
25+
- name: Initialize Go module
26+
working-directory: ./core/scripts/auth
27+
run: |
28+
go mod init hysteria_auth
29+
go mod tidy
30+
31+
- name: Build and Package for linux-amd64
32+
id: package_amd64
33+
run: |
34+
(cd core/scripts/auth && GOOS=linux GOARCH=amd64 go build -o user_auth .)
35+
zip_name="Blitz-amd64.zip"
36+
zip -r "$zip_name" . \
37+
-x ".git/*" \
38+
".github/*" \
39+
".gitignore" \
40+
"CONTRIBUTING.md" \
41+
"LICENSE" \
42+
"README*.md" \
43+
"SECURITY.md" \
44+
"changelog" \
45+
"core/scripts/auth/go.*" \
46+
"core/scripts/auth/user_auth.go"
47+
rm core/scripts/auth/user_auth
48+
echo "zip_name=$zip_name" >> $GITHUB_OUTPUT
49+
50+
51+
- name: Build and Package for linux-arm64
52+
id: package_arm64
53+
run: |
54+
(cd core/scripts/auth && GOOS=linux GOARCH=arm64 go build -o user_auth .)
55+
zip_name="Blitz-arm64.zip"
56+
zip -r "$zip_name" . \
57+
-x ".git/*" \
58+
".github/*" \
59+
".gitignore" \
60+
"CONTRIBUTING.md" \
61+
"LICENSE" \
62+
"README*.md" \
63+
"SECURITY.md" \
64+
"changelog" \
65+
"core/scripts/auth/go.*" \
66+
"core/scripts/auth/user_auth.go"
67+
rm core/scripts/auth/user_auth
68+
echo "zip_name=$zip_name" >> $GITHUB_OUTPUT
69+
2070
2171
- name: Read changelog for release description
72+
id: get_changelog
2273
run: |
2374
changelog=$(cat changelog)
2475
echo "changelog<<EOF" >> $GITHUB_OUTPUT
2576
echo "$changelog" >> $GITHUB_OUTPUT
2677
echo "EOF" >> $GITHUB_OUTPUT
27-
id: get_changelog
2878
2979
- name: Create GitHub Release
30-
uses: softprops/action-gh-release@v1
31-
env:
32-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
uses: softprops/action-gh-release@v2
3381
with:
3482
tag_name: ${{ steps.get_version.outputs.version }}
3583
name: "${{ steps.get_version.outputs.version }}"
3684
body: ${{ steps.get_changelog.outputs.changelog }}
85+
files: |
86+
${{ steps.package_amd64.outputs.zip_name }}
87+
${{ steps.package_arm64.outputs.zip_name }}
3788
draft: false
3889
prerelease: false

changelog

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
### 🚀 **\[2.0.0] – Major Release: MongoDB Migration**
1+
### 🚀 **\[2.1.0] – Streamlined Installation & CI Improvements**
22

3-
*Released: 2025-09-10*
3+
*Released: 2025-09-11*
44

5-
#### 💾 Core Update
5+
#### ⚙️ CI/CD
66

7-
* 📦 **User management migrated from `users.json` → MongoDB**
8-
* ⚡ Improved **scalability, performance, and reliability** for large deployments
7+
* 🛠️ Added **build step** to release workflow
8+
* 🧹 Removed unnecessary **auth binary compilation** from core install script
99

10-
#### ⚠️ Breaking Change
10+
#### 📦 Installation & Upgrade
1111

12-
* Previous JSON-based `users.json` file is no longer used
12+
* 🔄 **Refactored install script** to use release artifacts instead of `git clone`
13+
* ⬆️ **Refactored upgrade script** to pull release artifacts for faster, more reliable updates

core/scripts/hysteria2/install.sh

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,6 @@ source /etc/hysteria/core/scripts/utils.sh
55
source /etc/hysteria/core/scripts/scheduler.sh
66
define_colors
77

8-
compile_auth_binary() {
9-
echo "Compiling authentication binary..."
10-
local auth_dir="/etc/hysteria/core/scripts/auth"
11-
12-
if [ -f "$auth_dir/user_auth.go" ]; then
13-
(
14-
cd "$auth_dir" || exit 1
15-
go mod init hysteria-auth >/dev/null 2>&1
16-
go mod tidy >/dev/null 2>&1
17-
if go build -o user_auth .; then
18-
chmod +x user_auth
19-
echo "Authentication binary compiled successfully."
20-
else
21-
echo -e "${red}Error:${NC} Failed to compile the authentication binary."
22-
exit 1
23-
fi
24-
)
25-
else
26-
echo -e "${red}Error:${NC} Go source file not found at $auth_dir/user_auth.go"
27-
exit 1
28-
fi
29-
}
308

319
install_hysteria() {
3210
local port=$1
@@ -36,8 +14,6 @@ install_hysteria() {
3614

3715
mkdir -p /etc/hysteria && cd /etc/hysteria/
3816

39-
compile_auth_binary
40-
4117
echo "Generating CA key and certificate..."
4218
openssl ecparam -genkey -name prime256v1 -out ca.key >/dev/null 2>&1
4319
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/CN=$sni" >/dev/null 2>&1

install.sh

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ install_mongodb() {
119119
}
120120

121121
install_packages() {
122-
local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "git" "bc" "zip" "cron" "lsof" "golang-go" "gnupg" "lsb-release")
122+
local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "bc" "zip" "lsof" "gnupg" "lsb-release")
123123
local MISSING_PACKAGES=()
124124

125125
log_info "Checking required packages..."
@@ -153,27 +153,63 @@ install_packages() {
153153
install_mongodb
154154
}
155155

156-
clone_repository() {
157-
log_info "Cloning Blitz repository..."
158-
156+
download_and_extract_release() {
157+
log_info "Downloading and extracting Blitz panel..."
158+
159159
if [ -d "/etc/hysteria" ]; then
160160
log_warning "Directory /etc/hysteria already exists."
161-
read -p "Do you want to remove it and clone again? (y/n): " -n 1 -r
161+
read -p "Do you want to remove it and install again? (y/n): " -n 1 -r
162162
echo
163163
if [[ $REPLY =~ ^[Yy]$ ]]; then
164164
rm -rf /etc/hysteria
165165
else
166-
log_info "Using existing directory."
166+
log_info "Skipping download. Using existing directory."
167167
return 0
168168
fi
169169
fi
170-
171-
if git clone https://github.com/ReturnFI/Blitz /etc/hysteria &> /dev/null; then
172-
log_success "Repository cloned successfully"
170+
171+
local arch
172+
case $(uname -m) in
173+
x86_64) arch="amd64" ;;
174+
aarch64) arch="arm64" ;;
175+
*)
176+
log_error "Unsupported architecture: $(uname -m)"
177+
exit 1
178+
;;
179+
esac
180+
log_info "Detected architecture: $arch"
181+
182+
local zip_name="Blitz-${arch}.zip"
183+
local download_url="https://github.com/ReturnFI/Blitz/releases/latest/download/${zip_name}"
184+
local temp_zip="/tmp/${zip_name}"
185+
186+
log_info "Downloading from ${download_url}..."
187+
if curl -sL -o "$temp_zip" "$download_url"; then
188+
log_success "Download complete."
173189
else
174-
log_error "Failed to clone repository"
190+
log_error "Failed to download the release asset. Please check the URL and your connection."
175191
exit 1
176192
fi
193+
194+
log_info "Extracting to /etc/hysteria..."
195+
mkdir -p /etc/hysteria
196+
if unzip -q "$temp_zip" -d /etc/hysteria; then
197+
log_success "Extracted successfully."
198+
else
199+
log_error "Failed to extract the archive."
200+
exit 1
201+
fi
202+
203+
rm "$temp_zip"
204+
log_info "Cleaned up temporary file."
205+
206+
local auth_binary="/etc/hysteria/core/scripts/auth/user_auth"
207+
if [ -f "$auth_binary" ]; then
208+
chmod +x "$auth_binary"
209+
log_success "Set execute permission for auth binary."
210+
else
211+
log_warning "Auth binary not found at $auth_binary. The installation might be incomplete."
212+
fi
177213
}
178214

179215
setup_python_env() {
@@ -227,7 +263,7 @@ main() {
227263
check_root
228264
check_os_version
229265
install_packages
230-
clone_repository
266+
download_and_extract_release
231267
setup_python_env
232268
add_alias
233269

@@ -239,4 +275,4 @@ main() {
239275
run_menu
240276
}
241277

242-
main
278+
main

upgrade.sh

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ trap 'echo -e "\n❌ An error occurred. Aborting."; exit 1' ERR
66
# ========== Variables ==========
77
HYSTERIA_INSTALL_DIR="/etc/hysteria"
88
HYSTERIA_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"
129
GEOSITE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat"
1310
GEOIP_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat"
1411
MIGRATE_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 ==========
85120
declare -a ACTIVE_SERVICES_BEFORE_UPGRADE=()
86121
ALL_SERVICES=(
@@ -106,36 +141,6 @@ done
106141
# ========== Install MongoDB Prerequisite ==========
107142
install_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 ==========
140145
cd /root
141146
TEMP_DIR=$(mktemp -d)
@@ -165,12 +170,8 @@ for FILE in "${FILES[@]}"; do
165170
fi
166171
done
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 ==========
176177
info "Downloading geosite.dat and geoip.dat..."
@@ -202,10 +203,14 @@ fi
202203

203204
# ========== Permissions ==========
204205
info "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
208211
chmod +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 ==========
211216
info "Setting up virtual environment and installing dependencies..."
@@ -219,9 +224,6 @@ success "Python environment ready."
219224
# ========== Data Migration ==========
220225
migrate_json_to_mongo
221226

222-
# ========== Compile Go Binary ==========
223-
install_go_and_compile_auth
224-
225227
# ========== Systemd Services ==========
226228
info "Ensuring systemd services are configured..."
227229
if source "$HYSTERIA_INSTALL_DIR/core/scripts/scheduler.sh"; then
@@ -261,6 +263,7 @@ else
261263
fi
262264

263265
# ========== Launch Menu ==========
264-
# sleep 10
266+
info "Upgrade process finished. Launching menu..."
267+
cd "$HYSTERIA_INSTALL_DIR"
265268
chmod +x menu.sh
266-
./menu.sh
269+
./menu.sh

0 commit comments

Comments
 (0)