Archived
145 lines
3.9 KiB
Python
Executable File
145 lines
3.9 KiB
Python
Executable File
#!/bin/bash
|
|
|
|
# Abort if anything fails
|
|
set -e
|
|
|
|
# Source common functions
|
|
BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..")
|
|
source "$BUILD_ROOT/helpers/message-helpers.sh"
|
|
source "$BUILD_ROOT/helpers/docker-helpers.sh"
|
|
source "$BUILD_ROOT/helpers/paths.sh"
|
|
|
|
# Create directories if they don't exist
|
|
mkdir -p "$BUILD_OUTPUT_DIR" "$REPO_DIR" "$SRC_DIR"
|
|
|
|
print_header "Omarchy AUR Package Builder"
|
|
|
|
# Check Docker is available
|
|
check_docker
|
|
|
|
# Parse command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--arch)
|
|
ARCH="$2"
|
|
update_arch_paths
|
|
shift 2
|
|
;;
|
|
--mirror)
|
|
MIRROR="$2"
|
|
if [[ "$MIRROR" != "edge" && "$MIRROR" != "stable" ]]; then
|
|
print_error "Invalid mirror: $MIRROR (must be 'edge' or 'stable')"
|
|
exit 1
|
|
fi
|
|
update_arch_paths
|
|
shift 2
|
|
;;
|
|
--package)
|
|
shift
|
|
PACKAGES=""
|
|
while [[ $# -gt 0 && ! "$1" =~ ^-- ]]; do
|
|
PACKAGES="$PACKAGES $1"
|
|
shift
|
|
done
|
|
PACKAGES="${PACKAGES# }"
|
|
;;
|
|
-h | --help)
|
|
echo "Usage: $0 [OPTIONS]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " --arch <arch> Target architecture (x86_64 or aarch64, default: x86_64)"
|
|
echo " --mirror <mirror> Mirror to use (edge or stable, default: edge)"
|
|
echo " --package <names> Build only the specified package(s) (space-separated)"
|
|
echo " -h, --help Show this help message"
|
|
echo ""
|
|
echo "This script builds packages from pkgbuilds/ directories based on mirror:"
|
|
echo " --mirror edge: builds from pkgbuilds/edge/ + pkgbuilds/shared/"
|
|
echo " --mirror stable: builds from pkgbuilds/stable/ + pkgbuilds/shared/"
|
|
echo ""
|
|
echo "Or build specific packages with --package:"
|
|
echo " Package names should match directories in the relevant pkgbuilds/ tier"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 --arch aarch64"
|
|
echo " $0 --mirror stable"
|
|
echo " $0 --package yay"
|
|
echo " $0 --package yay elephant cursor-bin"
|
|
echo ""
|
|
exit 0
|
|
;;
|
|
*)
|
|
print_error "Unknown option: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Show target architecture and mirror after parsing args
|
|
print_info "Target architecture: $ARCH"
|
|
print_info "Mirror: $MIRROR"
|
|
print_info "Build workspace: $BUILD_OUTPUT_DIR"
|
|
print_info "Final output: $REPO_DIR"
|
|
|
|
# Setup QEMU for aarch64 builds on x86_64 hosts
|
|
if [[ "$(uname -m)" == "x86_64" && "$ARCH" == "aarch64" ]]; then
|
|
# Check if QEMU is already working
|
|
if ! docker run --rm --platform linux/arm64 alpine:3.21 /bin/true >/dev/null 2>&1; then
|
|
print_info "Setting up QEMU for ARM64 emulation..."
|
|
setup_qemu
|
|
fi
|
|
fi
|
|
|
|
# Clean build-output directory to start fresh
|
|
print_info "Cleaning build workspace..."
|
|
rm -rf "$BUILD_OUTPUT_DIR"/*
|
|
mkdir -p "$BUILD_OUTPUT_DIR"
|
|
|
|
# Show package info
|
|
if [[ -n "$PACKAGES" ]]; then
|
|
print_info "Building packages: $PACKAGES"
|
|
else
|
|
print_info "Building all packages for $MIRROR mirror"
|
|
fi
|
|
|
|
# Build/update the Docker image
|
|
build_docker_image "$BUILD_DIR" "$ARCH" "$MIRROR"
|
|
|
|
print_info "Running AUR package build..."
|
|
|
|
# Create output directories if they don't exist
|
|
mkdir -p "$BUILD_OUTPUT_DIR"
|
|
mkdir -p "$REPO_DIR"
|
|
|
|
# Ensure output directories are writable by container user
|
|
make_dir_writable "$BUILD_OUTPUT_DIR"
|
|
make_dir_writable "$REPO_DIR"
|
|
|
|
# Build Docker arguments
|
|
DOCKER_ARGS=(
|
|
--rm
|
|
-e ARCH="$ARCH"
|
|
-e MIRROR="$MIRROR"
|
|
-e PACKAGES="$PACKAGES"
|
|
-v "$BUILD_ROOT/build-output:/build-output"
|
|
-v "$BUILD_ROOT/pkgs.omarchy.org:/pkgs.omarchy.org"
|
|
-v "$BUILD_DIR:/build:ro"
|
|
-v "$BUILD_ROOT/pkgbuilds:/pkgbuilds:ro"
|
|
)
|
|
|
|
# Run the builder with assembled args
|
|
IMAGE_TAG="omarchy-pkg-builder:latest-$ARCH-$MIRROR"
|
|
PLATFORM_ARG=$(get_platform_arg "$ARCH")
|
|
|
|
docker run $PLATFORM_ARG "${DOCKER_ARGS[@]}" "$IMAGE_TAG" /build/build.sh
|
|
|
|
BUILD_RESULT=$?
|
|
|
|
# Summary
|
|
echo ""
|
|
if [[ $BUILD_RESULT -eq 0 ]]; then
|
|
print_success "AUR build completed successfully!"
|
|
else
|
|
print_warning "Some AUR packages failed (see details above)"
|
|
exit $BUILD_RESULT
|
|
fi
|