#!/bin/sh

MAKEDEPS="make docbook4-xml docbook-xsl docbook-dtd libxslt"
DEPS="pam gperf eudev"

PKG_VER=246.10
SOURCE=https://github.com/elogind/elogind/archive/v$PKG_VER/elogind-$PKG_VER.tar.gz
DESC="The standalone logind daemon"

prepare () {
    sed -i '/Disable polkit/,+8 d' meson.build
}

build () {
    mkdir build &&
    cd    build &&

    # TODO re-enable BUILD_MANS
    meson --prefix=/usr                        \
          --buildtype=release                  \
          -Dcgroup-controller=elogind          \
          -Ddbuspolicydir=/etc/dbus-1/system.d \
          -DBUILD_MANS=false                   \
          ..  &&
    ninja
}

package () {
    DESTDIR=$PKG_DEST ninja install &&
    ln -sfv  libelogind.pc $PKG_DEST/usr/lib/pkgconfig/libsystemd.pc &&
    ln -sfvn elogind $PKG_DEST/usr/include/systemd


    sed -e '/\[Login\]/a KillUserProcesses=no' \
    -i $PKG_DEST/etc/elogind/logind.conf

    cat >> $PKG_DEST/etc/pam.d/system-session << "EOF" &&
# Begin elogind addition

session  required    pam_loginuid.so
session  optional    pam_elogind.so

# End elogind addition
EOF
    cat > $PKG_DEST/etc/pam.d/elogind-user << "EOF"
# Begin /etc/pam.d/elogind-user

account  required    pam_access.so
account  include     system-account

session  required    pam_env.so
session  required    pam_limits.so
session  required    pam_unix.so
session  required    pam_loginuid.so
session  optional    pam_keyinit.so force revoke
session  optional    pam_elogind.so

auth     required    pam_deny.so
password required    pam_deny.so

# End /etc/pam.d/elogind-user
EOF


}