pkgname=sudo
_sudover=1.9.17p2
pkgver=${_sudover/p/_p}
pkgdesc="Give certain users the ability to run some commands as root"
arch=('x86_64')
homepage="https://www.sudo.ws/sudo/"
license=('custom')
depends=('glibc' 'openssl' 'pam' 'zlib' 'virtual/libcrypt')
sources=("${pkgname}-${_sudover}.tar.gz")
urls=("https://www.sudo.ws/sudo/dist/${sources[0]}")
md5sums=("dcbf46f739ae06b076e1a11cbb271a10")

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

src_build() {
  local conf_args=(
    --prefix=/usr
    --disable-hardening
    --disable-python
    --enable-tmpfiles.d=/usr/lib/tmpfiles.d
    --enable-zlib=system
    --with-editor=/usr/bin/vim
    --with-env-editor
    --with-plugindir=/usr/lib/sudo
    --with-rundir=/run/sudo
    --with-vardir=/var/db/sudo
    --without-linux-audit
    --without-opie
    --disable-gcrypt
    --enable-nls
    --disable-sasl
    --enable-openssl
    --without-ldap
    --without-insults
    --without-all-insults
    --with-pam
    --with-pam-login
    --with-secure-path
    --with-secure-path-value="/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin"
    --without-selinux
    --without-sendmail
    --without-skey
    --without-sssd
  )
  ./configure "${conf_args[@]}"
  make
}

src_check() {
  env LC_ALL=C make check
}

src_install() {
  make DESTDIR="${pkgdir}" install

  install -vDm644 "${filedir}/sudo.pam" "${pkgdir}/etc/pam.d/sudo"
  install -vDm644 "${filedir}/sudo.pam" "${pkgdir}/etc/pam.d/sudo-i"

  chmod -v 0700 "${pkgdir}/var/db/sudo/lectured"
  chmod -v 0711 "${pkgdir}/var/db/sudo"

  rm -rf "${pkgdir}/run"

  mv -v "${pkgdir}/usr/share/doc/${pkgname}" "${pkgdir}/usr/share/doc/${pkgname}-${pkgver}"

  install -Dm644 LICENSE.md -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

src_postinstall() {
  local sudo_db="/var/db/sudo"
  if [[ "$(stat -c %a "${sudo_db}")" -ne 711 ]] ; then
    chmod 711 "${sudo_db}" || leaf_error "cannot chmod ${sudo_db}."
  fi
}

# vim:ft=sh syn=sh et sw=2:
