diff options
author | coadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu> | 2015-08-26 03:33:26 -0300 |
---|---|---|
committer | coadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu> | 2015-08-26 03:33:26 -0300 |
commit | 8eafe04ec5eaf917d9e2d58993604c454f1a26d1 (patch) | |
tree | c0e9bb91659c3a1f5814ba94ee251639b52c5873 /extra/coadde/db-move | |
parent | f17c9169de91036cd4b9bb725d2cc6713ad06ce5 (diff) |
re-estructure dbscrips
Diffstat (limited to 'extra/coadde/db-move')
-rwxr-xr-x | extra/coadde/db-move | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/extra/coadde/db-move b/extra/coadde/db-move new file mode 100755 index 0000000..275a11a --- /dev/null +++ b/extra/coadde/db-move @@ -0,0 +1,106 @@ +#!/bin/bash + +. "$(dirname "$(readlink -e "$0")")/config" +. "$(dirname "$(readlink -e "$0")")/db-functions" + +if [ $# -lt 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_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 %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 + +# First loop is to check that all necessary files exist +for pkgbase in "${args[@]:2}"; do + for pkgarch in "${ARCHES[@]}" 'any'; do + xbsrepo_from="$(xbs releasepath "${pkgbase}" "${repo_from}" "${pkgarch}")" + if [ -r "${xbsrepo_from}/PKGBUILD" ]; then + pkgnames=($(. "${xbsrepo_from}/PKGBUILD"; echo "${pkgname[@]}")) + if [ ${#pkgnames[@]} -lt 1 ]; then + die "Could not read pkgname" + fi + + pkgver=$(. "${xbsrepo_from}/PKGBUILD"; get_full_version "${epoch:-0}" "${pkgver}" "${pkgrel}") + if [ -z "${pkgver}" ]; then + die "Could not read pkgver" + fi + + if [ "${pkgarch}" == 'any' ]; then + tarches=("${ARCHES[@]}") + else + tarches=("${pkgarch}") + fi + + for pkgname in "${pkgnames[@]}"; do + for tarch in "${tarches[@]}"; do + getpkgfile "${ftppath_from}/${tarch}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT} >/dev/null + done + done + continue 2 + fi + done + die "%s not found in %s" "${pkgbase}" "${repo_from}" +done + +msg "Moving packages from [%s] to [%s]..." "${repo_from}" "${repo_to}" + +declare -A add_pkgs +declare -A remove_pkgs +for pkgbase in "${args[@]:2}"; do + # move the package in xbs + arches=($(xbs move "${repo_from}" "${repo_to}" "${pkgbase}")) + # move the package in ftp + for pkgarch in "${arches[@]}"; do + xbsrepo_to="$(xbs releasepath "$pkgbase" "$repo_to" "$pkgarch")" + if true; then # to add an indent level to make merging easier + if [ "${pkgarch}" == 'any' ]; then + tarches=("${ARCHES[@]}") + else + tarches=("${pkgarch}") + fi + msg2 '%s (%s)' "${pkgbase}" "${tarches[*]}" + pkgnames=($(. "${xbsrepo_to}/PKGBUILD"; echo "${pkgname[@]}")) + pkgver=$(. "${xbsrepo_to}/PKGBUILD"; get_full_version "${epoch:-0}" "${pkgver}" "${pkgrel}") + + for pkgname in "${pkgnames[@]}"; do + for tarch in "${tarches[@]}"; do + pkgpath=$(getpkgfile "${ftppath_from}/${tarch}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT}) + pkgfile="${pkgpath##*/}" + + ln -s "../../../${PKGPOOL}/${pkgfile}" "${ftppath_to}/${tarch}/" + if [ -f "${FTP_BASE}/${PKGPOOL}/${pkgfile}.sig" ]; then + ln -s "../../../${PKGPOOL}/${pkgfile}.sig" "${ftppath_to}/${tarch}/" + fi + add_pkgs[${tarch}]+="${FTP_BASE}/${PKGPOOL}/${pkgfile} " + remove_pkgs[${tarch}]+="${pkgname} " + done + done + fi + done +done + +for tarch in "${ARCHES[@]}"; do + if [ -n "${add_pkgs[${tarch}]}" ]; then + arch_repo_add "${repo_to}" "${tarch}" ${add_pkgs[${tarch}]} + arch_repo_remove "${repo_from}" "${tarch}" ${remove_pkgs[${tarch}]} + fi +done + +for pkgarch in "${ARCHES[@]}"; do + repo_unlock "${repo_from}" "${pkgarch}" + repo_unlock "${repo_to}" "${pkgarch}" +done |