summaryrefslogtreecommitdiff
path: root/db-remove
blob: 4e1003f45d2412309545db9aa8d88923d31add28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

. "$(dirname "$(readlink -e "$0")")/config"
. "$(dirname "$(readlink -e "$0")")/db-functions"

if (( $# < 3 )); then
	msg "usage: %s <repo> <arch> <pkgbase> ..." "${0##*/}"
	msg "   or: %s <repo> <arch> pkgname=<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