summaryrefslogtreecommitdiff
path: root/misc-scripts/find-dupes
blob: 16bf5303303e108883a01998c7c71c12d4acdca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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="/srv/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 *${PKGEXT}; 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 *${PKGEXT}; 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