#
# This script fixes permissions for some files and dirs,
# and creates the policykit system user/group.
#
case "$2" in
pre)
	;;
post)
	echo "Running $3-$4 post installation hooks..."
	if ! chroot . getent group policykit >/dev/null; then
		chroot . groupadd -r policykit
		[ $? -ne 0 ] && exit $?
		echo "Created policykit system group."
	fi
	if ! chroot . getent passwd policykit >/dev/null; then
		chroot . useradd -c "PolicyKit user" \
			-d / -s /sbin/nologin -g policykit -r policykit && \
		chroot . passwd -l policykit &>/dev/null
		[ $? -ne 0 ] && exit $?
		echo "Created policykit system user."
	fi
	chroot . chgrp policykit var/run/PolicyKit
	chroot . chgrp policykit var/lib/PolicyKit
	chroot . chown policykit var/lib/PolicyKit-public
	chroot . chown policykit:policykit var/lib/misc/PolicyKit.reload
	chroot . chown policykit usr/libexec/polkit-set-default-helper
	chroot . chmod u+s usr/libexec/polkit-set-default-helper
	for i in polkit-read-auth-helper polkit-revoke-helper \
		polkit-grant-helper polkit-explicit-grant-helper; do
		chroot . chgrp policykit usr/libexec/$i
		chroot . chmod g+s usr/libexec/$i
	done
	chroot . chgrp policykit usr/libexec/polkit-grant-helper-pam
	chroot . chmod u+s usr/libexec/polkit-grant-helper-pam
	;;
esac
