Merge pull request #269 from ReturnFI/beta

Streamlined Installation & CI Improvements
This commit is contained in:
Whispering Wind
2025-09-11 23:32:30 +03:30
committed by GitHub
5 changed files with 165 additions and 98 deletions

View File

@ -6,33 +6,84 @@ on:
- 'VERSION' - 'VERSION'
jobs: jobs:
create-release: build-and-release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.x'
cache-dependency-path: core/scripts/auth/go.sum
- name: Read version from VERSION file - name: Read version from VERSION file
run: |
version=$(cat VERSION)
echo "version=${version}" >> $GITHUB_OUTPUT
id: get_version id: get_version
run: echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT
- name: Initialize Go module
working-directory: ./core/scripts/auth
run: |
go mod init hysteria_auth
go mod tidy
- name: Build and Package for linux-amd64
id: package_amd64
run: |
(cd core/scripts/auth && GOOS=linux GOARCH=amd64 go build -o user_auth .)
zip_name="Blitz-amd64.zip"
zip -r "$zip_name" . \
-x ".git/*" \
".github/*" \
".gitignore" \
"CONTRIBUTING.md" \
"LICENSE" \
"README*.md" \
"SECURITY.md" \
"changelog" \
"core/scripts/auth/go.*" \
"core/scripts/auth/user_auth.go"
rm core/scripts/auth/user_auth
echo "zip_name=$zip_name" >> $GITHUB_OUTPUT
- name: Build and Package for linux-arm64
id: package_arm64
run: |
(cd core/scripts/auth && GOOS=linux GOARCH=arm64 go build -o user_auth .)
zip_name="Blitz-arm64.zip"
zip -r "$zip_name" . \
-x ".git/*" \
".github/*" \
".gitignore" \
"CONTRIBUTING.md" \
"LICENSE" \
"README*.md" \
"SECURITY.md" \
"changelog" \
"core/scripts/auth/go.*" \
"core/scripts/auth/user_auth.go"
rm core/scripts/auth/user_auth
echo "zip_name=$zip_name" >> $GITHUB_OUTPUT
- name: Read changelog for release description - name: Read changelog for release description
id: get_changelog
run: | run: |
changelog=$(cat changelog) changelog=$(cat changelog)
echo "changelog<<EOF" >> $GITHUB_OUTPUT echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$changelog" >> $GITHUB_OUTPUT echo "$changelog" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT
id: get_changelog
- name: Create GitHub Release - name: Create GitHub Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag_name: ${{ steps.get_version.outputs.version }} tag_name: ${{ steps.get_version.outputs.version }}
name: "${{ steps.get_version.outputs.version }}" name: "${{ steps.get_version.outputs.version }}"
body: ${{ steps.get_changelog.outputs.changelog }} body: ${{ steps.get_changelog.outputs.changelog }}
files: |
${{ steps.package_amd64.outputs.zip_name }}
${{ steps.package_arm64.outputs.zip_name }}
draft: false draft: false
prerelease: false prerelease: false

View File

@ -1,12 +1,13 @@
### 🚀 **\[2.0.0] Major Release: MongoDB Migration** ### 🚀 **\[2.1.0] Streamlined Installation & CI Improvements**
*Released: 2025-09-10* *Released: 2025-09-11*
#### 💾 Core Update #### ⚙️ CI/CD
* 📦 **User management migrated from `users.json` → MongoDB** * 🛠️ Added **build step** to release workflow
* ⚡ Improved **scalability, performance, and reliability** for large deployments * 🧹 Removed unnecessary **auth binary compilation** from core install script
#### ⚠️ Breaking Change #### 📦 Installation & Upgrade
* Previous JSON-based `users.json` file is no longer used * 🔄 **Refactored install script** to use release artifacts instead of `git clone`
* ⬆️ **Refactored upgrade script** to pull release artifacts for faster, more reliable updates

View File

@ -5,28 +5,6 @@ source /etc/hysteria/core/scripts/utils.sh
source /etc/hysteria/core/scripts/scheduler.sh source /etc/hysteria/core/scripts/scheduler.sh
define_colors define_colors
compile_auth_binary() {
echo "Compiling authentication binary..."
local auth_dir="/etc/hysteria/core/scripts/auth"
if [ -f "$auth_dir/user_auth.go" ]; then
(
cd "$auth_dir" || exit 1
go mod init hysteria-auth >/dev/null 2>&1
go mod tidy >/dev/null 2>&1
if go build -o user_auth .; then
chmod +x user_auth
echo "Authentication binary compiled successfully."
else
echo -e "${red}Error:${NC} Failed to compile the authentication binary."
exit 1
fi
)
else
echo -e "${red}Error:${NC} Go source file not found at $auth_dir/user_auth.go"
exit 1
fi
}
install_hysteria() { install_hysteria() {
local port=$1 local port=$1
@ -36,8 +14,6 @@ install_hysteria() {
mkdir -p /etc/hysteria && cd /etc/hysteria/ mkdir -p /etc/hysteria && cd /etc/hysteria/
compile_auth_binary
echo "Generating CA key and certificate..." echo "Generating CA key and certificate..."
openssl ecparam -genkey -name prime256v1 -out ca.key >/dev/null 2>&1 openssl ecparam -genkey -name prime256v1 -out ca.key >/dev/null 2>&1
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/CN=$sni" >/dev/null 2>&1 openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/CN=$sni" >/dev/null 2>&1

View File

@ -119,7 +119,7 @@ install_mongodb() {
} }
install_packages() { install_packages() {
local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "git" "bc" "zip" "cron" "lsof" "golang-go" "gnupg" "lsb-release") local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "bc" "zip" "lsof" "gnupg" "lsb-release")
local MISSING_PACKAGES=() local MISSING_PACKAGES=()
log_info "Checking required packages..." log_info "Checking required packages..."
@ -153,27 +153,63 @@ install_packages() {
install_mongodb install_mongodb
} }
clone_repository() { download_and_extract_release() {
log_info "Cloning Blitz repository..." log_info "Downloading and extracting Blitz panel..."
if [ -d "/etc/hysteria" ]; then if [ -d "/etc/hysteria" ]; then
log_warning "Directory /etc/hysteria already exists." log_warning "Directory /etc/hysteria already exists."
read -p "Do you want to remove it and clone again? (y/n): " -n 1 -r read -p "Do you want to remove it and install again? (y/n): " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf /etc/hysteria rm -rf /etc/hysteria
else else
log_info "Using existing directory." log_info "Skipping download. Using existing directory."
return 0 return 0
fi fi
fi fi
if git clone https://github.com/ReturnFI/Blitz /etc/hysteria &> /dev/null; then local arch
log_success "Repository cloned successfully" case $(uname -m) in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
*)
log_error "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
log_info "Detected architecture: $arch"
local zip_name="Blitz-${arch}.zip"
local download_url="https://github.com/ReturnFI/Blitz/releases/latest/download/${zip_name}"
local temp_zip="/tmp/${zip_name}"
log_info "Downloading from ${download_url}..."
if curl -sL -o "$temp_zip" "$download_url"; then
log_success "Download complete."
else else
log_error "Failed to clone repository" log_error "Failed to download the release asset. Please check the URL and your connection."
exit 1 exit 1
fi fi
log_info "Extracting to /etc/hysteria..."
mkdir -p /etc/hysteria
if unzip -q "$temp_zip" -d /etc/hysteria; then
log_success "Extracted successfully."
else
log_error "Failed to extract the archive."
exit 1
fi
rm "$temp_zip"
log_info "Cleaned up temporary file."
local auth_binary="/etc/hysteria/core/scripts/auth/user_auth"
if [ -f "$auth_binary" ]; then
chmod +x "$auth_binary"
log_success "Set execute permission for auth binary."
else
log_warning "Auth binary not found at $auth_binary. The installation might be incomplete."
fi
} }
setup_python_env() { setup_python_env() {
@ -227,7 +263,7 @@ main() {
check_root check_root
check_os_version check_os_version
install_packages install_packages
clone_repository download_and_extract_release
setup_python_env setup_python_env
add_alias add_alias
@ -239,4 +275,4 @@ main() {
run_menu run_menu
} }
main main

View File

@ -6,9 +6,6 @@ trap 'echo -e "\n❌ An error occurred. Aborting."; exit 1' ERR
# ========== Variables ========== # ========== Variables ==========
HYSTERIA_INSTALL_DIR="/etc/hysteria" HYSTERIA_INSTALL_DIR="/etc/hysteria"
HYSTERIA_VENV_DIR="$HYSTERIA_INSTALL_DIR/hysteria2_venv" HYSTERIA_VENV_DIR="$HYSTERIA_INSTALL_DIR/hysteria2_venv"
AUTH_BINARY_DIR="$HYSTERIA_INSTALL_DIR/core/scripts/auth"
REPO_URL="https://github.com/ReturnFI/Blitz"
REPO_BRANCH="main"
GEOSITE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat" GEOSITE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat"
GEOIP_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat" GEOIP_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat"
MIGRATE_SCRIPT_PATH="$HYSTERIA_INSTALL_DIR/core/scripts/db/migrate_users.py" MIGRATE_SCRIPT_PATH="$HYSTERIA_INSTALL_DIR/core/scripts/db/migrate_users.py"
@ -81,6 +78,44 @@ migrate_json_to_mongo() {
fi fi
} }
download_and_extract_latest_release() {
local arch
case $(uname -m) in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
*)
error "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
info "Detected architecture: $arch"
local zip_name="Blitz-${arch}.zip"
local download_url="https://github.com/ReturnFI/Blitz/releases/latest/download/${zip_name}"
local temp_zip="/tmp/${zip_name}"
info "Downloading latest release from ${download_url}..."
if ! curl -sL -o "$temp_zip" "$download_url"; then
error "Failed to download the release asset. Please check the URL and your connection."
exit 1
fi
success "Download complete."
info "Removing old installation directory..."
rm -rf "$HYSTERIA_INSTALL_DIR"
mkdir -p "$HYSTERIA_INSTALL_DIR"
info "Extracting to ${HYSTERIA_INSTALL_DIR}..."
if ! unzip -q "$temp_zip" -d "$HYSTERIA_INSTALL_DIR"; then
error "Failed to extract the archive."
exit 1
fi
success "Extracted successfully."
rm "$temp_zip"
info "Cleaned up temporary file."
}
# ========== Capture Active Services ========== # ========== Capture Active Services ==========
declare -a ACTIVE_SERVICES_BEFORE_UPGRADE=() declare -a ACTIVE_SERVICES_BEFORE_UPGRADE=()
ALL_SERVICES=( ALL_SERVICES=(
@ -106,36 +141,6 @@ done
# ========== Install MongoDB Prerequisite ========== # ========== Install MongoDB Prerequisite ==========
install_mongodb install_mongodb
# ========== Install Go and Compile Auth Binary ==========
install_go_and_compile_auth() {
info "Checking for Go and compiling authentication binary..."
if ! command -v go &>/dev/null; then
warn "Go is not installed. Attempting to install..."
apt-get install -y golang-go
success "Go installed successfully."
else
success "Go is already installed."
fi
if [[ -f "$AUTH_BINARY_DIR/user_auth.go" ]]; then
info "Found auth binary source. Compiling..."
(
cd "$AUTH_BINARY_DIR"
go mod init hysteria_auth >/dev/null 2>&1
go mod tidy >/dev/null 2>&1
if go build -o user_auth .; then
chmod +x user_auth
success "Authentication binary compiled successfully."
else
error "Failed to compile the authentication binary."
exit 1
fi
)
else
warn "Authentication binary source not found. Skipping compilation."
fi
}
# ========== Backup Files ========== # ========== Backup Files ==========
cd /root cd /root
TEMP_DIR=$(mktemp -d) TEMP_DIR=$(mktemp -d)
@ -165,12 +170,8 @@ for FILE in "${FILES[@]}"; do
fi fi
done done
# ========== Replace Installation ========== # ========== Download and Replace Installation ==========
info "Removing old hysteria directory..." download_and_extract_latest_release
rm -rf "$HYSTERIA_INSTALL_DIR"
info "Cloning Blitz repository (branch: $REPO_BRANCH)..."
git clone -q -b "$REPO_BRANCH" "$REPO_URL" "$HYSTERIA_INSTALL_DIR"
# ========== Download Geo Data ========== # ========== Download Geo Data ==========
info "Downloading geosite.dat and geoip.dat..." info "Downloading geosite.dat and geoip.dat..."
@ -202,10 +203,14 @@ fi
# ========== Permissions ========== # ========== Permissions ==========
info "Setting ownership and permissions..." info "Setting ownership and permissions..."
chown hysteria:hysteria "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" if id -u hysteria >/dev/null 2>&1; then
chmod 640 "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" chown hysteria:hysteria "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" 2>/dev/null || true
chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot" chmod 640 "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" 2>/dev/null || true
chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot" 2>/dev/null || true
fi
chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/kick.py" chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/kick.py"
chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/auth/user_auth"
success "Permissions updated."
# ========== Virtual Environment ========== # ========== Virtual Environment ==========
info "Setting up virtual environment and installing dependencies..." info "Setting up virtual environment and installing dependencies..."
@ -219,9 +224,6 @@ success "Python environment ready."
# ========== Data Migration ========== # ========== Data Migration ==========
migrate_json_to_mongo migrate_json_to_mongo
# ========== Compile Go Binary ==========
install_go_and_compile_auth
# ========== Systemd Services ========== # ========== Systemd Services ==========
info "Ensuring systemd services are configured..." info "Ensuring systemd services are configured..."
if source "$HYSTERIA_INSTALL_DIR/core/scripts/scheduler.sh"; then if source "$HYSTERIA_INSTALL_DIR/core/scripts/scheduler.sh"; then
@ -261,6 +263,7 @@ else
fi fi
# ========== Launch Menu ========== # ========== Launch Menu ==========
# sleep 10 info "Upgrade process finished. Launching menu..."
cd "$HYSTERIA_INSTALL_DIR"
chmod +x menu.sh chmod +x menu.sh
./menu.sh ./menu.sh