#!/bin/sh
#
# Copyright 2008-2009 Dropline GNOME
# Available under the terms of the GNU GPL.
#

NAME="policykit"
VERSION="0.9"
REVISION="12"
TARNAME="PolicyKit"

PKG_SOURCEURL='http://hal.freedesktop.org/releases/$TARNAME-$VERSION.tar.gz'

PKG_PATCH[0]='pk-ck-api-change.patch'
PKG_PATCH[1]='pkit-slack.patch'

PKG_PATCH[2]='org.freedesktop.hal.device-access.policy'
PKG_PATCH[3]='org.freedesktop.hal.dockstation.policy'
PKG_PATCH[4]='org.freedesktop.hal.killswitch.policy'
PKG_PATCH[5]='org.freedesktop.hal.policy'
PKG_PATCH[6]='org.freedesktop.hal.power-management.policy'
PKG_PATCH[7]='org.freedesktop.hal.storage.policy'
PKG_PATCH[8]='org.freedesktop.hal.wol.policy'

PKG_PATCH[9]='PolicyKit.conf'

. $DLG_ROOT/config
. $DLG_ROOT/SCRIPTS/dropline-functions.sh

PKG_LOCALSTATEDIR=/var

cflags
cxxflags
prepare
applypatch 0 1
applypatch 1 1

cd $PKG_SRCROOT
autoreconf
analyzesource
configure --with-pam-module-dir=/usr/lib$LIBSUFFIX/security \
          --with-polkit-user=polkituser \
          --with-polkit-group=polkituser 
make
makeinstall install-strip

# Lets 0wnz sum sum thingz :D
spewdo "chmod u+s $PKG_STAGEROOT$PKG_PREFIX/sbin/userhelper"
spewdo "chown polkituser:polkituser $PKG_STAGEROOT/var/{run,lib}/PolicyKit"
spewdo "chown polkituser $PKG_STAGEROOT/var/lib/PolicyKit-public"
spewdo "chown polkituser:polkituser $PKG_STAGEROOT/var/lib/misc/PolicyKit.reload"
spewdo "chown polkituser $PKG_STAGEROOT$PKG_PREFIX/lib$LIBSUFFIX/PolicyKit/polkit-set-default-helper"
spewdo "chmod u+s $PKG_STAGEROOT$PKG_PREFIX/lib$LIBSUFFIX/PolicyKit/polkit-set-default-helper"

spewdo "cd $PKG_STAGEROOT$PKG_PREFIX/libexec"
for i in polkit-read-auth-helper polkit-revoke-helper polkit-grant-helper polkit-explicit-grant-helper; do
	chgrp $i
	chmod g+s $i
done

for patchnum in 2 3 4 5 6 7 8
do
  findpatch filename ${PKG_PATCH[$patchnum]}
  spewdo "cp $filename ${PKG_STAGEROOT}${PKG_DATADIR}/PolicyKit/policy/"
done

findpatch filename ${PKG_PATCH[9]}
spewdo "cp $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/PolicyKit/"
configfile $PKG_SYSCONFDIR/PolicyKit/PolicyKit.conf

spewdo "chgrp polkituser $PKG_STAGEROOT$PKG_PREFIX/lib$LIBSUFFIX/PolicyKit/polkit-grant-helper-pam"
spewdo "chmod u+s $PKG_STAGEROOT$PKG_PREFIX/lib$LIBSUFFIX/PolicyKit/polkit-grant-helper-pam"

tidydocumentation
analyzebinaries

createroleaccount polkituser 73 73

finalizepackage
packagize
cleanup
