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

pkgname=shadow
pkgver=4.12.3
pkgrel=02
pkgdesc="Password and account management tool suite with support for shadow files and PAM w/o systemd"
arch=('x86_64')
url='https://github.com/shadow-maint/shadow'
depends=(
  acl libacl.so
  attr libattr.so
  audit libaudit.so
  glibc
  libxcrypt libcrypt.so
  pam libpam.so libpam_misc.so
)
makedepends=(docbook-xsl itstool libcap libxslt)
backup=(
  etc/default/useradd
  etc/login.defs
  etc/pam.d/{chage,{,ch,chg}passwd,group{add,del,mems,mod},newusers,shadow,user{add,del,mod}}
)
#options=(debug !emptydirs)
options=('!emptydirs')
source=(
  https://github.com/shadow-maint/shadow/releases/download/$pkgver/shadow-$pkgver.tar.xz{,.asc}
  0001-Disable-replaced-tools-and-man-pages.patch
  0002-Adapt-login.defs-for-PAM-and-util-linux.patch
  0003-Add-Arch-Linux-defaults-for-login.defs.patch
  0004-Add-Arch-Linux-defaults-for-etc-pam.d.patch
#  chgpasswd
#  chpasswd
#  defaults.pam
#  login.defs
#  newusers
#  passwd
  useradd.defaults
)
# install=shadow.install

prepare() {
  local filename

  cd $pkgname-$pkgver
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      printf "Applying patch %s\n" "${filename##*/}"
      patch -Np1 -i "$srcdir/${filename##*/}"
    fi
  done

  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --bindir=/usr/bin
    --sbindir=/usr/bin
    --libdir=/usr/lib
    --mandir=/usr/share/man
    --sysconfdir=/etc
    --disable-account-tools-setuid
    --enable-man
    --with-fcaps
    --with-libpam
    --with-group-name-max-length=32
    --with-audit
    --with-bcrypt
    --with-yescrypt
    --without-selinux
    --without-systemd
    --disable-dependency-tracking
    --without-su
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"

  # prevent excessive overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  cd $pkgname-$pkgver

  make DESTDIR="$pkgdir" install
  make DESTDIR="$pkgdir" -C man install

  # license
  install -vDm 644 COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"

  # custom useradd(8) defaults (not provided by upstream)
  install -vDm 600 ../useradd.defaults "$pkgdir/etc/default/useradd"

}

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

license=('BSD')

validpgpkeys=(66D0387DB85D320F8408166DB175CFA98F192AF2)  # Serge Hallyn <sergeh@kernel.org>

sha256sums=(3d3ec447cfdd11ab5f0486ebc47d15718349d13fea41fc8584568bc118083ccd  # shadow-4.12.3.tar.xz
	7fa4f333fd5d67390fc7b5b4a27ecc864ab59141d189012f463bca8eec57dfa1  # shadow-4.12.3.tar.xz.asc
	774c7b4941489a2a9da99f9d391356fb21fd400be02a4bbc678438edfabf17df  # 0001-Disable-replaced-tools-and-man-pages.patch
	986562e197f1efef60b4ebab5316c388d630d171fdca74237bff864db0bf4970  # 0002-Adapt-login.defs-for-PAM-and-util-linux.patch
	85e22497e1a7e3be04233090d12866b5d2b9752ddba08f9aa63bc938a0b8b780  # 0003-Add-Arch-Linux-defaults-for-login.defs.patch
	287fa34df46338a9ee4090e0f358d4f537124879dc0c0ab8ab2d148f9416efb2  # 0004-Add-Arch-Linux-defaults-for-etc-pam.d.patch
	c7ae1086e00248915cf67d361482510ec00e728d21714d4e2b56b90cc9adac91)  # useradd.defaults

