From fd921f8dc355ac51a8be843a4da052474b22700c Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Thu, 29 May 2008 15:31:21 -0400 Subject: Move ftpdir-cleanup to misc-scripts Signed-off-by: Aaron Griffin --- misc-scripts/ftpdir-cleanup | 116 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 misc-scripts/ftpdir-cleanup (limited to 'misc-scripts') diff --git a/misc-scripts/ftpdir-cleanup b/misc-scripts/ftpdir-cleanup new file mode 100755 index 0000000..f8c1a8e --- /dev/null +++ b/misc-scripts/ftpdir-cleanup @@ -0,0 +1,116 @@ +#!/bin/bash + +if [ $# -ne 2 ]; then + echo "usage: $(basename $0) " + exit 1 +fi + +reponame=$1 +arch=$2 + +##### Arch specific stuff. TODO make this configurable ##### +ftppath="/home/ftp/$reponame/os/$arch/" +############################################################ + +if [ ! -d "$ftppath" ]; then + echo "FTP path '$ftppath' does not exist" + exit 1 +fi + +if [ ! -f /etc/makepkg.conf ]; then + echo "/etc/makepkg.conf not found! Aborting" + exit 1 +fi + +. /etc/makepkg.conf + +getpkgname() { + local tmp + + tmp=${1##*/} + tmp=${tmp%$PKGEXT} + tmp=${tmp%-$arch} + echo ${tmp%-*-*} +} + +getpkgname_ver() { + local tmp + + tmp=${1##*/} + tmp=${tmp%$PKGEXT} + echo ${tmp%-$arch} +} + +MISSINGFILES="" +DELETEFILES="" +EXTRAFILES="" + +TMPDIR=$(mktemp -d /tmp/cleanup.XXXXXX) || exit 1 + +cd "${TMPDIR}" +/bin/tar xzf "$ftppath/$reponame.db.tar.$DB_COMPRESSION" + +for pkg in *; do + filename=$(grep -A1 '^%FILENAME%$' "${pkg}/desc" | tail -n1) + [ -z "${filename}" ] && filename="${pkg}.pkg.tar.gz" + + if [ ! -f "${ftppath}/${filename}" ]; then + MISSINGFILES="${MISSINGFILES} ${filename}" + else + pkgname="$(getpkgname ${filename})" + for otherfile in ${ftppath}/${pkgname}-*; do + otherfile="$(basename ${otherfile})" + if [ "${otherfile}" != "${filename}" -a "${pkgname}" = "$(getpkgname ${otherfile})" ]; then + DELETEFILES="${DELETEFILES} ${otherfile}" + fi + done + fi +done + +cd "$ftppath" +for pkg in *$PKGEXT; do + pkgname="$(getpkgname $pkg)" + for p in ${TMPDIR}/${pkgname}-*; do + if [ -d "${p}" -a "$(getpkgname $(basename ${p}))" = "${pkgname}" ]; then + continue 2 + fi + done + EXTRAFILES="$EXTRAFILES $pkg" +done + +cd "$ftppath" +rm -rf ${TMPDIR} + +echo "Scan complete for $reponame ($arch) at ${ftppath}" +if [ -n "$DELETEFILES" ]; then + echo " The following files are out of date" + echo " They will be moved to /home/package-cleanup" + for f in $DELETEFILES; do + echo " $f" + done +fi +echo "" +if [ -n "$MISSINGFILES" ]; then + echo " The following files are missing in the repo" + for f in $MISSINGFILES; do + echo " $f" + done +fi +echo "" +if [ -n "$EXTRAFILES" ]; then + echo " The following files are in the repo but not the db" + echo " They will be moved to /home/package-cleanup" + for f in $EXTRAFILES; do + echo " $f" + done +fi + +if [ -n "${DELETEFILES}" ]; then + mv ${DELETEFILES} /home/package-cleanup/ + echo "" +fi + +if [ -n "${EXTRAFILES}" ]; then + mv ${EXTRAFILES} /home/package-cleanup/ + echo "" +fi -- cgit v1.2.3-24-g4f1b