-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb-move
More file actions
executable file
·92 lines (73 loc) · 2.57 KB
/
db-move
File metadata and controls
executable file
·92 lines (73 loc) · 2.57 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/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}")
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
if ! in_array "$arch" "${ARCHES[@]}" "all"; then
die "Invalid arch '$arch'"
fi
if [[ $arch == "all" ]]; then
arches=(${ARCHES[@]})
else
arches=($arch)
fi
for pkgarch in ${arches[@]}; do
repo_lock ${repo_to} ${pkgarch} || exit 1
repo_lock ${repo_from} ${pkgarch} || exit 1
repo_lock ${repo_to}-${DEBUGSUFFIX} ${pkgarch} || exit 1
repo_lock ${repo_from}-${DEBUGSUFFIX} ${pkgarch} || exit 1
done
msg "Moving packages from [${repo_from}] to [${repo_to}]..."
declare -a pkgs_to_remove
for arch in ${arches[@]}; do
for pkgname in "${pkgnames[@]}"; do
msg2 "$arch\t$pkgname"
for pkg in $(find_removed_split_packages "${repo_from}" "${repo_to}" "${arch}" "${pkgname}"); do
pkgentry=$(pkgentry_from_db "${repo_to}" "${arch}" "${pkg}")
pkgarch=$(getpkgarch $(getpkgfile "${FTP_BASE}/${repo_to}/os/${arch}/${pkgentry}"*${PKGEXT}))
if [[ ${pkgarch} == any ]]; then
msg2 "any\t${pkg}\t[removal]"
for _arch in ${ARCHES[@]}; do
pkgs_to_remove+=(${pkg}/${_arch})
done
else
msg2 "${arch}\t${pkg}\t[removal]"
pkgs_to_remove+=(${pkg}/${pkgarch})
fi
done
arch_db_move "${repo_from}" "${repo_to}" "${arch}" "${pkgname}"
if [[ -f "${HISTORYREPO}/${repo_from}-${DEBUGSUFFIX}/${arch}/${pkgname}-${DEBUGSUFFIX}" ]]; then
arch_db_move "${repo_from}-${DEBUGSUFFIX}" "${repo_to}-${DEBUGSUFFIX}" \
"${arch}" "${pkgname}-${DEBUGSUFFIX}"
fi
done
done
# TODO: assumes all packages are in the same repo, might not be the case
if [[ ${#pkgs_to_remove[@]} > 0 ]]; then
pkgs_to_remove=($(dedup_array ${pkgs_to_remove[@]}))
for pkgname in ${pkgs_to_remove[@]}; do
pkgarch=${pkgname#*/}
pkgname=${pkgname%/*}
arch_db_remove "${repo_to}" "${pkgarch}" "${pkgname}"
if [[ -f "${HISTORYREPO}/${repo_to}-${DEBUGSUFFIX}/${arch}/${pkgname}-${DEBUGSUFFIX}" ]]; then
arch_db_remove "${repo_to}-${DEBUGSUFFIX}" "${pkgarch}" "${pkgname}-${DEBUGSUFFIX}"
fi
done
fi
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}
repo_unlock ${repo_from}-${DEBUGSUFFIX} ${pkgarch}
repo_unlock ${repo_to}-${DEBUGSUFFIX} ${pkgarch}
done