#!/bin/bash
#
# Copyright 2005, 2006 Scott Harmon
# Copyright 2006-2026 Sasa Ostrouska <saxa@droplinegnome.org>
# Copyright 2014 John Truex <apolluwn@gmail.com>
# Available under the terms of the GNU GPL.
#

NAME="gdm"
VERSION="50.1"
REVISION="1"

PKG_SOURCEURL='${DLG_GNOMEMIRROR}/${NAME}/${VER_MAJ}/${NAME}-${VERSION}.tar.xz'

PKG_PATCH[0]="xinitrc.gnome"
PKG_PATCH[1]='blackbox.desktop'
PKG_PATCH[2]='fluxbox.desktop'
PKG_PATCH[3]='fvwm2.desktop'
PKG_PATCH[4]='kde.desktop'
PKG_PATCH[5]='twm.desktop'
PKG_PATCH[6]='windowmaker.desktop'
PKG_PATCH[7]='custom.conf'
PKG_PATCH[8]='gdmpin-pamd'
PKG_PATCH[9]='gdmauto-pamd'
PKG_PATCH[10]='gdmcard-pamd'
PKG_PATCH[11]='gdmfinger-pamd'
PKG_PATCH[12]='gdmpass-pamd'
PKG_PATCH[13]='system.conf'
#PKG_PATCH[14]='gdm-44.0-meson-allow-building-with-elogind.patch'

. $DLG_ROOT/etc/config
. $DLG_ROOT/lib/dl-base

cflags
prepare
analyzesource

# We have to patch the meson.build to get the thing going with libelogind.
#applypatch 14 1

configure -Dsystemd-journal=false \
	-Dselinux=disabled \
	-Dsystemdsystemunitdir=no \
	-Dsystemduserunitdir=no \
	-Dlog-dir=/var/log/gdm \
	-Dinitial-vt=7 \
	-Ddefault-pam-config=redhat \
	-Ddbus-sys=/etc/dbus-1/system.d \
	-Dplymouth=disabled \
	-Drun-dir=/run/gdm \
	-Dgdm-xsession=true \
	-Dlogind-provider=elogind 

make
makeinstall

# configfile $PKG_SYSCONFDIR/gdm/custom.conf
createroleaccount gdm 42 42

# Install the xinitrc.gnome file that starts GNOME *correctly*
createdir $PKG_STAGEROOT$PKG_SYSCONFDIR/X11/xinit
findpatch filename ${PKG_PATCH[0]}
spewdo "install -m 755 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/X11/xinit/"
spewdo "cd $PKG_STAGEROOT$PKG_SYSCONFDIR/X11/xinit/ && ln -sf xinitrc.gnome xinitrc"

# Copy all those little .desktop files (for the things Slackware ships only)
spewdo "createdir $PKG_STAGEROOT$PKG_PREFIX/share/xsessions"
for (( idx=1; idx <= 6; idx++ )); do
	findpatch filename ${PKG_PATCH[idx]}
	spewdo "install -m 755 $filename $PKG_STAGEROOT$PKG_PREFIX/share/xsessions"
done

createdir $PKG_STAGEROOT$PKG_SYSCONFDIR/gdm
findpatch filename ${PKG_PATCH[7]}
spewdo "install -m 644 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/gdm/custom.conf"

# Add the files that consolekit and userhelper require to make gdmsetup
# work with a non-root user
createdir $PKG_STAGEROOT$PKG_SYSCONFDIR/pam.d
findpatch filename ${PKG_PATCH[8]}
spewdo "install -m 644 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/pam.d/gdm-pin"
findpatch filename ${PKG_PATCH[9]}
spewdo "install -m 644 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/pam.d/gdm-autologin"
findpatch filename ${PKG_PATCH[10]}
spewdo "install -m 644 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/pam.d/gdm-smartcard"
findpatch filename ${PKG_PATCH[11]}
spewdo "install -m 644 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/pam.d/gdm-fingerprint"
findpatch filename ${PKG_PATCH[12]}
spewdo "install -m 644 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/pam.d/gdm-password"

# Copy the original dbus config
findpatch filename ${PKG_PATCH[13]}
spewdo "install -m 644 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/dbus-1/system.conf"

tidydocumentation
analyzebinaries
finalizepackage
packagize
cleanup
