Private
Public Access
1
0

Add multi-platform build scripts

- build-rpm.sh: Build RPM packages on RHEL/CentOS/Fedora
- build-alpine.sh: Build APK packages on Alpine Linux
- build-arch.sh: Build Arch packages on Arch Linux/Manjaro

Each script can also run in Docker containers for cross-platform builds.
Complements CI/CD pipeline for local package building.
This commit is contained in:
2026-04-10 02:01:46 +00:00
parent 7891fb8d91
commit 943aafbec2
3 changed files with 198 additions and 0 deletions

72
build-alpine.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/bash
# Build Alpine Package (.apk)
# Run on: Alpine Linux 3.18+
# Or in Docker: docker run -v $(pwd):/build alpine:latest /build/build-alpine.sh
set -e
echo "=== Linux Patch API - Alpine Build Script ==="
echo ""
# Check if running on Alpine
if ! command -v abuild &> /dev/null; then
echo "Installing Alpine build tools..."
apk add --no-cache alpine-sdk rust cargo openssl-dev systemd-dev git
fi
# Setup build environment
echo "Setting up build environment..."
export CBUILDROOT=$(pwd)/.abuild
mkdir -p "$CBUILDROOT"
# Build release binary
echo "Building release binary..."
cargo build --release --target x86_64-unknown-linux-musl
# Create package directory
PKGDIR=$(pwd)/apk-package
mkdir -p "$PKGDIR"/usr/bin
mkdir -p "$PKGDIR"/etc/linux_patch_api
mkdir -p "$PKGDIR"/lib/systemd/system
# Copy files
cp target/x86_64-unknown-linux-musl/release/linux-patch-api "$PKGDIR"/usr/bin/
chmod 755 "$PKGDIR"/usr/bin/linux-patch-api
cp configs/linux-patch-api.service "$PKGDIR"/lib/systemd/system/
cp configs/config.yaml.example "$PKGDIR"/etc/linux_patch_api/config.yaml
cp configs/whitelist.yaml.example "$PKGDIR"/etc/linux_patch_api/whitelist.yaml
# Create APKBUILD
echo "Creating APKBUILD..."
cat > APKBUILD << 'EOF'
pkgname=linux-patch-api
pkgver=1.0.0
pkgrel=1
pkgdesc="Secure remote package management API for Linux systems"
url="https://gitea.internal/linux-patch-api"
arch="x86_64"
license="MIT"
depends="systemd"
source="apk-package"
package() {
cp -r "$srcdir"/apk-package/* "$pkgdir"/
}
EOF
# Build APK package
echo "Building APK package..."
abuild -F -r
# Copy to releases directory
echo ""
echo "Copying package to releases/..."
mkdir -p releases
cp ~/packages/x86_64/*.apk releases/ 2>/dev/null || cp /root/packages/x86_64/*.apk releases/ || find / -name "linux-patch-api-*.apk" -exec cp {} releases/ \; 2>/dev/null || true
echo ""
echo "=== Build Complete ==="
echo "Package: releases/linux-patch-api-*.apk"
echo ""
echo "Install with:"
echo " sudo apk add --allow-unstable ./releases/linux-patch-api-*.apk"

76
build-arch.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/bash
# Build Arch Linux Package (.pkg.tar.zst)
# Run on: Arch Linux, Manjaro
# Or in Docker: docker run -v $(pwd):/build archlinux:latest /build/build-arch.sh
set -e
echo "=== Linux Patch API - Arch Build Script ==="
echo ""
# Check if running on Arch
if ! command -v makepkg &> /dev/null; then
echo "Error: makepkg not found. This script must run on Arch Linux."
echo "Or use Docker: docker run -v \$(pwd):/build archlinux:latest /build/build-arch.sh"
exit 1
fi
# Install build dependencies
echo "Installing build dependencies..."
sudo pacman -Syu --noconfirm rust cargo systemd git base-devel
# Build release binary
echo "Building release binary..."
cargo build --release
# Create package directory
PKGDIR=$(pwd)/arch-package
mkdir -p "$PKGDIR"/usr/bin
mkdir -p "$PKGDIR"/etc/linux_patch_api
mkdir -p "$PKGDIR"/usr/lib/systemd/system
# Copy files
cp target/release/linux-patch-api "$PKGDIR"/usr/bin/
chmod 755 "$PKGDIR"/usr/bin/linux-patch-api
cp configs/linux-patch-api.service "$PKGDIR"/usr/lib/systemd/system/
cp configs/config.yaml.example "$PKGDIR"/etc/linux_patch_api/config.yaml
cp configs/whitelist.yaml.example "$PKGDIR"/etc/linux_patch_api/whitelist.yaml
# Create PKGBUILD
echo "Creating PKGBUILD..."
cat > PKGBUILD << 'EOF'
pkgname=linux-patch-api
pkgver=1.0.0
pkgrel=1
pkgdesc="Secure remote package management API for Linux systems"
url="https://gitea.internal/linux-patch-api"
arch=('x86_64')
license=('MIT')
depends=('systemd')
source=('arch-package')
package() {
cp -r "$srcdir"/arch-package/* "$pkgdir"/
}
EOF
# Create .SRCINFO
echo "Creating .SRCINFO..."
makepkg --printsrcinfo > .SRCINFO
# Build package
echo "Building Arch package..."
makepkg -f --noconfirm
# Copy to releases directory
echo ""
echo "Copying package to releases/..."
mkdir -p releases
cp *.pkg.tar.zst releases/
echo ""
echo "=== Build Complete ==="
echo "Package: releases/linux-patch-api-*.pkg.tar.zst"
echo ""
echo "Install with:"
echo " sudo pacman -U ./releases/linux-patch-api-*.pkg.tar.zst"

50
build-rpm.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
# Build RPM Package for RHEL/CentOS/Fedora
# Run on: RHEL 8/9, CentOS 8/9, Fedora 38+
set -e
echo "=== Linux Patch API - RPM Build Script ==="
echo ""
# Check if running on RPM-based system
if ! command -v rpmbuild &> /dev/null; then
echo "Installing RPM build tools..."
if command -v dnf &> /dev/null; then
sudo dnf install -y rpm-build cargo rust gcc systemd-devel
elif command -v yum &> /dev/null; then
sudo yum install -y rpm-build cargo rust gcc systemd-devel
else
echo "Error: Cannot install rpm-build. Please install manually."
exit 1
fi
fi
# Setup RPM build directory structure
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
# Copy source files
echo "Preparing source files..."
cp linux-patch-api.spec ~/rpmbuild/SPECS/
cp -r target/release/linux-patch-api ~/rpmbuild/SOURCES/ 2>/dev/null || cargo build --release
cp -r configs ~/rpmbuild/SOURCES/
cp -r debian ~/rpmbuild/SOURCES/
# Build RPM
echo "Building RPM package..."
rpmbuild -ba ~/rpmbuild/SPECS/linux-patch-api.spec
# Copy to releases directory
echo ""
echo "Copying package to releases/..."
mkdir -p releases
cp ~/rpmbuild/RPMS/x86_64/*.rpm releases/
echo ""
echo "=== Build Complete ==="
echo "Package: releases/linux-patch-api-*.rpm"
echo ""
echo "Install with:"
echo " sudo dnf install -y ./releases/linux-patch-api-*.rpm"
echo " # or"
echo " sudo yum install -y ./releases/linux-patch-api-*.rpm"