summaryrefslogtreecommitdiffstats
path: root/db-move
blob: 1a69383881633182bdca370d725cfb441d123f87 (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
#!/bin/bash

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

if [ $# -lt 3 ]; then
	msg "usage: ${0##*/} <repo-from> <repo-to> <arch> <pkgname> ..."
	exit 1
fi

args=(${@})
repo_from="${args[0]}"
repo_to="${args[1]}"
arch="${args[2]}"
pkgnames=("${args[@]:3}")
ftppath_from="${FTP_BASE}/${repo_from}/os/"
ftppath_to="${FTP_BASE}/${repo_to}/os/"

if ! check_repo_permission $repo_to || ! check_repo_permission $repo_from; then
	die "You don't have permission to move packages from ${repo_from} to ${repo_to}"
fi

# TODO: this might lock too much (architectures)
for pkgarch in ${ARCHES[@]}; do
	repo_lock ${repo_to} ${pkgarch} || exit 1
	repo_lock ${repo_from} ${pkgarch} || exit 1
done

msg "Moving packages from [${repo_from}] to [${repo_to}]..."

for pkgname in "${pkgnames[@]}"; do
	pkgentry=$(pkgentry_from_db "$repo_from" "$arch" "$pkgname")
	pkgs=($(getpkgfiles "$ftppath_from$arch/$pkgentry"*${PKGEXT}))

	if [[ -z $pkgentry ]]; then
		warning "Failed to detect pkgentry for $pkgname"
		continue
	fi

	for pkg in "${pkgs[@]}"; do
		pkgname=$(getpkgname "$pkg")
		arch_db_add "${repo_to}" "$arch" "${pkg##*/}"
		arch_db_remove "${repo_from}" "$arch" "$pkgname"
	done
done

arch_history_commit "db-move: $repo_from -> $repo_to: ${pkgnames[@]}"

for pkgarch in ${ARCHES[@]}; do
	repo_unlock ${repo_from} ${pkgarch}
	repo_unlock ${repo_to} ${pkgarch}
done