summaryrefslogtreecommitdiff
path: root/db-cleanup
blob: 0c093c2f0e1cb1440833c39cfffa4483e3a4e30b (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
#!/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!

trap_exit() {
    echo
    error "$@"
    exit 1
}

source $(dirname $0)/config
source $(dirname $0)/local_config
source $(dirname $0)/libremessages

# From makepkg
set -E

trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR

(( CLEANUP_DRYRUN )) && EXTRAFLAGS+=" --dry-run"

for _repo in ${ARCHREPOS[@]}; do
    for _arch in ${ARCHARCHES[@]}; do
        msg "Getting ${_repo}-${_arch} database"

        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}" | \
            cut -d'/' -f1 | \
            sort -u | \
            sed "s|$|*|" >> /tmp/$0.$PID.filter

    done
done

msg "Removing old files:"

for POOL in ${PKGPOOLS[@]} ${SRCPOOLS[@]}; do
    msg2 "${POOL}"

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

exit $?