summaryrefslogtreecommitdiffstats
path: root/cron-jobs/create-filelists
blob: e90da00e128e65f93d0884b36fb3f40792684f70 (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
78
79
80
81
82
83
84
#!/bin/bash

reposdir="/srv/ftp"
targetdir="/srv/ftp"
repos="core extra testing community community-testing"
lock="/tmp/create-filelists.lock"

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

if [ -f "$lock" ]; then
    echo "Error: create-filelists already in progress."
    exit 1
fi

touch "$lock" || exit 1
TMPDIR="$(mktemp -d /tmp/create-filelists.XXXXXX)" || exit 1
CACHEDIR="$(mktemp -d /tmp/create-filelists.XXXXXX)" || exit 1

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

case "${DBEXT}" in
    *.gz)  TAR_OPT="z" ;;
    *.bz2) TAR_OPT="j" ;;
    *.xz)  TAR_OPT="J" ;;
    *) echo "Unknown compression type for DBEXT=${DBEXT}" && exit 1 ;;
esac

FILESEXT="${DBEXT//db/files}"

for repo in $repos; do
    REPO_DB_FILE="${repo}$FILESEXT"
    for arch in ${ARCHES[@]}; do
        cd "$reposdir"

        repodir="${repo}/os/${arch}"
        cached="no"

        # extract old file archive
        if [ -f "${targetdir}/${repodir}/${REPO_DB_FILE}" ]; then
            mkdir -p "${CACHEDIR}/${repodir}"
            bsdtar -xf "${targetdir}/${repodir}/${REPO_DB_FILE}" -C "${CACHEDIR}/${repodir}"
            cached="yes"
        fi

        # create file lists
        for pkg in $repodir/*${PKGEXT}; do
            pkgname="$(getpkgname "$pkg")"
            pkgver="$(getpkgver "$pkg")"
            tmppkgdir="${TMPDIR}/${repodir}/${pkgname}-${pkgver}"
            mkdir -p "$tmppkgdir"
            if [ -f "${CACHEDIR}/${repodir}/${pkgname}-${pkgver}/files" ]; then
#               echo "cache: $pkgname"
                mv "${CACHEDIR}/${repodir}/${pkgname}-${pkgver}/files" "${tmppkgdir}/files"
            else
#               echo "$repo/$arch: $pkgname"
                echo '%FILES%' > "${tmppkgdir}/files"
                bsdtar --exclude=.* -tf "$pkg" >> "${tmppkgdir}/files"
                cached="no"
            fi
        done

        # create new file archive
        if [ "$cached" == "no" ]; then
            # at least one package has changed, so let's rebuild the archive
#           echo "creating ${REPO_DB_FILE}/${arch}"
            pkgdir="${targetdir}/${repodir}"
            mkdir -p "$pkgdir"
            cd "${TMPDIR}/${repodir}"
            [ -f "${pkgdir}/${REPO_DB_FILE}.old" ] && rm "${pkgdir}/${REPO_DB_FILE}.old"
            [ -f "${pkgdir}/${REPO_DB_FILE}" ] && mv "${pkgdir}/${REPO_DB_FILE}" "${pkgdir}/${REPO_DB_FILE}.old"
            bsdtar --exclude=*${DBEXT//\.db/} -c${TAR_OPT}f "${pkgdir}/${REPO_DB_FILE}" *
        fi
    done
done

cd - >/dev/null
rm -rf "$TMPDIR" || exit 1
rm -rf "$CACHEDIR" || exit 1
rm -f "$lock" || exit 1
# echo 'done'

# vim: set ts=4 sw=4 et ft=sh: