pkgname=shadow
pkgver=4.18.0
pkgdesc="Password and account management tool suite with support for shadow files and PAM"
homepage="https://github.com/shadow-maint/shadow"
license=(BSD-3-Clause)
sources=("${pkgname}-${pkgver}.tar.xz"
)
urls=("https://github.com/shadow-maint/shadow/releases/download/${pkgver}/${sources[0]}"
)
md5sums=("30ef46f54363db1d624587be68794ef2"
)


src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1

  sed -i 's/groups$(EXEEXT) //' src/Makefile.in
  find man -name Makefile.in -exec sed -i 's/groups\.1 / /'   {} \;
  find man -name Makefile.in -exec sed -i 's/getspnam\.3 / /' {} \;
  find man -name Makefile.in -exec sed -i 's/passwd\.5 / /'   {} \;

  sed -e 's:#ENCRYPT_METHOD DES:ENCRYPT_METHOD YESCRYPT:' \
      -e 's:/var/spool/mail:/var/mail:'                   \
      -e '/PATH=/{s@/sbin:@@;s@/bin:@@}'                  \
      -i etc/login.defs

  if [[ ! -f /usr/bin/passwd ]]; then
    touch /usr/bin/passwd
  fi
}

src_build() {
  ./configure --sysconfdir=/etc   \
              --disable-static    \
              --with-{b,yes}crypt \
              --without-libbsd    \
              --with-group-name-max-length=32
  make
}

src_install() {
  make exec_prefix=/usr DESTDIR="${pkgdir}" install
  make DESTDIR="${pkgdir}" -C man install-man
  install -vDm 644 COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  #install -vDm 600 "${distdir}/useradd" -t "${pkgdir}/etc/default/"
  mkdir -pv "${pkgdir}/etc/default"
  cat > "${pkgdir}/etc/default/useradd" << EOF
GROUP=999
GROUPS=
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
USRSKEL=/usr/etc/skel
CREATE_MAIL_SPOOL=no
LOG_INIT=yes
EOF
}
