#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=xorg-xdm
pkgver=1.1.14
pkgrel=01
pkgdesc="X Display Manager no systemd"
arch=('x86_64')
url="https://xorg.freedesktop.org/"
depends=('pam' 'libxaw' 'libxinerama' 'xorg-xrdb' 'xorg-sessreg' 'libxft' 'libxcrypt')
makedepends=('xorg-util-macros' 'xtrans')
backup=(etc/X11/xdm/Xaccess etc/X11/xdm/Xresources etc/X11/xdm/Xservers etc/X11/xdm/xdm-config etc/pam.d/xdm etc/X11/xdm/Xsetup_0 etc/X11/xdm/Xsession)
source=(${url}/releases/individual/app/xdm-${pkgver}.tar.xz{,.sig}
        Xsession-loginshell.patch
        Xsession-xsm.patch
        xdm-1.0.5-sessreg-utmp-fix-bug177890.patch
        xdm.pam
        nolisten.patch)

prepare() {
  cd xdm-${pkgver}
  patch -Np0 -i "${srcdir}/Xsession-loginshell.patch"
  patch -Np1 -i "${srcdir}/Xsession-xsm.patch"
  patch -Np0 -i "${srcdir}/xdm-1.0.5-sessreg-utmp-fix-bug177890.patch"
  patch -Np1 -i ../nolisten.patch
  autoreconf -vfi
}

build() {
  cd xdm-${pkgver}

  # FS#63867 XDM's default userPath / systemPath hide /usr/local 
  unset DEF_USER_PATH

  ./configure --prefix=/usr \
      --disable-xdm-auth \
      --disable-static \
      --with-xdmconfigdir=/etc/X11/xdm \
      --with-xdmscriptdir=/etc/X11/xdm \
      --with-pixmapdir=/usr/share/xdm/pixmaps \
      --with-systemdsystemunitdir=no \
      DEF_USER_PATH="/usr/local/bin:/usr/bin:/bin" \
      DEF_SYSTEM_PATH="/usr/local/bin:/usr/bin:/bin"

  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd xdm-${pkgver}
  make check
}

package() {
  cd xdm-${pkgver}
  make DESTDIR="${pkgdir}" install
  install -m755 -d "${pkgdir}/var/lib/xdm"
  install -m755 -d "${pkgdir}/etc/pam.d"
  install -m644 "${srcdir}/xdm.pam" "${pkgdir}/etc/pam.d/xdm"
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/"

  sed -i -e 's/\/X11R6//g' "${pkgdir}"/etc/X11/xdm/*

#  sed -i 's|^Alias=.*|Alias=display-manager.service|' \
#    "$pkgdir/usr/lib/systemd/system/xdm.service"
}

#---- license gpg-key sha256sums ----

license=('custom')

validpgpkeys=('4A193C06D35E7C670FA4EF0BA2FB9E081F2D130E') # Alan Coopersmith <alan.coopersmith@oracle.com>

sha256sums=(3e9bf25636797ec9e595286dd6820ecc33901439f07705eaf608ecda012c3d5f # xdm-1.1.14.tar.xz
	40c51925f12d7d7ce2e5f100a69e5bc489dc0441ae3848b07a8fb390351bc22f # xdm-1.1.14.tar.xz.sig
	29898ece007a81d313b39a0b4fd461a68b45341e0b41967c61fc89df036bccac # Xsession-loginshell.patch
	502970834df0cfba4354f5cac8c01478339d63b6469c5cf12cf8d9356b2864ee # Xsession-xsm.patch
	5f380a2d6f77feb910d77f7f6843fce9b00ff7610c159fc029ee44cc6c23a48a # xdm-1.0.5-sessreg-utmp-fix-bug177890.patch
	e8c4c5fd3b801a390d201166fd1fb9730e78a5c62928768103b870b6bd980ea0 # xdm.pam
	c0ae2a6e9e92f96ee588ef92028dc3e42eca934305fd7fc608ca01bd8e190e60) # nolisten.patch
 
