description="Application development toolkit for controlling system-wide privileges"
url="http://hal.freedesktop.org/docs/polkit"

packager="spiky <spiky@nutyx.org>"
contributors="Pierre,Tnut"

name=polkit
version=125

makedepends=(pam systemd gettext glib duktape gobject-introspection elogind
             patch autoconf intltool perl-xml-parser libxslt docbook-xsl)
source=(https://github.com/$name-org/$name/archive/$version/$name-$version.tar.gz)

prepare() {
SN="polkitd"
IDN="27"
if ! (getent group $SN > /dev/null); then
   groupadd -g $IDN $SN
fi
if ! (getent passwd $SN > /dev/null); then
   useradd -c "PolicyKit Daemon Owner" -d /etc/polkit-1 \
   -u $IDN -g $SN -s /bin/false $SN
fi
sed -i '/systemd_sysusers_dir/s/^/#/' $name-$version/meson.build
}
build() {
cd $name-$version

mkdir build
cd    build

meson --prefix=/usr                       \
      --buildtype=release                 \
      -Dman=false                         \
      -Dsession_tracking=elogind       \
      -Dtests=true                        \
      -Djs_engine=duktape                 \
      ..

ninja

DESTDIR=$PKG ninja install

mkdir -p $PKG/etc/pam.d
cat > $PKG/etc/pam.d/polkit-1 << "EOF"
# Begin /etc/pam.d/polkit-1

auth     include        system-auth
account  include        system-account
password include        system-password
session  include        system-session

# End /etc/pam.d/polkit-1
EOF
}
