summaryrefslogtreecommitdiff
path: root/cron-jobs/ftpdir-cleanup
blob: 3456e9c99deea397abd904f135a7c81a2accffe9 (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
#!/bin/bash

. "$(dirname $0)/../db-functions"
. "$(dirname $0)/../config"

repos="$(get_repos_for_host)"

script_lock

#adjust the nice level to run at a lower priority
/usr/bin/renice +10 -p $$ > /dev/null

repopaths=''
for repo in $repos; do
    $(dirname $0)/../misc-scripts/ftpdir-cleanup-repo $repo
    repopaths="${repopaths} ${FTP_BASE}/${repo}/os/"
done

to_cleanup=""
poolpath="$FTP_BASE/$(get_pkgpool_for_host)/"
pushd $poolpath >/dev/null
for pkg in *$PKGEXT; do
[ -f "$pkg" ] || continue # in case we get a file named "*.pkg.tar.gz"
LINKS="$(/usr/bin/find $repopaths -type l -name "$pkg" 2>/dev/null)"
if [ -z "$LINKS" ]; then
	to_cleanup="$to_cleanup $poolpath/$pkg"
fi
done
popd >/dev/null

if [ -n "$to_cleanup" ]; then
    msg "The following packages are no longer in any repo"
    for f in $to_cleanup; do
        msg2 "$(basename "$f")"
    done
    ${CLEANUP_DRYRUN} || mv $to_cleanup "$CLEANUP_DESTDIR"
fi

script_unlock