From 51a3318b10a70dc3e584530eba562c40304a7c99 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 27 Oct 2025 00:28:46 -0400 Subject: [PATCH] Consolidate more helpers --- bin/build | 11 +++----- bin/clean-repo | 2 +- bin/promote-build | 2 +- bin/release | 2 +- bin/remove-package | 9 +++---- bin/repo | 2 +- bin/sign | 9 +++---- bin/sync-aur | 2 +- bin/sync-repo | 2 +- bin/update-repo | 9 +++---- helpers/docker-helpers.sh | 42 +++++++++++++++++++++++++++++ {lib => helpers}/message-helpers.sh | 21 --------------- 12 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 helpers/docker-helpers.sh rename {lib => helpers}/message-helpers.sh (54%) diff --git a/bin/build b/bin/build index be56dda..f4486c7 100755 --- a/bin/build +++ b/bin/build @@ -5,7 +5,8 @@ set -e # Source common functions BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" +source "$BUILD_ROOT/helpers/docker-helpers.sh" ARCH=${ARCH:-x86_64} @@ -89,12 +90,8 @@ build_docker_image "$BUILD_DIR" print_info "Running AUR package build..." # Ensure output directories are writable by container user -# The container runs as 'builder' user, so we need to make output writable -if [ "$(id -u)" -eq 0 ]; then - chmod -R 777 "$BUILD_OUTPUT_DIR" "$FINAL_OUTPUT_DIR" -else - sudo chown -R $(id -u):$(id -g) "$BUILD_OUTPUT_DIR" "$FINAL_OUTPUT_DIR" 2>/dev/null || chmod -R 777 "$BUILD_OUTPUT_DIR" "$FINAL_OUTPUT_DIR" -fi +make_dir_writable "$BUILD_OUTPUT_DIR" +make_dir_writable "$FINAL_OUTPUT_DIR" # Build Docker arguments DOCKER_ARGS=( diff --git a/bin/clean-repo b/bin/clean-repo index ec7b252..5d512d9 100755 --- a/bin/clean-repo +++ b/bin/clean-repo @@ -6,7 +6,7 @@ set -e # Source common functions BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" # Repository configuration ARCH=${ARCH:-x86_64} diff --git a/bin/promote-build b/bin/promote-build index e57a9de..94f3ba6 100755 --- a/bin/promote-build +++ b/bin/promote-build @@ -4,7 +4,7 @@ set -e BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" ARCH=${ARCH:-x86_64} BUILD_OUTPUT_DIR="$BUILD_ROOT/build-output/$ARCH" diff --git a/bin/release b/bin/release index 8510a8e..c7b3b42 100755 --- a/bin/release +++ b/bin/release @@ -4,7 +4,7 @@ set -e BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" ARCH=${ARCH:-x86_64} SYNC_REMOTE="" diff --git a/bin/remove-package b/bin/remove-package index b6a3b91..12252cc 100755 --- a/bin/remove-package +++ b/bin/remove-package @@ -2,7 +2,8 @@ set -e BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" +source "$BUILD_ROOT/helpers/docker-helpers.sh" ARCH=${ARCH:-x86_64} REPO_DIR="$BUILD_ROOT/pkgs.omarchy.org/$ARCH" @@ -60,11 +61,7 @@ build_docker_image "$BUILD_DIR" print_info "Removing package..." # Ensure directory is writable by container user -if [ "$(id -u)" -eq 0 ]; then - chmod -R 777 "$REPO_DIR" -else - sudo chown -R $(id -u):$(id -g) "$REPO_DIR" 2>/dev/null || chmod -R 777 "$REPO_DIR" -fi +make_dir_writable "$REPO_DIR" # Run the removal script in Docker docker run --rm \ diff --git a/bin/repo b/bin/repo index 211be2a..764479f 100755 --- a/bin/repo +++ b/bin/repo @@ -9,7 +9,7 @@ SCRIPT_DIR=$(realpath "${BASH_SOURCE[0]%/*}") BUILD_ROOT=$(realpath "$SCRIPT_DIR/..") # Source common functions -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" # Setup logging with timestamps LOG_DIR="$BUILD_ROOT/logs" diff --git a/bin/sign b/bin/sign index bf4feea..393ad1a 100755 --- a/bin/sign +++ b/bin/sign @@ -4,7 +4,8 @@ set -e BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" +source "$BUILD_ROOT/helpers/docker-helpers.sh" ARCH=${ARCH:-x86_64} BUILD_OUTPUT_DIR="$BUILD_ROOT/build-output/$ARCH" @@ -66,11 +67,7 @@ build_docker_image "$BUILD_DIR" print_info "Running package signing..." # Ensure output directory is writable by container user -if [ "$(id -u)" -eq 0 ]; then - chmod -R 777 "$BUILD_OUTPUT_DIR" -else - sudo chown -R $(id -u):$(id -g) "$BUILD_OUTPUT_DIR" 2>/dev/null || chmod -R 777 "$BUILD_OUTPUT_DIR" -fi +make_dir_writable "$BUILD_OUTPUT_DIR" # Run the signing script in Docker docker run --rm \ diff --git a/bin/sync-aur b/bin/sync-aur index 4742b15..a972376 100755 --- a/bin/sync-aur +++ b/bin/sync-aur @@ -1,7 +1,7 @@ #!/bin/bash BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" PKGBUILDS_DIR="$BUILD_ROOT/pkgbuilds" PACKAGES_FILE="$BUILD_ROOT/build/packages/omarchy-aur.packages" diff --git a/bin/sync-repo b/bin/sync-repo index 58730df..0d6c96c 100755 --- a/bin/sync-repo +++ b/bin/sync-repo @@ -2,7 +2,7 @@ # Source common functions BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" # Default remote (production) DEFAULT_REMOTE="pkgs.omarchy.org:omarchy-pkgs" diff --git a/bin/update-repo b/bin/update-repo index 00080e5..a07427b 100755 --- a/bin/update-repo +++ b/bin/update-repo @@ -6,7 +6,8 @@ set -e # Source common functions BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") -source "$BUILD_ROOT/lib/message-helpers.sh" +source "$BUILD_ROOT/helpers/message-helpers.sh" +source "$BUILD_ROOT/helpers/docker-helpers.sh" ARCH=${ARCH:-x86_64} BUILD_DIR="$BUILD_ROOT/build" @@ -27,11 +28,7 @@ update_database() { fi # Make output directory writable for container - if [ "$(id -u)" -eq 0 ]; then - chmod -R 777 "$ARCH_DIR" - else - sudo chown -R $(id -u):$(id -g) "$ARCH_DIR" 2>/dev/null || chmod -R 777 "$ARCH_DIR" - fi + make_dir_writable "$ARCH_DIR" # Build Docker image build_docker_image "$BUILD_DIR" diff --git a/helpers/docker-helpers.sh b/helpers/docker-helpers.sh new file mode 100644 index 0000000..2cb160a --- /dev/null +++ b/helpers/docker-helpers.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Docker helper functions for Omarchy package build system + +# Check Docker is available and running +check_docker() { + if ! command -v docker &>/dev/null; then + print_error "Docker is not installed" + exit 1 + fi + + if ! docker info &>/dev/null; then + print_error "Docker daemon is not running" + print_warning "Start Docker with: sudo systemctl start docker" + exit 1 + fi +} + +# Build the Docker image if needed +build_docker_image() { + local build_dir="$1" + print_info "Building Docker image..." + docker build -t omarchy-aur-builder:latest -f "$build_dir/Dockerfile" "$build_dir" +} + +# Make directory writable by Docker container user +make_dir_writable() { + local dir="$1" + if [ "$(id -u)" -eq 0 ]; then + chmod -R 777 "$dir" + else + sudo chown -R $(id -u):$(id -g) "$dir" 2>/dev/null || chmod -R 777 "$dir" + fi +} + +# Run a Docker container with standard setup +run_docker() { + local script="$1" + shift + local -a args=("$@") + + docker run --rm "${args[@]}" omarchy-aur-builder:latest "$script" +} diff --git a/lib/message-helpers.sh b/helpers/message-helpers.sh similarity index 54% rename from lib/message-helpers.sh rename to helpers/message-helpers.sh index 203f382..69679b0 100644 --- a/lib/message-helpers.sh +++ b/helpers/message-helpers.sh @@ -36,24 +36,3 @@ print_header() { echo -e "${BOLD}$1${NC}" echo -e "${BOLD}================================${NC}" } - -# Check Docker is available and running -check_docker() { - if ! command -v docker &>/dev/null; then - print_error "Docker is not installed" - exit 1 - fi - - if ! docker info &>/dev/null; then - print_error "Docker daemon is not running" - print_warning "Start Docker with: sudo systemctl start docker" - exit 1 - fi -} - -# Build the Docker image if needed -build_docker_image() { - local build_dir="$1" - print_info "Building Docker image..." - docker build -t omarchy-aur-builder:latest -f "$build_dir/Dockerfile" "$build_dir" -}