#!/bin/bash . "$(dirname "$(readlink -e "$0")")/config" . "$(dirname "$(readlink -e "$0")")/db-functions" if (( $# < 3 )); then msg "usage: %s ..." "${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 # check if packages to be moved exist in svn and ftp dir arch_svn checkout -q -N "${SVNREPO}" "${WORKDIR}/svn" >/dev/null for pkgbase in "${args[@]:2}"; do arch_svn up -q "${WORKDIR}/svn/${pkgbase}" >/dev/null found=false for tarch in "${ARCHES[@]}"; do while read -r pkgarch pkgfile; do svnrepo_from="${WORKDIR}/svn/${pkgbase}/repos/${repo_from}-${pkgarch}" if ! [[ -r ${svnrepo_from}/PKGBUILD ]]; then die "%s not found in %s-%s" "$pkgbase" "$repo_from" "$pkgarch" fi # getpkgfile will `exit` for us if it fails; # no need to check its result getpkgfile "${ftppath_from}/${tarch}/${pkgfile}" >/dev/null found=true done < <(arch_expac_pkgbase "$repo_from" "$tarch" '%a %f' "$pkgbase") 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 remove_pkgs_$arch done for pkgbase in "${args[@]:2}"; do tag_list="" for tarch in "${ARCHES[@]}"; do while read -r pkgname pkgver pkgarch pkgfile; do svnrepo_from="${WORKDIR}/svn/${pkgbase}/repos/${repo_from}-${pkgarch}" svnrepo_to="${WORKDIR}/svn/${pkgbase}/repos/${repo_to}-${pkgarch}" if [[ -f ${svnrepo_from}/PKGBUILD ]]; then msg2 "%s (%s)" "$pkgbase" "$pkgarch" if [[ -d ${svnrepo_to} ]]; then for file in $(arch_svn ls "${svnrepo_to}"); do arch_svn rm -q "${svnrepo_to}/$file@" done else mkdir "${svnrepo_to}" arch_svn add -q "${svnrepo_to}" fi for file in $(arch_svn ls "${svnrepo_from}"); do arch_svn mv -q -r HEAD "${svnrepo_from}/$file@" "${svnrepo_to}/" done arch_svn rm --force -q "${svnrepo_from}" tag_list+=", $pkgarch" fi declare -n add_pkgs="add_pkgs_${tarch}" declare -n remove_pkgs="remove_pkgs_${tarch}" 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+=("${FTP_BASE}/${PKGPOOL}/${pkgfile}") remove_pkgs+=("${pkgname}") done < <(arch_expac_pkgbase "$repo_from" "$tarch" '%n %v %a %f' "$pkgbase") done tag_list="${tag_list#, }" arch_svn commit -q "${WORKDIR}/svn/${pkgbase}" -m "${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 remove_pkgs="remove_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 done for pkgarch in "${ARCHES[@]}"; do repo_unlock "${repo_from}" "${pkgarch}" repo_unlock "${repo_to}" "${pkgarch}" done