From bdc95e2d741b95172eaaf119fbb111a3d500809d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Ismael=20Haase=20Hern=C3=A1ndez?= Date: Sat, 16 Apr 2011 11:57:47 -0700 Subject: Dbscripts on stable too --- cron-jobs/sourceballs2 | 87 ++++++++++++++++++++++++++++++++++++ db-move | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ db-remove | 46 +++++++++++++++++++ db-repo-add | 39 +++++++++++++++++ db-repo-remove | 36 +++++++++++++++ 5 files changed, 325 insertions(+) create mode 100755 cron-jobs/sourceballs2 create mode 100755 db-move create mode 100755 db-remove create mode 100755 db-repo-add create mode 100755 db-repo-remove diff --git a/cron-jobs/sourceballs2 b/cron-jobs/sourceballs2 new file mode 100755 index 0000000..452208e --- /dev/null +++ b/cron-jobs/sourceballs2 @@ -0,0 +1,87 @@ +#!/bin/bash + +dirname="$(dirname $(readlink -e $0))" +. "${dirname}/../db-functions" +. "${dirname}/../config" +. "${MAKEPKGCONF}" + +pushd "${WORKDIR}" >/dev/null + +script_lock + +#adjust the nice level to run at a lower priority +renice +10 -p $$ > /dev/null + +# Create a list of all available source package file names +find "${ARCH_BASE}/${SRCPOOL}" -xtype f -name "*${SRCEXT}" -printf '%f\n' | sort -u > "${WORKDIR}/available-src-pkgs" + +# Steps +# Traverse the ABSLibre +# Makepkg --allsource every package +# Remove the old packages +pushd "${SVNREPO}" >/dev/null + +failedpkgs=() +for repo in ${PKGREPOS[@]}; do + pushd $repo >/dev/null + find . -maxdepth 1 -type d | while read pkg; do + pushd "${SVNREPO}/$repo/$pkg" >/dev/null + + [[ ! -e PKGBUILD ]] && { + warning "$repo/$pkg is not a package" + continue + } + + unset pkgbase pkgname + source PKGBUILD + pkgbase=${pkgbase:-$pkgname} + + echo "${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" >> "${WORKDIR}/expected-src-pkgs" + + # Skip already sourceballed + [[ -e "${SRCPKGDEST}/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" ]] && \ + continue + + makepkg --allsource --ignorearch -c >/dev/null 2>&1 + + [[ $? -ne 0 ]] && \ + failedpkgs[${#failedpkgs[*]}]="${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" + + done + popd >/dev/null +done + +# Cleanup old source packages +cat "${WORKDIR}/expected-src-pkgs" | sort -u > "${WORKDIR}/expected-src-pkgs.sort" +cat "${WORKDIR}/available-src-pkgs" | sort -u > "${WORKDIR}/available-src-pkgs.sort" +old_pkgs=($(comm -23 "${WORKDIR}/available-src-pkgs.sort" "${WORKDIR}/expected-src-pkgs.sort")) + +if [ ${#old_pkgs[@]} -ge 1 ]; then + msg "Removing old source packages..." + ${SOURCE_CLEANUP_DRYRUN} && warning 'dry run mode is active' + for old_pkg in ${old_pkgs[@]}; do + msg2 "${old_pkg}" + if ! ${SOURCE_CLEANUP_DRYRUN}; then + mv "$ARCH_BASE/${SRCPOOL}/${old_pkg}" "${SOURCE_CLEANUP_DESTDIR}" + touch "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" + fi + done +fi + +old_pkgs=($(find ${SOURCE_CLEANUP_DESTDIR} -type f -name "*${SRCEXT}" -mtime +${SOURCE_CLEANUP_KEEP} -printf '%f\n')) +if [ ${#old_pkgs[@]} -ge 1 ]; then + msg "Removing old source packages from the cleanup directory..." + for old_pkg in ${old_pkgs[@]}; do + msg2 "${old_pkg}" + ${SOURCE_CLEANUP_DRYRUN} || rm -f "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" + done +fi + +msg "Failed" +for _fail in ${failedpkgs[@]}; do + msg2 "$_fail" +done + + +script_unlock + diff --git a/db-move b/db-move new file mode 100755 index 0000000..ae21781 --- /dev/null +++ b/db-move @@ -0,0 +1,117 @@ +#!/bin/bash + +. "$(dirname $0)/db-functions" +. "$(dirname $0)/config" + +if [ $# -lt 3 ]; then + msg "usage: $(basename $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 ${repo_from} to ${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 +/usr/bin/svn checkout -q -N "${SVNREPO}" "${WORKDIR}/svn" >/dev/null +for pkgbase in ${args[@]:2}; do + /usr/bin/svn up -q "${WORKDIR}/svn/${pkgbase}" >/dev/null + for pkgarch in ${ARCHES[@]} 'any'; do + svnrepo_from="${WORKDIR}/svn/${pkgbase}/repos/${repo_from}-${pkgarch}" + if [ -r "${svnrepo_from}/PKGBUILD" ]; then + pkgnames=($(. "${svnrepo_from}/PKGBUILD"; echo ${pkgname[@]})) + if [ ${#pkgnames[@]} -lt 1 ]; then + die "Could not read pkgname" + fi + + pkgver=$(. "${svnrepo_from}/PKGBUILD"; echo "${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 "${pkgbase} not found in ${repo_from}" +done + +msg "Moving packages from [${repo_from}] to [${repo_to}]..." + +declare -A add_pkgs +declare -A remove_pkgs +for pkgbase in ${args[@]:2}; do + for pkgarch in ${ARCHES[@]} 'any'; 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 + if [ "${pkgarch}" == 'any' ]; then + tarches=(${ARCHES[@]}) + else + tarches=("${pkgarch}") + fi + msg2 "${pkgbase} ($(echo ${tarches[@]}))" + pkgnames=($(. "${svnrepo_from}/PKGBUILD"; echo ${pkgname[@]})) + pkgver=$(. "${svnrepo_from}/PKGBUILD"; echo "${pkgver}-${pkgrel}") + + if [ -d "${svnrepo_to}" ]; then + /usr/bin/svn rm --force -q "${svnrepo_to}" + /usr/bin/svn commit -q "${WORKDIR}/svn/${pkgbase}" -m "$(basename $0): ${pkgbase} removed by $(id -un) for move to [${repo_to}] (${pkgarch})" + fi + + /usr/bin/svn mv -q -r HEAD "${svnrepo_from}" "${svnrepo_to}" + /usr/bin/svn commit -q "${WORKDIR}/svn/${pkgbase}" -m "$(basename $0): moved ${pkgbase} from [${repo_from}] to [${repo_to}] (${pkgarch})" + + for pkgname in ${pkgnames[@]}; do + for tarch in ${tarches[@]}; do + pkgpath=$(getpkgfile "${ftppath_from}/${tarch}/"${pkgname}-${pkgver}-${pkgarch}${PKGEXT}) + pkgfile=$(basename "${pkgpath}") + + # copy package to pool if needed + # TODO: can be removed once every package has been moved to the package pool + if [ ! -f ${FTP_BASE}/${PKGPOOL}/${pkgfile} ]; then + cp ${pkgpath} ${FTP_BASE}/${PKGPOOL} + fi + ln -s "../../../${PKGPOOL}/${pkgfile}" ${ftppath_to}/${tarch}/ + 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 diff --git a/db-remove b/db-remove new file mode 100755 index 0000000..292af5d --- /dev/null +++ b/db-remove @@ -0,0 +1,46 @@ +#!/bin/bash + +. "$(dirname $0)/db-functions" +. "$(dirname $0)/config" + +if [ $# -ne 3 ]; then + msg "usage: $(basename $0) " + exit 1 +fi + +pkgbase="$1" +repo="$2" +arch="$3" + +ftppath="$FTP_BASE/$repo/os" +svnrepo="$repo-$arch" + +if ! check_repo_permission $repo; then + die "You don't have permission to remove packages from ${repo}" +fi + +if [ "$arch" == "any" ]; then + tarches=(${ARCHES[@]}) +else + tarches=("$arch") +fi + +for tarch in ${tarches[@]}; do + repo_lock $repo $tarch || exit 1 +done + +msg "Removing $pkgbase from [$repo]..." +/usr/bin/svn checkout -q "${SVNREPO}/${pkgbase}" "${WORKDIR}/svn/${pkgbase}" >/dev/null + +if [ -d "${WORKDIR}/svn/$pkgbase/repos/$svnrepo" ]; then + pkgnames=($(. "${WORKDIR}/svn/$pkgbase/repos/$svnrepo/PKGBUILD"; echo ${pkgname[@]})) + /usr/bin/svn rm --force -q "${WORKDIR}/svn/$pkgbase/repos/$svnrepo" + /usr/bin/svn commit -q "${WORKDIR}/svn/$pkgbase" -m "$(basename $0): $pkgbase removed by $(id -un)" +else + warning "$pkgbase not found in $svnrepo" +fi + +for tarch in ${tarches[@]}; do + arch_repo_remove "${repo}" "${tarch}" ${pkgnames[@]} + repo_unlock $repo $tarch +done diff --git a/db-repo-add b/db-repo-add new file mode 100755 index 0000000..53cfc84 --- /dev/null +++ b/db-repo-add @@ -0,0 +1,39 @@ +#!/bin/bash + +. "$(dirname $0)/db-functions" +. "$(dirname $0)/config" + +if [ $# -ne 3 ]; then + msg "usage: $(basename $0) " + exit 1 +fi + +pkgfile="$1" +repo="$2" +arch="$3" + +ftppath="$FTP_BASE/$repo/os" + +if ! check_repo_permission $repo; then + die "You don't have permission to add packages to ${repo}" +fi + +if [ "$arch" == "any" ]; then + tarches=(${ARCHES[@]}) +else + tarches=("$arch") +fi + +for tarch in ${tarches[@]}; do + repo_lock $repo $tarch || exit 1 +done + +msg "Adding $pkgfile to [$repo]..." + +for tarch in ${tarches[@]}; do + if [ ! -f "${pkgfile}" ]; then + die "Package file ${pkgfile} not found" + fi + arch_repo_add "${repo}" "${tarch}" ${pkgfile} + repo_unlock $repo $tarch +done diff --git a/db-repo-remove b/db-repo-remove new file mode 100755 index 0000000..b01910f --- /dev/null +++ b/db-repo-remove @@ -0,0 +1,36 @@ +#!/bin/bash + +. "$(dirname $0)/db-functions" +. "$(dirname $0)/config" + +if [ $# -ne 3 ]; then + msg "usage: $(basename $0) " + exit 1 +fi + +pkgname="$1" +repo="$2" +arch="$3" + +ftppath="$FTP_BASE/$repo/os" + +if ! check_repo_permission $repo; then + die "You don't have permission to remove packages from ${repo}" +fi + +if [ "$arch" == "any" ]; then + tarches=(${ARCHES[@]}) +else + tarches=("$arch") +fi + +for tarch in ${tarches[@]}; do + repo_lock $repo $tarch || exit 1 +done + +msg "Removing $pkgname from [$repo]..." + +for tarch in ${tarches[@]}; do + arch_repo_remove "${repo}" "${tarch}" ${pkgname} + repo_unlock $repo $tarch +done -- cgit v1.2.3