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

setacl()
{
    u="$1"
    g="$2"
    m="$3"
    shift 3
    for f in $*; do
        if ! dpkg-statoverride --list "$f" >/dev/null 2>&1; then
            dpkg-statoverride --update --add "$u" "$g" "$m" "$f"
        fi
    done
}

setacld()
{
    u="$1"
    g="$2"
    m="$3"
    shift 3
    for d in $*; do
        for p in `find "$d" -type d`; do
            setacl "$u" "$g" "$m" "$p"
        done
    done
}

setaclf()
{
    u="$1"
    g="$2"
    m="$3"
    shift 3
    for d in $*; do
        for p in `find "$d" -type f`; do
            setacl "$u" "$g" "$m" "$p"
        done
    done
}

setacl "root" "www-data" 0775 "$BUGZILLA_ETCDIR" "$BUGZILLA_ETCDIR/sites"
setacl "www-data" "www-data" 0660 "$BUGZILLA_ETCDIR"/params
setacl "www-data" "www-data" 0660 "$BUGZILLA_ETCDIR"/localconfig
setacl "www-data" "www-data" 0660 "$BUGZILLA_DATADIR"/shutdownhtml
setacl "root" "www-data" 0644 "$BUGZILLA_ETCDIR"/index.html

setacl "root" "www-data" 0775 "$BUGZILLA_DATADIR" "$BUGZILLA_DATADIR"/attachments "$BUGZILLA_DATADIR"/duplicates "$BUGZILLA_DATADIR"/mining "$BUGZILLA_DATADIR"/template "$BUGZILLA_DATADIR"/webdot

# It's a really time consuming action to manage access rights for all files
# and directories with dpkg-statoverride e.g. for the $BUGZILLA_VARDIR/template.
#setacld "www-data" "www-data" 0755 "$BUGZILLA_VARDIR"/template
#setaclf "www-data" "www-data" 0644 "$BUGZILLA_VARDIR"/template
#
# As workarround we make some assumtions:
# 1) All directories get the same user/group and mode as "$BUGZILLA_VARDIR"/tempalte
# 2) All files gets the same same user/group and mode as "$BUGZILLA_VARDIR"/template/en/default/index.html.tmpl
#
# Check post-checksetup.p/15restoredpkgstatoverride how this will be achived.
setacl "www-data" "www-data" 0755 "$BUGZILLA_VARDIR"/template
setacl "www-data" "www-data" 0644 "$BUGZILLA_VARDIR"/template/en/default/index.html.tmpl

setacld "root" "www-data" 0775 "$BUGZILLA_WEBDIR"/skins
setaclf "root" "www-data" 0664 "$BUGZILLA_WEBDIR"/skins

setacl "root" "www-data" 0755 "$BUGZILLA_EXTENSIONSDIR"

# vim:ts=4:et
