#!/bin/sh
# Copyright (C) 2009  Raphael Bossek <bossekr@debian.org>

set -e

tmpf=`tempfile`
trap "rm $tmpf" EXIT QUIT
dpkg-statoverride --list "*/bugzilla3*"| sed -e 's,^\([^[:space:]]\+\)[[:space:]]\([^[:space:]]\+\)[[:space:]]\([^[:space:]]\+\)[[:space:]]\(.*\),chown \1:\2 "\4"\nchmod \3 "\4",g' >"$tmpf"
set +e
. "$tmpf"
set -e

# Please read the post-checksetup.d/10setdefaultdpkgstatoverride about how
# to speed up the processing of "$BUGZILLA_VARDIR"/templates
for d in `find "$BUGZILLA_VARDIR"/template -mindepth 1 -type d`; do
	chmod --reference="$BUGZILLA_VARDIR"/template "$d"
	chown --reference="$BUGZILLA_VARDIR"/template "$d"
done
for f in `find "$BUGZILLA_VARDIR"/template -mindepth 1 -type f`; do
	test "$f" = "$BUGZILLA_VARDIR"/template/en/default/index.html.tmpl && continue
	chmod --reference="$BUGZILLA_VARDIR"/template/en/default/index.html.tmpl "$f"
	chown --reference="$BUGZILLA_VARDIR"/template/en/default/index.html.tmpl "$f"
done
# Access rights for the $BUGZILLA_DATADIR/template content are the same as
# for the source files.
for d in `find $BUGZILLA_DATADIR/template -mindepth 1 -type d`; do
	chmod --reference="$BUGZILLA_VARDIR"/template "$d"
	chown --reference="$BUGZILLA_VARDIR"/template "$d"
done
for f in `find $BUGZILLA_DATADIR/template -mindepth 1 -type f`; do
	chmod --reference="$BUGZILLA_VARDIR"/template/en/default/index.html.tmpl "$f"
	chown --reference="$BUGZILLA_VARDIR"/template/en/default/index.html.tmpl "$f"
done
