summaryrefslogtreecommitdiffstats
path: root/cron-jobs/create-filelists
blob: c3e7d7293bfbd97a031081ae95db46087b519534 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash

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

script_lock

for repo in ${PKGREPOS[@]}; do
	for arch in ${ARCHES[@]}; do
		repo_lock ${repo} ${arch} || exit 1
	done
done

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

for repo in ${PKGREPOS[@]}; do
	for arch in ${ARCHES[@]}; do
		repodb="${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}"
		filedb="${FTP_BASE}/${repo}/os/${arch}/${repo}${FILESEXT}"

		if [ ! -f "${repodb}" ]; then
			continue
		fi
		# get a list of package files defined in the repo db
		mkdir -p "${WORKDIR}/db-dir-${repo}-${arch}"
		bsdtar -xf "${repodb}" -C "${WORKDIR}/db-dir-${repo}-${arch}"
		find "${WORKDIR}/db-dir-${repo}-${arch}" -name 'desc' \
			-exec awk '/^%FILENAME%/{getline;print}' {} \; | sort > "${WORKDIR}/db-${repo}-${arch}"

		# get a list of package files defined in the files db
		mkdir -p "${WORKDIR}/files-current-dir-${repo}-${arch}"
		if [ ! -f "${filedb}" ]; then
			echo > "${WORKDIR}/files-${repo}-${arch}"
		else
			bsdtar -xf "${filedb}" -C "${WORKDIR}/files-current-dir-${repo}-${arch}"
			find "${WORKDIR}/files-current-dir-${repo}-${arch}" -name 'desc' \
				-exec awk '/^%FILENAME%/{getline;print}' {} \; | sort > "${WORKDIR}/files-${repo}-${arch}"
		fi
	done
done

case "${FILESEXT}" in
	*.gz)  TAR_OPT="z" ;;
	*.bz2) TAR_OPT="j" ;;
	*.xz)  TAR_OPT="J" ;;
	*) die "Unknown compression type for FILESEXT=${FILESEXT}" ;;
esac

for repo in ${PKGREPOS[@]}; do
	for arch in ${ARCHES[@]}; do
		filedb="${FTP_BASE}/${repo}/os/${arch}/${repo}${FILESEXT}"

		if [ ! -f  "${WORKDIR}/db-${repo}-${arch}" ]; then
			# remove any files db that might be in this empty repo
			if [ -f "${filedb}" ]; then
				rm -f "${filedb}"
			fi
			continue
		fi

		# Check if updating the files db is needed
		if ! diff -q "${WORKDIR}/db-${repo}-${arch}" "${WORKDIR}/files-${repo}-${arch}" >/dev/null; then
			mkdir -p "${WORKDIR}/files-new-dir-${repo}-${arch}"

			# Include all unchanged file lists
			# Note: deleted packages are implicitly excluded
			for f in $(comm -12 "${WORKDIR}/db-${repo}-${arch}" "${WORKDIR}/files-${repo}-${arch}"); do
				mv "${WORKDIR}/files-current-dir-${repo}-${arch}/${f%*-*${PKGEXT}}" \
					"${WORKDIR}/files-new-dir-${repo}-${arch}"
			done

			# Create file lists for new packages
			for f in $(comm -23 "${WORKDIR}/db-${repo}-${arch}" "${WORKDIR}/files-${repo}-${arch}"); do
				tdir="${WORKDIR}/files-new-dir-${repo}-${arch}/${f%*-*${PKGEXT}}"
				mkdir "${tdir}"
				echo '%FILES%' > "${tdir}/files"
				bsdtar --exclude=.* -tf "${FTP_BASE}/${repo}/os/${arch}/${f}" >> "${tdir}/files"

				# add desc and depends file from db
				dbdir="${WORKDIR}/db-dir-${repo}-${arch}/${f%*-*${PKGEXT}}"
				mv "${dbdir}/desc" "${tdir}/desc"
				mv "${dbdir}/depends" "${tdir}/depends"
			done

			# Create the actual file db
			pushd "${WORKDIR}/files-new-dir-${repo}-${arch}" >/dev/null
			bsdtar -c${TAR_OPT}f "${WORKDIR}/${arch}-${repo}${FILESEXT}" *
			popd >/dev/null
			mv -f "${WORKDIR}/${arch}-${repo}${FILESEXT}" "${filedb}"
			ln -sf "${repo}${FILESEXT}" "${filedb%.tar.*}"
		fi
	done
done

for repo in ${PKGREPOS[@]}; do
	for arch in ${ARCHES[@]}; do
		repo_unlock ${repo} ${arch}
	done
done

script_unlock