# shellcheck shell=bash disable=SC2034
# Maintainer: Storm Dragon <storm_dragon@stormux.org>

pkgname=nodm
pkgver=0.13
pkgrel=1slint
forkBranch=10-rebase
source=(
  "https://github.com/dgw/nodm/archive/${forkBranch}.tar.gz"
  "nodm.conf"
  "rc.nodm"
)
url="https://github.com/dgw/nodm"
license=('GPL')
depends=('pam' 'xorg-xinit')
makedepends=('help2man')
options=('noautodotnew')

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"nodm (automatic login display manager)"
"nodm is a minimal X display manager for automatic logins."
"This package uses dgw's fork with restart fixes."
"It installs /etc/nodm.conf and /etc/rc.d/rc.nodm."
)

doinst() {
  config() {
    newFile="$1"
    oldFile="$(dirname "$newFile")/$(basename "$newFile" .new)"
    if [ ! -r "$oldFile" ]; then
      mv "$newFile" "$oldFile"
    elif [ "$(cat "$oldFile" | md5sum)" = "$(cat "$newFile" | md5sum)" ]; then
      rm "$newFile"
    fi
  }

  config etc/nodm.conf.new
  config etc/rc.d/rc.nodm.new

}

build() {
  buildArch="${ARCH:-x86_64}"
  jobCount="${numjobs:-1}"
  scriptDir="${startdir:-$PWD}"

  cd "$SRC/$pkgname-10-rebase" || exit 1

  ./autogen.sh || exit 1
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/sbin \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --build="${buildArch}-slackware-linux" || exit 1
  make -j "$jobCount" || exit 1
  make DESTDIR="$PKG" install || exit 1

  install -d "$PKG/etc/rc.d"
  install -m 644 "$scriptDir/nodm.conf" "$PKG/etc/nodm.conf.new"
  install -m 755 "$scriptDir/rc.nodm" "$PKG/etc/rc.d/rc.nodm.new"
}
