Introduce "db-functions-$VCS" which will eventually contain all VCS-specific code, and make this configurable in config. Move private arch_svn function and svn acl handling here, and introduce a new source_pkgbuild function to handle discovering PKGBUILDs from the configured VCS and sourcing them to extract metadata. The PKGBUILD is the only file we ever check out from version control, and only ever to scrape information from it, except for when we actually want to db-move a whole directory (which is by necessity considerably dependent on the VCS in use). source_pkgbuild is inspired by commits from the dbscripts rewrite, authored by Florian Pritz <bluewind@xinu.at> Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- config | 7 +++++-- db-functions | 50 +++++++++++++++--------------------------------- db-functions-svn | 27 ++++++++++++++++++++++++++ db-move | 5 +++-- db-remove | 5 ++--- db-update | 4 ++-- 6 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 db-functions-svn diff --git a/config b/config index fd79b6ee..1cfe11f4 100644 --- a/config +++ b/config @@ -1,14 +1,17 @@ #!/hint/bash FTP_BASE="/srv/ftp" -SVNREPO='' -SVNUSER='' PKGREPOS=() PKGPOOL='' SRCPOOL='' TESTING_REPO='' STABLE_REPOS=() +# VCS backend +VCS=svn +SVNREPO='' +SVNUSER='' + CLEANUP_DESTDIR="/var/tmp" CLEANUP_DRYRUN=false # Time in days to keep moved packages diff --git a/db-functions b/db-functions index 0491c22d..3757b726 100644 --- a/db-functions +++ b/db-functions @@ -39,11 +39,6 @@ mv_acl() { # set up general environment WORKDIR=$(mktemp -dt "${0##*/}.XXXXXXXXXX") -if [[ -n ${SVNUSER} ]]; then - setfacl -m u:"${SVNUSER}":rwx "${WORKDIR}" - setfacl -m d:u:"${USER}":rwx "${WORKDIR}" - setfacl -m d:u:"${SVNUSER}":rwx "${WORKDIR}" -fi LOCKS=() REPO_MODIFIED=0 @@ -306,27 +301,24 @@ check_pkgfile() { [[ ${pkgfile##*/} = "${pkgname}-${pkgver}-${pkgarch}"* ]] } -check_pkgsvn() { +# Check that the package file is consistent with the PKGBUILD in version control +check_pkgvcs() { local pkgfile="${1}" + local repo="${2}" local _pkgbase="$(getpkgbase "${pkgfile}")" || return 1 local _pkgname="$(getpkgname "${pkgfile}")" || return 1 local _pkgver="$(getpkgver "${pkgfile}")" || return 1 local _pkgarch="$(getpkgarch "${pkgfile}")" || return 1 - local repo="${2}" in_array "${repo}" "${PKGREPOS[@]}" || return 1 - if [[ ! -f ${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase} ]]; then - mkdir -p "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}" - arch_svn export -q "${SVNREPO}/${_pkgbase}/repos/${repo}-${_pkgarch}/PKGBUILD" \ - "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" >/dev/null || return 1 - fi + local vcsver vcsnames=() + read -rd'\n' vcsver vcsnames < <(source_pkgbuild "${_pkgbase}" "repos/${repo}-${_pkgarch}"; \ + get_full_version; echo "${pkgname[@]}") + read -ra vcsnames <<<"${vcsnames}" - local svnver="$(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; get_full_version)" - [[ "${svnver}" = "${_pkgver}" ]] || return 1 - - local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo "${pkgname[@]}")) - in_array "${_pkgname}" "${svnnames[@]}" || return 1 + [[ "${vcsver}" = "${_pkgver}" ]] || return 1 + in_array "${_pkgname}" "${vcsnames[@]}" || return 1 return 0 } @@ -337,7 +329,7 @@ check_splitpkgs() { local pkgfiles=("${@}") local pkgfile local pkgdir - local svnname + local vcsname mkdir -p "${WORKDIR}/check_splitpkgs/" pushd "${WORKDIR}/check_splitpkgs" >/dev/null @@ -350,22 +342,16 @@ check_splitpkgs() { mkdir -p "${repo}/${_pkgarch}/${_pkgbase}" echo "${_pkgname}" >> "${repo}/${_pkgarch}/${_pkgbase}/staging" - if [[ ! -f ${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase} ]]; then - mkdir -p "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}" - arch_svn export -q "${SVNREPO}/${_pkgbase}/repos/${repo}-${_pkgarch}/PKGBUILD" \ - "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" >/dev/null || return 1 - fi - - local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo "${pkgname[@]}")) - printf '%s\n' "${svnnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn" + local vcsnames=($(source_pkgbuild "${_pkgbase}" "repos/${repo}-${_pkgarch}"; echo "${pkgname[@]}")) + printf '%s\n' "${vcsnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/vcs" done popd >/dev/null for pkgdir in "${WORKDIR}/check_splitpkgs/${repo}"/*/*; do [[ ! -d ${pkgdir} ]] && continue sort -u "${pkgdir}/staging" -o "${pkgdir}/staging" - sort -u "${pkgdir}/svn" -o "${pkgdir}/svn" - if [[ ! -z "$(comm -13 "${pkgdir}/staging" "${pkgdir}/svn")" ]]; then + sort -u "${pkgdir}/vcs" -o "${pkgdir}/vcs" + if [[ ! -z "$(comm -13 "${pkgdir}/staging" "${pkgdir}/vcs")" ]]; then return 1 fi done @@ -458,10 +444,4 @@ arch_repo_modify() { REPO_MODIFIED=1 } -arch_svn() { - if [[ -z ${SVNUSER} ]]; then - /usr/bin/svn "${@}" - else - sudo -u "${SVNUSER}" -- /usr/bin/svn --username "${USER}" "${@}" - fi -} +. "$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")/db-functions-${VCS}" diff --git a/db-functions-svn b/db-functions-svn new file mode 100644 index 00000000..aa7952d8 --- /dev/null +++ b/db-functions-svn @@ -0,0 +1,27 @@ +#!/hint/bash + +if [[ -n ${SVNUSER} ]]; then + setfacl -m u:"${SVNUSER}":rwx "${WORKDIR}" + setfacl -m d:u:"${USER}":rwx "${WORKDIR}" + setfacl -m d:u:"${SVNUSER}":rwx "${WORKDIR}" +fi + +arch_svn() { + if [[ -z ${SVNUSER} ]]; then + /usr/bin/svn "${@}" + else + sudo -u "${SVNUSER}" -- /usr/bin/svn --username "${USER}" "${@}" + fi +} + +# source_pkgbuild pkgbase tag +# +# Source the PKGBUILD from the package's git/svn/whatever repo. +# Depending on how the VCS is used the tag might be "trunk" or "repos/$repo-$arch" +# or the full package version (epoch:pkgver-pkgrel) or any other recognized tag. +source_pkgbuild() { + local pkgbase="$1" + local tag="$2" + + . <(arch_svn cat "${SVNREPO}/${pkgbase}/${tag}/PKGBUILD" 2>/dev/null || echo "false") +} diff --git a/db-move b/db-move index b6448898..2a1da68d 100755 --- a/db-move +++ b/db-move @@ -77,8 +77,9 @@ for pkgbase in "${args[@]:2}"; do tarches=("${pkgarch}") fi msg2 "%s (%s)" "$pkgbase" "${tarches[*]}" - pkgnames=($(. "${svnrepo_from}/PKGBUILD"; echo "${pkgname[@]}")) - pkgver=$(. "${svnrepo_from}/PKGBUILD"; get_full_version) + read -rd'\n' pkgver pkgnames < <(source_pkgbuild "${pkgbase}" "repos/${repo_from}-${pkgarch}"; \ + get_full_version; echo "${pkgname[@]}") + read -ra pkgnames <<<"$pkgnames" if [[ -d ${svnrepo_to} ]]; then for file in $(arch_svn ls "${svnrepo_to}"); do diff --git a/db-remove b/db-remove index ac9a1688..b794edc2 100755 --- a/db-remove +++ b/db-remove @@ -32,10 +32,9 @@ done remove_pkgs=() for pkgbase in "${pkgbases[@]}"; do msg "Removing %s from [%s]..." "$pkgbase" "$repo" - arch_svn checkout -q "${SVNREPO}/${pkgbase}" "${WORKDIR}/svn/${pkgbase}" >/dev/null - if [[ -d ${WORKDIR}/svn/$pkgbase/repos/$svnrepo ]]; then - remove_pkgs+=($(. "${WORKDIR}/svn/$pkgbase/repos/$svnrepo/PKGBUILD"; echo ${pkgname[@]})) + if remove_pkgs+=($(. source_pkgbuild "${pkgbase}" "repos/${svnrepo}" && echo ${pkgname[@]})); then + arch_svn checkout -q "${SVNREPO}/${pkgbase}" "${WORKDIR}/svn/${pkgbase}" >/dev/null arch_svn rm --force -q "${WORKDIR}/svn/$pkgbase/repos/$svnrepo" arch_svn commit -q "${WORKDIR}/svn/$pkgbase" -m "${0##*/}: $pkgbase removed by $(id -un)" else diff --git a/db-update b/db-update index 8eb27dfe..313fb999 100755 --- a/db-update +++ b/db-update @@ -46,8 +46,8 @@ for repo in "${repos[@]}"; do if ! pacman-key -v "${pkg}.sig" >/dev/null 2>&1; then die "Package %s does not have a valid signature" "$repo/${pkg##*/}" fi - if ! check_pkgsvn "${pkg}" "${repo}"; then - die "Package %s is not consistent with svn repository" "$repo/${pkg##*/}" + if ! check_pkgvcs "${pkg}" "${repo}"; then + die "Package %s is not consistent with %s repository" "$repo/${pkg##*/}" "${VCS}" fi if ! check_pkgrepos "${pkg}"; then die "Package %s already exists in another repository" "$repo/${pkg##*/}" -- 2.18.0