From 410d14a1f9f22bf3f52a58f732305020c29e3141 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Sun, 3 Feb 2008 18:27:29 +0100 Subject: Adding cleanup scripts so they don't get lost: cleanup.sh: Iterates through the db file and lists dupes and missing files. cleanup2.sh: Iterates through the ftp directory and finds files that don't correspond to any package in the db. They currently only list files, but don't delete anything. --- cleanup-scripts/cleanup.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++ cleanup-scripts/cleanup2.sh | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100755 cleanup-scripts/cleanup.sh create mode 100755 cleanup-scripts/cleanup2.sh diff --git a/cleanup-scripts/cleanup.sh b/cleanup-scripts/cleanup.sh new file mode 100755 index 0000000..cdb0cef --- /dev/null +++ b/cleanup-scripts/cleanup.sh @@ -0,0 +1,53 @@ +#!/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%-*-*} +} + +FTPBASEDIR="/home/ftp" +FTPDIR=${FTPBASEDIR}/${1}/os/${2} +DBFILE=${FTPDIR}/${1}.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" diff --git a/cleanup-scripts/cleanup2.sh b/cleanup-scripts/cleanup2.sh new file mode 100755 index 0000000..4a79654 --- /dev/null +++ b/cleanup-scripts/cleanup2.sh @@ -0,0 +1,46 @@ +#!/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%-*-*} +} + +FTPBASEDIR="/home/ftp" +FTPDIR=${FTPBASEDIR}/${1}/os/${2} +DBFILE=${FTPDIR}/${1}.db.tar.gz +OBSOLETEFILES="" + +if [ $# -lt 2 -o ! -f ${DBFILE} ]; then + usage + exit 1 +fi + +TMPDIR=$(mktemp -d /tmp/cleanup.XXXXXX) || exit 1 +cd ${TMPDIR} +tar xzf ${DBFILE} + +cd ${FTPDIR} +for pkgfile in *.pkg.tar.gz; do + pkgname="$(getpkgname ${pkgfile})" + for p in ${FTPDIR}/${pkgname}-*; do + if [ "$(getpkgname $(basename ${p}))" = "${pkgname}" ]; then + continue 2 + fi + done + OBSOLETEFILES="${OBSOLETEFILES} ${pkgfile}" +done + +cd - >/dev/null +rm -rf ${TMPDIR} + +echo -ne "DIRECTORY:\n${FTPDIR}\n\n" +echo -ne "OBSOLETEFILES:\n${OBSOLETEFILES}\n\n" -- cgit v1.2.3-24-g4f1b