summaryrefslogtreecommitdiffstats
path: root/misc-scripts/find-dupes
diff options
context:
space:
mode:
authorAaron Griffin <aaronmgriffin@gmail.com>2008-05-15 00:49:20 +0200
committerAaron Griffin <aaronmgriffin@gmail.com>2008-05-15 00:51:05 +0200
commit39298cf09e2e88b1f6aec779170990675baf8992 (patch)
tree653de4d1002b0be8a6b6111e88b7c4cc5df29203 /misc-scripts/find-dupes
parente021dfb2c476c2841606e63e6ae58dfc45cd1b47 (diff)
downloaddbscripts-39298cf09e2e88b1f6aec779170990675baf8992.tar.gz
dbscripts-39298cf09e2e88b1f6aec779170990675baf8992.tar.xz
Cron cleanup, and only copy DB files once
This would break all adds if there were any deletes. We definitely don't want that. Also, cleanup of cron scripts in the same commit because I'm lazy Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
Diffstat (limited to 'misc-scripts/find-dupes')
-rwxr-xr-xmisc-scripts/find-dupes77
1 files changed, 77 insertions, 0 deletions
diff --git a/misc-scripts/find-dupes b/misc-scripts/find-dupes
new file mode 100755
index 0000000..82cd1a4
--- /dev/null
+++ b/misc-scripts/find-dupes
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+if [ $# -ne 2 ]; then
+ echo "usage: $(basename $0) <reponame> <arch>"
+ 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
+
+cd $ftppath
+
+# Get the package name from the filename
+# hackish, but should work for now
+getpkgname() {
+ local tmp
+
+ tmp=${1##*/}
+ tmp=${tmp%$PKGEXT}
+ tmp=${tmp%-$CARCH}
+ echo ${tmp%-*-*}
+}
+
+showdupes() {
+ done=""
+ for i in *.pkg.tar.gz; do
+ pkgname=$(getpkgname $i)
+ if [ "$pkgname" = "$1" ]; then
+ lastmod="$(stat -c %y $i | cut -d. -f1)"
+ fname="$(basename $i)"
+
+ echo "$lastmod $fname"
+
+ done=1
+ else
+ if [ "$done" = "1" ]; then
+ return
+ fi
+ fi
+ done
+}
+
+echo "Scanning for duplicate packages in '$reponame' ($arch)"
+DUPES=""
+lastpkg=""
+
+for pkg in *.pkg.tar.gz; do
+ pkgname="$(getpkgname $pkg)"
+ if [ "$lastpkg" = "$pkgname" ]; then
+ DUPES="$DUPES $pkgname"
+ fi
+ lastpkg=$pkgname
+done
+
+if [ "$DUPES" ]; then
+ DUPES="$(echo $DUPES | sed 's| |\n|g' | sort -u)"
+ echo "Date Filename"
+ for dupe in $DUPES; do
+ showdupes $dupe
+ done
+fi