# Obarun        : 66 init/supervisor
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
# Obarun PkgSrc : https://git.obarun.org/pkg/obextra/consolekit/
#--------------------------------------------------------------------------
# Website       : https://github.com/ConsoleKit2/ConsoleKit2/
#--------------------------------------------------------------------------
#--DESCRIPTION---------------------------------------------------------------

pkgname=consolekit2

pkgver=1.2.4
pkgrel=2

pkgdesc="A framework for defining and tracking users, login sessions, and seats"

url="https://github.com/ConsoleKit2/ConsoleKit2"

target=tag
track="${pkgver}"

source=("$pkgname::git+$url#$target=$track"
        '25-consolekit.rules'
        'consolekit.pamd'
        'pam-foreground-compat.ck'
        'tmpfiles.conf'
        'trust_runtime_admin_policy.patch'
        'set_good_hpr_command.patch'
        'keep_runtime_dir.patch')

#--BUILD CONFIGURATION-------------------------------------------------------

options=('libtool')

optdepends=(
    'pm-utils: support for suspend/hibernate')

makedepends=(
    'xmlto'
    'docbook-xsl'
    'gtk-doc'
    'pam')

#--BUILD PREPARATION---------------------------------------------------------

pkgver() {
    cd $pkgname

    git describe --tags | sed -e 's:-:+:g;'
}

prepare() {
    cd $srcdir/$pkgname

    patch --forward --strip=1 --input="${srcdir}/trust_runtime_admin_policy.patch"
    patch --forward --strip=1 --input="${srcdir}/set_good_hpr_command.patch"
    patch --forward --strip=1 --input="${srcdir}/keep_runtime_dir.patch"
}

#--BUILD CONTROL----------------------------------------------------------

path=(
    --prefix=/usr
    --sysconfdir=/etc
    --sbindir=/usr/bin
    --with-rundir=/run
    --libexecdir=/usr/libexec/
    --localstatedir=/var
)

flags=(
    --enable-polkit
    --enable-pam-module
    --enable-udev-acl
    --with-dbus-services=/usr/share/dbus-1/services
    --with-dbus-sys=/usr/share/dbus-1/system.d
    --with-pam-module-dir=/usr/lib/security
    --with-systemdsystemunitdir=no
    --disable-libcgmanager
    --enable-libevdev
    --enable-libudev
    --with-html-dir=/usr/share/doc/consolekit/html
    --disable-gtk-doc-html
    --with-x
    --with-xinitrc-dir=/etc/X11/Xsession.d
)

#--BUILD---------------------------------------------------------------------

build(){
    cd $srcdir/$pkgname

    ./autogen.sh "${path[@]}" "${flags[@]}"
    make
}

#--PACKAGE-------------------------------------------------------------------

package() {
    cd $srcdir/$pkgname

    make DESTDIR="$pkgdir" install

    install -dm 700 "${pkgdir}"/usr/share/polkit-1/rules.d
    install -m 644 ${srcdir}/25-consolekit.rules $pkgdir/usr/share/polkit-1/rules.d/75-consolekit.rules

    install -dm755 $pkgdir/etc/pam.d/
    install -Dm644 ${srcdir}/consolekit.pamd $pkgdir/etc/pam.d/consolekit

    install -Dm 0755 "${srcdir}"/pam-foreground-compat.ck "${pkgdir}"/usr/lib/ConsoleKit/run-session.d/pam-foreground-compat.ck

    install -Dm 0644 "${srcdir}"/tmpfiles.conf "${pkgdir}"/usr/lib/tmpfiles.d/consolekit.conf

    rm -r "${pkgdir}"/run
}

#--INSTALL CONFIGURATION-----------------------------------------------------

arch=(x86_64)

provides=(
    'consolekit'
    'consolekit2')

replaces=(
    'consolekit')

conflicts=(
    'consolekit')

depends=(
    'dbus'
    'glib2'
    'libx11'
    'polkit'
    'udev'
    'zlib'
    'popt')

#--------------------------------------------------------------------------

license=('GPL')

sha512sums=('SKIP'
            '56865e65e269cb4aec2ab6beea537c79fa62b23eec74ec40c343956f0dd5d53c30f493e732c478c6f5ceb50a16008a3176ec69c089d735b3383bcf068060dc25'
            'ddc50300ec8328f1a586400d124a4f77b8267677f6804e91d62ba3a869e6e20ef192b77f009eb202d6d297c69f31ad67b47ac04fb9330dcb14aa6ad9c3030080'
            '294b006a31df6e4e7e71a4292626de961c0a6408ee977a041897001fc201e4e32bc50dba70fa1ee8d3398057881cea6335b8b2fed11b5d2c079701790caa2a2f'
            '1ec445433f7eee94d46609c3398c8388bb008323debc047e665e14a0c3f27a1c264460347531da124b5a907cb15ef9fdadff23aebab332b410c69b8ad1ff40b6'
            '65e5d6986b56f63b7ca347b3bd80576ef765d1f49ee27f3171b160ebb196b4c4968ed32c4df1e697a31706d1f0bca39d3bb66eaa89d6603e80fa4b7e400b9f3c'
            'a1dc81208940bdc392ba2a60e4871ddf11f15e7343f0b15bd2591d7436581f409d7c684291d3d91c8c978b89848e06b5f28b4c81a6c90c7afa0f2fbac48220ec'
            '05f01f2f0f6b293e97c1b39f8ef75c99dbacd89df7c7a4968f1ce1331175d2eda710b5f0d43443d4afe9ab581ca9399a08ff9be607d15caef2f017427ad4d212')
