#!/bin/bash . "$(dirname "$(readlink -e "$0")")/config" . "$(dirname "$(readlink -e "$0")")/db-functions" if (( $# < 3 )); then msg "usage: %s ..." "${0##*/}" msg " or: %s pkgname= ..." "${0##*/}" exit 1 fi repo="$1" arch="$2" pkgs=("${@:3}") if ! check_repo_permission "$repo"; then die "You don't have permission to remove packages from %s" "$repo" fi if [[ $arch = any ]]; then tarches=("${ARCHES[@]}") else tarches=("$arch") fi msg "Removing packages from [%s]..." "$repo" for tarch in "${tarches[@]}"; do repo_lock "$repo" "$tarch" || exit 1 declare -a remove_pkgs_$tarch done for pkg in "${pkgs[@]}"; do for tarch in "${tarches[@]}"; do msg2 "%s (%s)" "$pkg" "$tarch" declare -n remove_pkgs="remove_pkgs_${tarch}" # We could just use %n and a single `mapfile`, but # getting extra info and printing everything is more # user-friendly. found=false while read -r pkgbase pkgname pkgver; do [[ $pkgbase != '(null)' ]] || pkgbase=$pkgname plain 'pkgname=%s (%s)' "${pkgname}" "$pkgver" remove_pkgs+=("${pkgname}") found=true done < <( if [[ $pkg = 'pkgname='* ]]; then arch_expac "$repo" "$tarch" '%e %n %v' "${pkg#pkgname=}" else arch_expac_pkgbase "$repo" "$tarch" '%e %n %v' "$pkg" fi ) [[ $found = true ]] || plain '(none)' if [[ $pkg != 'pkgname='* ]]; then vcs_remove "$repo" "$tarch" "$pkg" fi done done for tarch in "${tarches[@]}"; do declare -n remove_pkgs="remove_pkgs_${tarch}" arch_repo_modify remove "${repo}" "${tarch}" "${remove_pkgs[@]}" repo_unlock "$repo" "$tarch" done