# Docker helper functions for Omarchy package build system 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 } docker_native_arch() { case "$(uname -m)" in x86_64) echo x86_64 ;; aarch64 | arm64) echo aarch64 ;; *) return 1 ;; esac } setup_qemu() { # Register emulators for builds whose target differs from the host. if ! docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes >/dev/null 2>&1; then print_error "Failed to set up QEMU emulation" exit 1 fi print_success "QEMU emulation enabled" } build_docker_image() { local build_dir="$1" local arch="${2:-x86_64}" local mirror="${3:-edge}" local platform="" local image_tag="omarchy-pkg-builder:latest-$arch-$mirror" case "$arch" in x86_64) platform="linux/amd64" ;; aarch64) platform="linux/arm64" ;; *) print_error "Unsupported architecture: $arch" exit 1 ;; esac print_info "Building Docker image for $arch ($platform) using $mirror mirror..." docker buildx build \ --platform "$platform" \ --build-arg MIRROR="$mirror" \ --load \ -t "$image_tag" \ -f "$build_dir/Dockerfile" \ "$build_dir" } get_platform_arg() { local arch="$1" case "$arch" in x86_64) echo "--platform=linux/amd64" ;; aarch64) echo "--platform=linux/arm64" ;; *) return 1 ;; esac } make_dir_writable() { local dir="$1" if (( EUID == 0 )); then chmod -R 777 "$dir" else # chown can succeed on part of the tree and fail on the rest (files a # previous container left behind as another uid); the old `|| chmod` # fallback only ran when chown failed outright, leaving those files # unwritable. Always follow with chmod so the whole tree is usable. sudo chown -R "$(id -u):$(id -g)" "$dir" 2>/dev/null || true chmod -R 777 "$dir" fi }