db-move 5.35 KB
Newer Older
Aaron Griffin's avatar
Aaron Griffin committed
1
2
#!/bin/bash

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

Eli Schwartz's avatar
Eli Schwartz committed
6
if (( $# < 3 )); then
7
	msg "usage: %s <repo-from> <repo-to> <pkgname|pkgbase> ..." "${0##*/}"
8
	exit 1
Pierre Schmitz's avatar
Pierre Schmitz committed
9
fi
Aaron Griffin's avatar
Aaron Griffin committed
10

11
args=("${@}")
12
13
14
repo_from="${args[0]}"
repo_to="${args[1]}"
ftppath_from="${FTP_BASE}/${repo_from}/os/"
15
ftppath_debug_from="${FTP_BASE}/${repo_from}-debug/os/"
16
ftppath_to="${FTP_BASE}/${repo_to}/os/"
17
ftppath_debug_to="${FTP_BASE}/${repo_to}-debug/os/"
Aaron Griffin's avatar
Aaron Griffin committed
18

19
20
21
22
23
check_leapfrog=false
if in_array "${repo_from}" "${STAGING_REPOS[@]}" && in_array "${repo_to}" "${STABLE_REPOS[@]}"; then
	check_leapfrog=true
fi

24
if ! check_repo_configured "$repo_from"; then
25
	die "%s is not a valid repository for %s" "$repo_from" "$0"
26
elif ! check_repo_configured "$repo_to"; then
27
	die "%s is not a valid repository for %s" "$repo_to" "$0"
28
29
fi

30
if ! check_repo_permission "$repo_to" || ! check_repo_permission "$repo_from"; then
31
	die "You don't have permission to move packages from %s to %s" "$repo_from" "$repo_to"
32
33
fi

Pierre Schmitz's avatar
Pierre Schmitz committed
34
# TODO: this might lock too much (architectures)
35
36
37
for pkgarch in "${ARCHES[@]}"; do
	repo_lock "${repo_to}" "${pkgarch}" || exit 1
	repo_lock "${repo_from}" "${pkgarch}" || exit 1
Pierre Schmitz's avatar
Pierre Schmitz committed
38
39
done

40
# check if packages to be moved exist in version control and ftp dir
41
for pkgbase in "${args[@]:2}"; do
42
43
44
45
46
47
48
49
	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"

Eli Schwartz's avatar
Eli Schwartz committed
50
			if (( ${#pkgnames[@]} < 1 )); then
51
52
53
				die "Could not read pkgname"
			fi

Eli Schwartz's avatar
Eli Schwartz committed
54
			if [[ -z ${pkgver} ]]; then
55
56
57
				die "Could not read pkgver"
			fi

58
			if [[ ${check_leapfrog} = true ]] && leapfrog=$(find_repo_for_package "${pkgbase}" "${pkgarch}" "${TESTING_REPOS[@]}"); then
Felix Yan's avatar
Felix Yan committed
59
				die "Package %s cannot be moved from %s to %s while it exists in %s" "${pkgbase}" "${repo_from}" "${repo_to}" "${leapfrog}"
60
61
			fi

62
			for pkgname in "${pkgnames[@]}"; do
63
				getpkgfile "${ftppath_from}/${pkgarch}/${pkgname}-${pkgver}-${vcsrepo_from##*-}"${PKGEXTS} >/dev/null
Pierre Schmitz's avatar
Pierre Schmitz committed
64
			done
65
			found=true
66
67
68
			continue 2
		fi
	done
69
	[[ ${found} = true ]] || die "%s not found in %s" "$pkgbase" "$repo_from"
70
71
done

72
msg "Moving packages from [%s] to [%s]..." "$repo_from" "$repo_to"
Aaron Griffin's avatar
Aaron Griffin committed
73

74
75
for arch in "${ARCHES[@]}"; do
	declare -a add_pkgs_$arch
Eli Schwartz's avatar
Eli Schwartz committed
76
	declare -a add_debug_pkgs_$arch
77
	declare -a remove_pkgs_$arch
Eli Schwartz's avatar
Eli Schwartz committed
78
	declare -a remove_debug_pkgs_$arch
79
done
80
for pkgbase in "${args[@]:2}"; do
81
	tag_list=""
82
	for pkgarch in "${ARCHES[@]}" 'any'; do
83
		vcsrepo_from=$(find_repo_for_package "${pkgbase}" "${pkgarch}" "${repo_from}")
Pierre Schmitz's avatar
Pierre Schmitz committed
84

85
		if [[ ${vcsrepo_from} = ${repo_from}-${pkgarch} ]]; then
Eli Schwartz's avatar
Eli Schwartz committed
86
			if [[ ${pkgarch} = any ]]; then
87
				tarches=("${ARCHES[@]}")
88
89
90
			else
				tarches=("${pkgarch}")
			fi
91
			msg2 "%s (%s)" "$pkgbase" "${tarches[*]}"
92
93
94
			read -rd'\n' pkgver pkgnames < <(source_pkgbuild "${pkgbase}" "repos/${repo_from}-${pkgarch}"; \
			    get_full_version; echo "${pkgname[@]}")
			read -ra pkgnames <<<"$pkgnames"
95

96
			vcs_move_package "${pkgbase}" "${repo_from}-${pkgarch}" "${repo_to}-${pkgarch}"
97
			tag_list+=", $pkgarch"
98

99
100
			for tarch in "${tarches[@]}"; do
				declare -n add_pkgs="add_pkgs_${tarch}"
Eli Schwartz's avatar
Eli Schwartz committed
101
				declare -n add_debug_pkgs="add_debug_pkgs_${tarch}"
102
				declare -n remove_pkgs="remove_pkgs_${tarch}"
Eli Schwartz's avatar
Eli Schwartz committed
103
				declare -n remove_debug_pkgs="remove_debug_pkgs_${tarch}"
104
				for pkgname in "${pkgnames[@]}"; do
105
					pkgpath=$(getpkgfile "${ftppath_from}/${tarch}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXTS})
Pierre Schmitz's avatar
Pierre Schmitz committed
106
					pkgfile="${pkgpath##*/}"
107

108
					ln -s "../../../${PKGPOOL}/${pkgfile}" "${ftppath_to}/${tarch}/"
Eli Schwartz's avatar
Eli Schwartz committed
109
					if [[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile}.sig ]]; then
110
						ln -s "../../../${PKGPOOL}/${pkgfile}.sig" "${ftppath_to}/${tarch}/"
111
					fi
112
113
					add_pkgs+=("${FTP_BASE}/${PKGPOOL}/${pkgfile}")
					remove_pkgs+=("${pkgname}")
114
				done
115
116
117
				debug_pkgpath=$(getpkgfile "${ftppath_debug_from}/${tarch}/${pkgbase}-debug-${pkgver}-${pkgarch}"${PKGEXTS})
				debug_pkgfile="${debug_pkgpath##*/}"
				if [[ -f ${debug_pkgpath} ]]; then
118
					msg2 "Found debug package %s (%s)" "${pkgbase}-debug" "${tarch}"
119
120
121
122
123
124
125
					ln -s "../../../${DEBUGPKGPOOL}/${debug_pkgfile}" "${ftppath_debug_to}/${tarch}/"
					if [[ -f ${FTP_BASE}/${DEBUGPKGPOOL}/${debug_pkgfile}.sig ]]; then
						ln -s "../../../${DEBUGPKGPOOL}/${debug_pkgfile}.sig" "${ftppath_debug_to}/${tarch}/"
					fi
					add_debug_pkgs+=("${FTP_BASE}/${DEBUGPKGPOOL}/${debug_pkgfile}")
					remove_debug_pkgs+=("${pkgbase}-debug")
				fi
126
			done
127
128
		fi
	done
129
	tag_list="${tag_list#, }"
130
	vcs_commit "${0##*/}: moved ${pkgbase} from [${repo_from}] to [${repo_to}] (${tag_list})"
131
done
Pierre Schmitz's avatar
Pierre Schmitz committed
132

133
for tarch in "${ARCHES[@]}"; do
134
	declare -n add_pkgs="add_pkgs_${tarch}"
135
	declare -n add_debug_pkgs="add_debug_pkgs_${tarch}"
136
	declare -n remove_pkgs="remove_pkgs_${tarch}"
137
	declare -n remove_debug_pkgs="remove_debug_pkgs_${tarch}"
138
	if [[ -n ${add_pkgs[*]} ]]; then
139
140
		arch_repo_modify add "${repo_to}" "${tarch}" "${add_pkgs[@]}"
		arch_repo_modify remove "${repo_from}" "${tarch}" "${remove_pkgs[@]}"
141
	fi
Morten Linderud's avatar
Morten Linderud committed
142
	if [[ -n ${add_debug_pkgs[*]} ]]; then
143
144
145
		arch_repo_modify add "${repo_to}-debug" "${tarch}" "${add_debug_pkgs[@]}"
		arch_repo_modify remove "${repo_from}-debug" "${tarch}" "${remove_debug_pkgs[@]}"
	fi
146
done
Pierre Schmitz's avatar
Pierre Schmitz committed
147

148
149
150
for pkgarch in "${ARCHES[@]}"; do
	repo_unlock "${repo_from}" "${pkgarch}"
	repo_unlock "${repo_to}" "${pkgarch}"
151
done