-
Notifications
You must be signed in to change notification settings - Fork 15
/
db-move
executable file
·152 lines (131 loc) · 5.34 KB
/
db-move
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
. "$(dirname "$(readlink -e "$0")")/config"
. "$(dirname "$(readlink -e "$0")")/db-functions"
if (( $# < 3 )); then
msg "usage: %s <repo-from> <repo-to> <pkgname|pkgbase> ..." "${0##*/}"
exit 1
fi
args=("${@}")
repo_from="${args[0]}"
repo_to="${args[1]}"
ftppath_from="${FTP_BASE}/${repo_from}/os/"
ftppath_debug_from="${FTP_BASE}/${repo_from}-debug/os/"
ftppath_to="${FTP_BASE}/${repo_to}/os/"
ftppath_debug_to="${FTP_BASE}/${repo_to}-debug/os/"
check_leapfrog=false
if in_array "${repo_from}" "${STAGING_REPOS[@]}" && in_array "${repo_to}" "${STABLE_REPOS[@]}"; then
check_leapfrog=true
fi
if ! check_repo_configured "$repo_from"; then
die "%s is not a valid repository for %s" "$repo_from" "$0"
elif ! check_repo_configured "$repo_to"; then
die "%s is not a valid repository for %s" "$repo_to" "$0"
fi
if ! check_repo_permission "$repo_to" || ! check_repo_permission "$repo_from"; then
die "You don't have permission to move packages from %s to %s" "$repo_from" "$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
# check if packages to be moved exist in version control and ftp dir
for pkgbase in "${args[@]:2}"; do
found=false
for pkgarch in "${ARCHES[@]}"; do
if vcsrepo_from=$(find_repo_for_package "${pkgbase}" "${pkgarch}" "${repo_from}"); then
#FIXME: abort if PKGBUILD not there
read -rd'\n' pkgver pkgnames < <(source_pkgbuild "${pkgbase}" "repos/${vcsrepo_from}"; \
get_full_version; echo "${pkgname[@]}")
read -ra pkgnames <<<"$pkgnames"
if (( ${#pkgnames[@]} < 1 )); then
die "Could not read pkgname"
fi
if [[ -z ${pkgver} ]]; then
die "Could not read pkgver"
fi
if [[ ${check_leapfrog} = true ]] && leapfrog=$(find_repo_for_package "${pkgbase}" "${pkgarch}" "${TESTING_REPOS[@]}"); then
die "Package %s cannot be moved from %s to %s while it exists in %s" "${pkgbase}" "${repo_from}" "${repo_to}" "${leapfrog}"
fi
for pkgname in "${pkgnames[@]}"; do
getpkgfile "${ftppath_from}/${pkgarch}/${pkgname}-${pkgver}-${vcsrepo_from##*-}"${PKGEXTS} >/dev/null
done
found=true
continue 2
fi
done
[[ ${found} = true ]] || die "%s not found in %s" "$pkgbase" "$repo_from"
done
msg "Moving packages from [%s] to [%s]..." "$repo_from" "$repo_to"
for arch in "${ARCHES[@]}"; do
declare -a add_pkgs_$arch
declare -a add_debug_pkgs_$arch
declare -a remove_pkgs_$arch
declare -a remove_debug_pkgs_$arch
done
for pkgbase in "${args[@]:2}"; do
tag_list=""
for pkgarch in "${ARCHES[@]}" 'any'; do
vcsrepo_from=$(find_repo_for_package "${pkgbase}" "${pkgarch}" "${repo_from}")
if [[ ${vcsrepo_from} = ${repo_from}-${pkgarch} ]]; then
if [[ ${pkgarch} = any ]]; then
tarches=("${ARCHES[@]}")
else
tarches=("${pkgarch}")
fi
msg2 "%s (%s)" "$pkgbase" "${tarches[*]}"
read -rd'\n' pkgver pkgnames < <(source_pkgbuild "${pkgbase}" "repos/${repo_from}-${pkgarch}"; \
get_full_version; echo "${pkgname[@]}")
read -ra pkgnames <<<"$pkgnames"
vcs_move_package "${pkgbase}" "${repo_from}-${pkgarch}" "${repo_to}-${pkgarch}"
tag_list+=", $pkgarch"
for tarch in "${tarches[@]}"; do
declare -n add_pkgs="add_pkgs_${tarch}"
declare -n add_debug_pkgs="add_debug_pkgs_${tarch}"
declare -n remove_pkgs="remove_pkgs_${tarch}"
declare -n remove_debug_pkgs="remove_debug_pkgs_${tarch}"
for pkgname in "${pkgnames[@]}"; do
pkgpath=$(getpkgfile "${ftppath_from}/${tarch}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXTS})
pkgfile="${pkgpath##*/}"
ln -sf "../../../${PKGPOOL}/${pkgfile}" "${ftppath_to}/${tarch}/"
if [[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile}.sig ]]; then
ln -sf "../../../${PKGPOOL}/${pkgfile}.sig" "${ftppath_to}/${tarch}/"
fi
add_pkgs+=("${FTP_BASE}/${PKGPOOL}/${pkgfile}")
remove_pkgs+=("${pkgname}")
done
if ! debug_pkgpath=$(maybe_getpkgfile "${ftppath_debug_from}/${tarch}/${pkgbase}-debug-${pkgver}-${pkgarch}"${PKGEXTS}); then
continue
fi
debug_pkgfile="${debug_pkgpath##*/}"
msg2 "Found debug package %s (%s)" "${pkgbase}-debug" "${tarch}"
ln -sf "../../../${DEBUGPKGPOOL}/${debug_pkgfile}" "${ftppath_debug_to}/${tarch}/"
if [[ -f ${FTP_BASE}/${DEBUGPKGPOOL}/${debug_pkgfile}.sig ]]; then
ln -sf "../../../${DEBUGPKGPOOL}/${debug_pkgfile}.sig" "${ftppath_debug_to}/${tarch}/"
fi
add_debug_pkgs+=("${FTP_BASE}/${DEBUGPKGPOOL}/${debug_pkgfile}")
remove_debug_pkgs+=("${pkgbase}-debug")
done
fi
done
tag_list="${tag_list#, }"
vcs_commit "${0##*/}: moved ${pkgbase} from [${repo_from}] to [${repo_to}] (${tag_list})"
done
for tarch in "${ARCHES[@]}"; do
declare -n add_pkgs="add_pkgs_${tarch}"
declare -n add_debug_pkgs="add_debug_pkgs_${tarch}"
declare -n remove_pkgs="remove_pkgs_${tarch}"
declare -n remove_debug_pkgs="remove_debug_pkgs_${tarch}"
if [[ -n ${add_pkgs[*]} ]]; then
arch_repo_modify add "${repo_to}" "${tarch}" "${add_pkgs[@]}"
arch_repo_modify remove "${repo_from}" "${tarch}" "${remove_pkgs[@]}"
fi
if [[ -n ${add_debug_pkgs[*]} ]]; then
arch_repo_modify add "${repo_to}-debug" "${tarch}" "${add_debug_pkgs[@]}"
arch_repo_modify remove "${repo_from}-debug" "${tarch}" "${remove_debug_pkgs[@]}"
fi
done
for pkgarch in "${ARCHES[@]}"; do
repo_unlock "${repo_from}" "${pkgarch}"
repo_unlock "${repo_to}" "${pkgarch}"
done