From c2d62eddd6ff2093bc2991e02bdf27e5e04c21ed Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 27 Oct 2025 00:23:23 -0400 Subject: [PATCH] Run remove in a container --- bin/remove-package | 69 +++++++++++++++++++++++++++++++---------- build/remove-package.sh | 45 +++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 16 deletions(-) create mode 100755 build/remove-package.sh diff --git a/bin/remove-package b/bin/remove-package index 764b18e..b6a3b91 100755 --- a/bin/remove-package +++ b/bin/remove-package @@ -1,47 +1,84 @@ #!/bin/bash set -e -# Get the directory of this script -SCRIPT_DIR=$(realpath "${BASH_SOURCE[0]%/*}") -BUILD_ROOT=$(realpath "$SCRIPT_DIR/..") +BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") source "$BUILD_ROOT/lib/message-helpers.sh" ARCH=${ARCH:-x86_64} -ARCH_DIR="$BUILD_ROOT/pkgs.omarchy.org/$ARCH" -cd "$ARCH_DIR" +REPO_DIR="$BUILD_ROOT/pkgs.omarchy.org/$ARCH" +BUILD_DIR="$BUILD_ROOT/build" + +print_header "Remove Package" if [[ -z "$1" ]]; then + print_error "Package name required" + echo "" echo "Usage: $0 " exit 1 fi -# Find exact package files (not subpackages like yay-debug) -FILES=$(ls ${1}-[0-9]*.pkg.tar.* 2>/dev/null || true) +PACKAGE_NAME="$1" + +print_info "Target architecture: $ARCH" +print_info "Repository: $REPO_DIR" + +# Check if repository exists +if [[ ! -d "$REPO_DIR" ]]; then + print_error "Repository directory not found: $REPO_DIR" + exit 1 +fi + +# Check Docker is available +check_docker + +# Find package files to confirm before running Docker +cd "$REPO_DIR" +FILES=$(ls ${PACKAGE_NAME}-[0-9]*.pkg.tar.* 2>/dev/null || true) if [[ -z "$FILES" ]]; then - echo "Package '$1' not found" + print_error "Package '$PACKAGE_NAME' not found" exit 1 fi # Confirm removal +echo "" echo "Package files to remove:" for file in $FILES; do echo " - $file" done echo "" -read -p "Remove package '$1'? (y/N) " -n 1 -r +read -p "Remove package '$PACKAGE_NAME'? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then print_info "Removal cancelled" exit 0 fi -# Remove from database -repo-remove omarchy.db.tar.zst "$1" +# Build/update the Docker image +build_docker_image "$BUILD_DIR" -# Remove files (only the exact package, not subpackages) -for file in $FILES; do - rm -f "$file" -done +print_info "Removing package..." -echo "Package '$1' removed" +# 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 + +# Run the removal script in Docker +docker run --rm \ + -e ARCH="$ARCH" \ + -v "$BUILD_ROOT/pkgs.omarchy.org:/pkgs.omarchy.org" \ + -v "$BUILD_DIR:/build:ro" \ + omarchy-aur-builder:latest /build/remove-package.sh "$PACKAGE_NAME" + +RESULT=$? + +echo "" +if [[ $RESULT -eq 0 ]]; then + print_success "Package removal completed successfully!" +else + print_error "Package removal failed" + exit $RESULT +fi diff --git a/build/remove-package.sh b/build/remove-package.sh new file mode 100755 index 0000000..b79adba --- /dev/null +++ b/build/remove-package.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Remove package from repository (runs inside Docker) + +set -e + +ARCH=${ARCH:-x86_64} +PACKAGE_NAME="$1" +REPO_DIR="/pkgs.omarchy.org/$ARCH" + +if [[ -z "$PACKAGE_NAME" ]]; then + echo "ERROR: Package name required" + exit 1 +fi + +cd "$REPO_DIR" + +# Find exact package files (not subpackages like yay-debug) +FILES=$(ls ${PACKAGE_NAME}-[0-9]*.pkg.tar.* 2>/dev/null || true) + +if [[ -z "$FILES" ]]; then + echo "ERROR: Package '$PACKAGE_NAME' not found" + exit 1 +fi + +echo "==> Removing package: $PACKAGE_NAME" +echo "" +echo "Files to remove:" +for file in $FILES; do + echo " - $file" +done +echo "" + +# Remove from database +echo "==> Removing from repository database..." +repo-remove omarchy.db.tar.zst "$PACKAGE_NAME" + +# Remove files +echo "==> Removing package files..." +for file in $FILES; do + rm -f "$file" + echo " ✓ Removed $file" +done + +echo "" +echo "==> Package '$PACKAGE_NAME' removed successfully"