🔥 Tremora del Terra: ultimate hmac-file-server fix – final push before the drop 💾🔐
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# HMAC File Server v3.2 - Multi-Architecture Build Script
|
||||
# Compiles binaries for AMD64, ARM64, and ARM32 architectures
|
||||
# Compiles binaries for AMD64, ARM64, ARM32, Windows, and macOS architectures
|
||||
|
||||
# Remove set -e to prevent early exit on errors
|
||||
|
||||
@ -45,13 +45,57 @@ if [[ ! -d "$TEMP_DIR" ]]; then
|
||||
print_info "Created temp directory: $TEMP_DIR"
|
||||
fi
|
||||
|
||||
# Source files to compile
|
||||
SOURCE_FILES="cmd/server/main.go cmd/server/helpers.go cmd/server/config_validator.go cmd/server/config_test_scenarios.go"
|
||||
# Source directory to compile
|
||||
SOURCE_DIR="./cmd/server/"
|
||||
|
||||
print_status "Starting multi-architecture build for HMAC File Server v3.2"
|
||||
print_info "Source files: $SOURCE_FILES"
|
||||
print_info "Output directory: $TEMP_DIR"
|
||||
echo ""
|
||||
# Interactive menu function
|
||||
show_menu() {
|
||||
echo ""
|
||||
echo "HMAC File Server Multi-Architecture Builder"
|
||||
echo "=========================================="
|
||||
echo "1) Build for current platform (auto-detect)"
|
||||
echo "2) Build for Linux AMD64"
|
||||
echo "3) Build for Linux ARM64"
|
||||
echo "4) Build for Linux ARM32v7"
|
||||
echo "5) Build for Windows AMD64"
|
||||
echo "6) Build for macOS AMD64 (Intel)"
|
||||
echo "7) Build for macOS ARM64 (Apple Silicon)"
|
||||
echo "8) Build all supported architectures"
|
||||
echo "9) Clean build artifacts"
|
||||
echo "0) Exit"
|
||||
echo ""
|
||||
read -p "Choose an option [0-9]: " choice
|
||||
}
|
||||
|
||||
# Clean function
|
||||
clean_artifacts() {
|
||||
print_info "Cleaning build artifacts..."
|
||||
if [[ -d "$TEMP_DIR" ]]; then
|
||||
rm -rf "$TEMP_DIR"/*
|
||||
print_status "Build artifacts cleaned"
|
||||
else
|
||||
print_info "No artifacts to clean"
|
||||
fi
|
||||
}
|
||||
|
||||
# Detect current platform
|
||||
detect_platform() {
|
||||
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
local arch=$(uname -m)
|
||||
|
||||
case "$arch" in
|
||||
x86_64) arch="amd64" ;;
|
||||
arm64|aarch64) arch="arm64" ;;
|
||||
armv7l) arch="arm" ;;
|
||||
*) arch="unknown" ;;
|
||||
esac
|
||||
|
||||
case "$os" in
|
||||
linux) echo "linux/$arch" ;;
|
||||
darwin) echo "darwin/$arch" ;;
|
||||
*) echo "unknown/unknown" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Build function
|
||||
build_for_arch() {
|
||||
@ -68,7 +112,7 @@ build_for_arch() {
|
||||
export CGO_ENABLED=0
|
||||
|
||||
# Build the binary
|
||||
if go build -ldflags="-w -s" -o "$TEMP_DIR/$output_name" $SOURCE_FILES 2>/dev/null; then
|
||||
if go build -ldflags="-w -s" -o "$TEMP_DIR/$output_name" $SOURCE_DIR 2>/dev/null; then
|
||||
# Get file size
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
@ -92,105 +136,270 @@ build_for_arch() {
|
||||
return 0
|
||||
else
|
||||
print_error "Build failed: $arch_description"
|
||||
if [[ "$goos" == "windows" ]]; then
|
||||
print_warning " Windows builds may fail due to platform-specific code (syscalls)"
|
||||
print_info " Consider using Linux subsystem or implementing Windows-specific storage checks"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Track build results
|
||||
BUILDS_ATTEMPTED=0
|
||||
BUILDS_SUCCESSFUL=0
|
||||
FAILED_BUILDS=()
|
||||
|
||||
echo "Starting builds..."
|
||||
echo "===================="
|
||||
echo ""
|
||||
|
||||
# Build for AMD64 (x86_64)
|
||||
print_arch "AMD64 (Intel/AMD 64-bit)"
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "linux" "amd64" "hmac-file-server-linux-amd64" "AMD64 Linux"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("AMD64")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Build for ARM64 (AArch64)
|
||||
print_arch "ARM64 (AArch64)"
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "linux" "arm64" "hmac-file-server-linux-arm64" "ARM64 Linux"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("ARM64")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Build for ARM32 (ARMv7)
|
||||
print_arch "ARM32 (ARMv7)"
|
||||
export GOARM=7 # ARMv7 with hardware floating point
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "linux" "arm" "hmac-file-server-linux-arm32" "ARM32 Linux"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("ARM32")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Reset environment variables
|
||||
unset GOOS GOARCH CGO_ENABLED GOARM
|
||||
|
||||
# Build summary
|
||||
echo "Build Summary"
|
||||
echo "================"
|
||||
print_info "Builds attempted: $BUILDS_ATTEMPTED"
|
||||
print_info "Builds successful: $BUILDS_SUCCESSFUL"
|
||||
|
||||
if [[ $BUILDS_SUCCESSFUL -eq $BUILDS_ATTEMPTED ]]; then
|
||||
print_status "ALL BUILDS SUCCESSFUL!"
|
||||
# Build all architectures function
|
||||
build_all_architectures() {
|
||||
print_status "Starting multi-architecture build for HMAC File Server v3.2"
|
||||
print_info "Source directory: $SOURCE_DIR"
|
||||
print_info "Output directory: $TEMP_DIR"
|
||||
echo ""
|
||||
print_info "Generated binaries in $TEMP_DIR:"
|
||||
ls -lh "$TEMP_DIR"/hmac-file-server-* | while read -r line; do
|
||||
echo " $line"
|
||||
done
|
||||
|
||||
# Track build results
|
||||
BUILDS_ATTEMPTED=0
|
||||
BUILDS_SUCCESSFUL=0
|
||||
FAILED_BUILDS=()
|
||||
|
||||
echo "Starting builds..."
|
||||
echo "===================="
|
||||
echo ""
|
||||
print_info "Usage examples:"
|
||||
echo " - Copy to target system and run: ./hmac-file-server-linux-amd64 --version"
|
||||
echo " - Deploy with installer: cp temp/hmac-file-server-linux-amd64 /opt/hmac-file-server/"
|
||||
echo " - Docker deployment: COPY temp/hmac-file-server-linux-amd64 /usr/local/bin/"
|
||||
|
||||
# Build for AMD64 (x86_64)
|
||||
print_arch "AMD64 (Intel/AMD 64-bit)"
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "linux" "amd64" "hmac-file-server-linux-amd64" "AMD64 Linux"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("AMD64")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Build for ARM64 (AArch64)
|
||||
print_arch "ARM64 (AArch64)"
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "linux" "arm64" "hmac-file-server-linux-arm64" "ARM64 Linux"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("ARM64")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Build for ARM32 (ARMv7)
|
||||
print_arch "ARM32 (ARMv7)"
|
||||
export GOARM=7 # ARMv7 with hardware floating point
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "linux" "arm" "hmac-file-server-linux-arm32v7" "ARM32 Linux"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("ARM32")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Build for Windows AMD64
|
||||
print_arch "Windows AMD64"
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "windows" "amd64" "hmac-file-server-windows-amd64.exe" "Windows AMD64"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("Windows")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Build for macOS Intel
|
||||
print_arch "macOS Intel"
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "darwin" "amd64" "hmac-file-server-darwin-amd64" "macOS Intel"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("macOS Intel")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Build for macOS Apple Silicon
|
||||
print_arch "macOS Apple Silicon"
|
||||
((BUILDS_ATTEMPTED++))
|
||||
if build_for_arch "darwin" "arm64" "hmac-file-server-darwin-arm64" "macOS Apple Silicon"; then
|
||||
((BUILDS_SUCCESSFUL++))
|
||||
else
|
||||
FAILED_BUILDS+=("macOS ARM64")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Reset environment variables
|
||||
unset GOOS GOARCH CGO_ENABLED GOARM
|
||||
|
||||
show_build_summary
|
||||
}
|
||||
|
||||
# Build single architecture function
|
||||
build_single_arch() {
|
||||
local platform_desc=$1
|
||||
local goos=$2
|
||||
local goarch=$3
|
||||
local goarm=$4
|
||||
local output_name=$5
|
||||
|
||||
elif [[ $BUILDS_SUCCESSFUL -gt 0 ]]; then
|
||||
print_warning "PARTIAL SUCCESS: $BUILDS_SUCCESSFUL/$BUILDS_ATTEMPTED builds completed"
|
||||
if [[ ${#FAILED_BUILDS[@]} -gt 0 ]]; then
|
||||
print_error "Failed architectures: ${FAILED_BUILDS[*]}"
|
||||
print_status "Building for $platform_desc"
|
||||
print_info "Source directory: $SOURCE_DIR"
|
||||
print_info "Output directory: $TEMP_DIR"
|
||||
echo ""
|
||||
|
||||
if [[ -n "$goarm" ]]; then
|
||||
export GOARM=$goarm
|
||||
fi
|
||||
|
||||
else
|
||||
print_error "ALL BUILDS FAILED!"
|
||||
exit 1
|
||||
fi
|
||||
BUILDS_ATTEMPTED=1
|
||||
BUILDS_SUCCESSFUL=0
|
||||
FAILED_BUILDS=()
|
||||
|
||||
if build_for_arch "$goos" "$goarch" "$output_name" "$platform_desc"; then
|
||||
BUILDS_SUCCESSFUL=1
|
||||
else
|
||||
FAILED_BUILDS+=("$platform_desc")
|
||||
fi
|
||||
|
||||
unset GOOS GOARCH CGO_ENABLED GOARM
|
||||
show_build_summary
|
||||
}
|
||||
|
||||
echo ""
|
||||
print_info "Architecture compatibility:"
|
||||
echo " - AMD64: Intel/AMD 64-bit servers, desktops, cloud instances"
|
||||
echo " - ARM64: Apple Silicon, AWS Graviton, modern ARM servers"
|
||||
echo " - ARM32: Raspberry Pi, embedded systems, older ARM devices"
|
||||
# Build current platform function
|
||||
build_current_platform() {
|
||||
local platform=$(detect_platform)
|
||||
local goos=$(echo "$platform" | cut -d'/' -f1)
|
||||
local goarch=$(echo "$platform" | cut -d'/' -f2)
|
||||
|
||||
case "$platform" in
|
||||
"linux/amd64")
|
||||
build_single_arch "Current Platform (Linux AMD64)" "linux" "amd64" "" "hmac-file-server-linux-amd64"
|
||||
;;
|
||||
"linux/arm64")
|
||||
build_single_arch "Current Platform (Linux ARM64)" "linux" "arm64" "" "hmac-file-server-linux-arm64"
|
||||
;;
|
||||
"linux/arm")
|
||||
build_single_arch "Current Platform (Linux ARM32v7)" "linux" "arm" "7" "hmac-file-server-linux-arm32v7"
|
||||
;;
|
||||
"darwin/amd64")
|
||||
build_single_arch "Current Platform (macOS Intel)" "darwin" "amd64" "" "hmac-file-server-darwin-amd64"
|
||||
;;
|
||||
"darwin/arm64")
|
||||
build_single_arch "Current Platform (macOS Apple Silicon)" "darwin" "arm64" "" "hmac-file-server-darwin-arm64"
|
||||
;;
|
||||
*)
|
||||
print_error "Unsupported platform: $platform"
|
||||
print_info "Supported platforms: linux/amd64, linux/arm64, linux/arm, darwin/amd64, darwin/arm64"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
echo ""
|
||||
print_status "Multi-architecture build completed!"
|
||||
# Show build summary
|
||||
show_build_summary() {
|
||||
# Build summary
|
||||
echo "Build Summary"
|
||||
echo "================"
|
||||
print_info "Builds attempted: $BUILDS_ATTEMPTED"
|
||||
print_info "Builds successful: $BUILDS_SUCCESSFUL"
|
||||
|
||||
# Final verification
|
||||
echo ""
|
||||
print_info "Final verification:"
|
||||
for binary in "$TEMP_DIR"/hmac-file-server-*; do
|
||||
if [[ -f "$binary" ]]; then
|
||||
filename=$(basename "$binary")
|
||||
if file "$binary" >/dev/null 2>&1; then
|
||||
file_info=$(file "$binary" | cut -d: -f2- | sed 's/^ *//')
|
||||
print_info " OK $filename: $file_info"
|
||||
else
|
||||
print_info " OK $filename: Binary file"
|
||||
if [[ $BUILDS_SUCCESSFUL -eq $BUILDS_ATTEMPTED ]]; then
|
||||
print_status "ALL BUILDS SUCCESSFUL!"
|
||||
echo ""
|
||||
print_info "Generated binaries in $TEMP_DIR:"
|
||||
ls -lh "$TEMP_DIR"/hmac-file-server-* 2>/dev/null | while read -r line; do
|
||||
echo " $line"
|
||||
done
|
||||
echo ""
|
||||
print_info "Usage examples:"
|
||||
echo " - Copy to target system and run: ./hmac-file-server-linux-amd64 --version"
|
||||
echo " - Deploy with installer: cp temp/hmac-file-server-linux-amd64 /opt/hmac-file-server/"
|
||||
echo " - Docker deployment: COPY temp/hmac-file-server-linux-amd64 /usr/local/bin/"
|
||||
|
||||
elif [[ $BUILDS_SUCCESSFUL -gt 0 ]]; then
|
||||
print_warning "PARTIAL SUCCESS: $BUILDS_SUCCESSFUL/$BUILDS_ATTEMPTED builds completed"
|
||||
if [[ ${#FAILED_BUILDS[@]} -gt 0 ]]; then
|
||||
print_error "Failed architectures: ${FAILED_BUILDS[*]}"
|
||||
fi
|
||||
|
||||
else
|
||||
print_error "ALL BUILDS FAILED!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
print_info "Architecture compatibility:"
|
||||
echo " - AMD64: Intel/AMD 64-bit servers, desktops, cloud instances"
|
||||
echo " - ARM64: Apple Silicon, AWS Graviton, modern ARM servers"
|
||||
echo " - ARM32: Raspberry Pi, embedded systems, older ARM devices"
|
||||
echo " - Windows: Windows 10/11, Windows Server"
|
||||
echo " - macOS: macOS 10.15+, Intel and Apple Silicon"
|
||||
|
||||
echo ""
|
||||
print_status "Build completed!"
|
||||
|
||||
# Final verification
|
||||
echo ""
|
||||
print_info "Final verification:"
|
||||
for binary in "$TEMP_DIR"/hmac-file-server-*; do
|
||||
if [[ -f "$binary" ]]; then
|
||||
filename=$(basename "$binary")
|
||||
if file "$binary" >/dev/null 2>&1; then
|
||||
file_info=$(file "$binary" | cut -d: -f2- | sed 's/^ *//')
|
||||
print_info " OK $filename: $file_info"
|
||||
else
|
||||
print_info " OK $filename: Binary file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Main execution
|
||||
if [[ $# -eq 0 ]]; then
|
||||
# Interactive mode
|
||||
while true; do
|
||||
show_menu
|
||||
case $choice in
|
||||
1)
|
||||
build_current_platform
|
||||
break
|
||||
;;
|
||||
2)
|
||||
build_single_arch "Linux AMD64" "linux" "amd64" "" "hmac-file-server-linux-amd64"
|
||||
break
|
||||
;;
|
||||
3)
|
||||
build_single_arch "Linux ARM64" "linux" "arm64" "" "hmac-file-server-linux-arm64"
|
||||
break
|
||||
;;
|
||||
4)
|
||||
build_single_arch "Linux ARM32v7" "linux" "arm" "7" "hmac-file-server-linux-arm32v7"
|
||||
break
|
||||
;;
|
||||
5)
|
||||
build_single_arch "Windows AMD64" "windows" "amd64" "" "hmac-file-server-windows-amd64.exe"
|
||||
break
|
||||
;;
|
||||
6)
|
||||
build_single_arch "macOS Intel" "darwin" "amd64" "" "hmac-file-server-darwin-amd64"
|
||||
break
|
||||
;;
|
||||
7)
|
||||
build_single_arch "macOS Apple Silicon" "darwin" "arm64" "" "hmac-file-server-darwin-arm64"
|
||||
break
|
||||
;;
|
||||
8)
|
||||
build_all_architectures
|
||||
break
|
||||
;;
|
||||
9)
|
||||
clean_artifacts
|
||||
;;
|
||||
0)
|
||||
print_info "Exiting build script"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_error "Invalid option. Please choose 0-9."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
# Non-interactive mode - build all architectures
|
||||
build_all_architectures
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
Reference in New Issue
Block a user