summaryrefslogtreecommitdiff
path: root/cron-jobs/db-cleanup
blob: fc7fd259b80ca8555bd39be5db1efdac5750476b (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
#!/bin/bash
# Syncs pools against themselves using database contents as filter to cleanup
# them up
# License: GPLv3

# Principles
# * Get repos dbs contents
# * Make them a include list
# * Rsync pools against themselves removing excluded files
# * Instant cleanup!

source "$(dirname "$(readlink -e "$0")")/../config"
source "$(dirname "$(readlink -e "$0")")/../db-cleanup.conf"
source "$(librelib messages)"
setup_traps

EXTRAFLAGS=()
if [[ $CLEANUP_DRYRUN = true ]]; then
	EXTRAFLAGS+=(--dry-run)
fi

filter=$(mktemp -t "${0##*/}.XXXXXXXXXX")
trap "rm -f -- ${filter@Q}" EXIT

for _repo in "${PKGREPOS[@]}"; do
	for _arch in "${ARCHES[@]}"; do
		msg "Getting %s-%s database" "${_repo}" "${_arch}"

		dbfile="${FTP_BASE}/${_repo}/os/${_arch}/${_repo}${DBEXT}"

		if [ ! -r "${dbfile}" ]; then
			warning "Not found"
			continue
		fi

		# Echo the contents into a filter file
		bsdtar tf "${dbfile}"
	done
done | cut -d'/' -f1 | sort -u | sed "s|$|*|" > "$filter"

msg "Removing old files:"

for POOL in "${PKGPOOLS[@]}" "${SRCPOOLS[@]}" "${TORRENTPOOLS[@]}"; do
	msg2 '%s' "${POOL}"

	rsync "${EXTRAFLAGS[@]}" -va --delete-excluded \
		--include-from="$filter" \
		--exclude="*" \
		"${FTP_BASE}/${POOL}/" \
		"${FTP_BASE}/${POOL}/"
done

msg "Removing dead symlinks:"
actions=(-print)
if [[ $CLEANUP_DRYRUN != true ]]; then
	actions+=(-delete)
fi
find -L "${FTP_BASE}/" -type l "${actions[@]}"