|
| 1 | +#!/bin/bash |
| 2 | +# h2.core cross-platform release build script |
| 3 | +# Builds CLI binaries for all supported platforms |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +VERSION="${VERSION:-0.1.0}" |
| 8 | +OUTPUT_DIR="${OUTPUT_DIR:-dist}" |
| 9 | +CMD_PATH="./cmd/https-vpn" |
| 10 | +BINARY_NAME="https-vpn" |
| 11 | + |
| 12 | +# Create output directory |
| 13 | +mkdir -p "$OUTPUT_DIR" |
| 14 | + |
| 15 | +# Build targets: GOOS/GOARCH/ARM/Name |
| 16 | +TARGETS=( |
| 17 | + # Linux |
| 18 | + "linux/amd64//h2-linux-64" |
| 19 | + "linux/386//h2-linux-32" |
| 20 | + "linux/arm64//h2-linux-arm64-v8a" |
| 21 | + "linux/arm/7/h2-linux-arm32-v7a" |
| 22 | + "linux/arm/6/h2-linux-arm32-v6" |
| 23 | + "linux/arm/5/h2-linux-arm32-v5" |
| 24 | + "linux/mips//h2-linux-mips32" |
| 25 | + "linux/mipsle//h2-linux-mips32le" |
| 26 | + "linux/mips64//h2-linux-mips64" |
| 27 | + "linux/mips64le//h2-linux-mips64le" |
| 28 | + "linux/ppc64//h2-linux-ppc64" |
| 29 | + "linux/ppc64le//h2-linux-ppc64le" |
| 30 | + "linux/riscv64//h2-linux-riscv64" |
| 31 | + "linux/s390x//h2-linux-s390x" |
| 32 | + "linux/loong64//h2-linux-loong64" |
| 33 | + |
| 34 | + # macOS |
| 35 | + "darwin/amd64//h2-macos-64" |
| 36 | + "darwin/arm64//h2-macos-arm64-v8a" |
| 37 | + |
| 38 | + # FreeBSD |
| 39 | + "freebsd/amd64//h2-freebsd-64" |
| 40 | + "freebsd/386//h2-freebsd-32" |
| 41 | + "freebsd/arm64//h2-freebsd-arm64-v8a" |
| 42 | + "freebsd/arm/7/h2-freebsd-arm32-v7a" |
| 43 | + |
| 44 | + # OpenBSD |
| 45 | + "openbsd/amd64//h2-openbsd-64" |
| 46 | + "openbsd/386//h2-openbsd-32" |
| 47 | + "openbsd/arm64//h2-openbsd-arm64-v8a" |
| 48 | + "openbsd/arm/7/h2-openbsd-arm32-v7a" |
| 49 | + |
| 50 | + # Android (CLI) |
| 51 | + "android/amd64//h2-android-amd64" |
| 52 | + "android/arm64//h2-android-arm64-v8a" |
| 53 | + |
| 54 | + # Windows |
| 55 | + "windows/amd64//h2-windows-64" |
| 56 | + "windows/386//h2-windows-32" |
| 57 | + "windows/arm64//h2-windows-arm64-v8a" |
| 58 | +) |
| 59 | + |
| 60 | +echo "Building h2.core v${VERSION} for ${#TARGETS[@]} platforms..." |
| 61 | + |
| 62 | +build_target() { |
| 63 | + local target="$1" |
| 64 | + IFS='/' read -r goos goarch goarm name <<< "$target" |
| 65 | + |
| 66 | + local binary="$BINARY_NAME" |
| 67 | + [[ "$goos" == "windows" ]] && binary="${BINARY_NAME}.exe" |
| 68 | + |
| 69 | + local build_dir="$OUTPUT_DIR/$name" |
| 70 | + mkdir -p "$build_dir" |
| 71 | + |
| 72 | + echo "Building $name..." |
| 73 | + |
| 74 | + local env="GOOS=$goos GOARCH=$goarch CGO_ENABLED=0" |
| 75 | + [[ -n "$goarm" ]] && env="$env GOARM=$goarm" |
| 76 | + |
| 77 | + if eval $env go build -trimpath -ldflags="-s -w -X main.Version=${VERSION}" \ |
| 78 | + -o "$build_dir/$binary" "$CMD_PATH" 2>/dev/null; then |
| 79 | + # Create zip |
| 80 | + (cd "$OUTPUT_DIR" && zip -q -r "$name.zip" "$name") |
| 81 | + rm -rf "$build_dir" |
| 82 | + echo " -> $OUTPUT_DIR/$name.zip" |
| 83 | + else |
| 84 | + echo " -> SKIPPED (build failed)" |
| 85 | + rm -rf "$build_dir" |
| 86 | + fi |
| 87 | +} |
| 88 | + |
| 89 | +# Build all targets |
| 90 | +for target in "${TARGETS[@]}"; do |
| 91 | + build_target "$target" |
| 92 | +done |
| 93 | + |
| 94 | +# Win7 builds (requires Go 1.20 - last version with Win7 support) |
| 95 | +# Skip if GO120 not set |
| 96 | +if [ -n "$GO120" ] && [ -x "$GO120" ]; then |
| 97 | + echo "" |
| 98 | + echo "Building Win7 targets with Go 1.20..." |
| 99 | + |
| 100 | + for arch in "amd64/h2-win7-64" "386/h2-win7-32"; do |
| 101 | + IFS='/' read -r goarch name <<< "$arch" |
| 102 | + mkdir -p "$OUTPUT_DIR/$name" |
| 103 | + echo "Building $name..." |
| 104 | + GOOS=windows GOARCH=$goarch CGO_ENABLED=0 $GO120 build -trimpath \ |
| 105 | + -ldflags="-s -w -X main.Version=${VERSION}" \ |
| 106 | + -o "$OUTPUT_DIR/$name/${BINARY_NAME}.exe" "$CMD_PATH" |
| 107 | + (cd "$OUTPUT_DIR" && zip -q -r "$name.zip" "$name") |
| 108 | + rm -rf "$OUTPUT_DIR/$name" |
| 109 | + echo " -> $OUTPUT_DIR/$name.zip" |
| 110 | + done |
| 111 | +else |
| 112 | + echo "" |
| 113 | + echo "Skipping Win7 builds (set GO120=/path/to/go1.20/bin/go to enable)" |
| 114 | +fi |
| 115 | + |
| 116 | +# Generate checksums |
| 117 | +echo "" |
| 118 | +echo "Generating checksums..." |
| 119 | +(cd "$OUTPUT_DIR" && sha256sum *.zip > checksums.txt 2>/dev/null || shasum -a 256 *.zip > checksums.txt) |
| 120 | +echo " -> $OUTPUT_DIR/checksums.txt" |
| 121 | + |
| 122 | +echo "" |
| 123 | +echo "Build complete! Archives in $OUTPUT_DIR/" |
| 124 | +ls -lh "$OUTPUT_DIR"/*.zip 2>/dev/null | head -20 |
| 125 | +echo "..." |
| 126 | +echo "Total: $(ls -1 "$OUTPUT_DIR"/*.zip 2>/dev/null | wc -l) archives" |
0 commit comments