summaryrefslogtreecommitdiffstats
path: root/cron-jobs/ftpdir-cleanup
diff options
context:
space:
mode:
authorAaron Griffin <aaronmgriffin@gmail.com>2008-05-07 08:06:21 +0200
committerAaron Griffin <aaronmgriffin@gmail.com>2008-05-07 08:06:57 +0200
commit511759504993c858d977b649cd02cf7969811b57 (patch)
tree3e98d0b862e5ccb7776d7ccd5cb92e6d259c6c04 /cron-jobs/ftpdir-cleanup
parentcbd6533816b1c27aab268b5c8f823345be8e12ed (diff)
downloaddbscripts-511759504993c858d977b649cd02cf7969811b57.tar.gz
dbscripts-511759504993c858d977b649cd02cf7969811b57.tar.xz
Moving some files around, organizational
Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
Diffstat (limited to 'cron-jobs/ftpdir-cleanup')
-rwxr-xr-xcron-jobs/ftpdir-cleanup60
1 files changed, 60 insertions, 0 deletions
diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup
new file mode 100755
index 0000000..18e26f2
--- /dev/null
+++ b/cron-jobs/ftpdir-cleanup
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+usage() {
+ echo "Usage: $0 repo architecture"
+}
+
+getpkgname() {
+ local tmp
+
+ tmp=${1##*/}
+ tmp=${tmp%.pkg.tar.gz}
+ tmp=${tmp%-i686}
+ tmp=${tmp%-x86_64}
+ echo ${tmp%-*-*}
+}
+
+reponame=$1
+arch=$2
+
+FTPBASEDIR="/home/ftp"
+FTPDIR=${FTPBASEDIR}/$reponame/os/$arch
+DBFILE=${FTPDIR}/$reponame.db.tar.gz
+MISSINGFILES=""
+DELETEFILES=""
+
+if [ $# -lt 2 -o ! -f ${DBFILE} ]; then
+ usage
+ exit 1
+fi
+
+TMPDIR=$(mktemp -d /tmp/cleanup.XXXXXX) || exit 1
+
+cd ${TMPDIR}
+tar xzf ${DBFILE}
+for pkg in *; do
+ filename=$(grep -A1 '^%FILENAME%$' ${pkg}/desc | tail -n1)
+ [ -z "${filename}" ] && filename="${pkg}.pkg.tar.gz"
+ if [ ! -f ${FTPDIR}/${filename} ]; then
+ MISSINGFILES="${MISSINGFILES} ${filename}"
+ else
+ pkgname="$(getpkgname ${filename})"
+ for otherfile in ${FTPDIR}/${pkgname}-*; do
+ otherfile="$(basename ${otherfile})"
+ if [ "${otherfile}" != "${filename}" -a "${pkgname}" = "$(getpkgname ${otherfile})" ]; then
+ DELETEFILES="${DELETEFILES} ${otherfile}"
+ fi
+ done
+ fi
+done
+
+cd - >/dev/null
+rm -rf ${TMPDIR}
+
+echo -ne "DIRECTORY:\n${FTPDIR}\n\n"
+echo -ne "DELETEFILES:\n${DELETEFILES}\n\n"
+echo -ne "MISSINGFILES:\n${MISSINGFILES}\n\n"
+
+cd ${FTPDIR}
+[ -n "${DELETEFILES}" ] && mv ${DELETEFILES} /home/package-cleanup/
+cd - >/dev/null