# PKGBUILD — autofs (ansipa self-hosted build)
#
# WHY THIS EXISTS:
#   The AUR `autofs` package is a hard dependency of the AUR `freeipa-client`
#   package (which ansipa needs to enroll Arch hosts into FreeIPA). As of the
#   autofs 5.2.0 upstream release, the kernel.org mirror pruned the
#   autofs-5.1.9.tar.xz tarball that the AUR PKGBUILD pins, so the AUR autofs
#   build fails with a 404 on its source — which in turn makes freeipa-client
#   (and therefore every Arch FreeIPA enrollment) impossible to install.
#
#   Rather than depend on that fragile, currently-broken tarball URL, this
#   PKGBUILD builds autofs from the upstream git repository pinned to a fixed
#   commit on the 5.1.9 maintenance series. That commit already contains the
#   upstream fix for "incompatible function pointer types in cyrus-sasl module"
#   (commit b7ff971b) that GCC 14+ requires, so we do not need the separate
#   downstream compiler patch the AUR fetched from the (also fragile) mirror.
#
#   freeipa-enroll.sh builds and installs this package before invoking the AUR
#   helper for freeipa-client, so the dependency is already satisfied and the
#   broken AUR autofs is never touched.
#
# Based on the AUR autofs PKGBUILD (maintainers: Alexander Jacocks, Hyacinthe
# Cartiaux et al.), reworked to build from git.

pkgname=autofs
pkgver=5.1.9
pkgrel=99          # high pkgrel so this local build wins over a stale AUR copy
pkgdesc='A kernel-based automounter for Linux (ansipa git build — fixes dead AUR tarball)'
arch=('x86_64')
url='https://git.kernel.org/pub/scm/linux/storage/autofs/autofs.git'
license=('GPL-2.0-or-later')
depends=('libxml2')
makedepends=('git' 'libldap' 'krb5' 'kmod' 'sssd' 'libnsl' 'rpcsvc-proto' 'systemd')
optdepends=('krb5: for LDAP support'
            'sssd: for SSSD integration')
backup=('etc/autofs/auto.master'
        'etc/autofs/auto.misc'
        'etc/autofs/auto.net'
        'etc/autofs/auto.smb'
        'etc/autofs/autofs.conf'
        'etc/autofs/autofs_ldap_auth.conf'
        'etc/default/autofs')
# Pinned commit on the 5.1.9 maintenance branch (tip as of this writing).
# Includes b7ff971b (cyrus-sasl function-pointer fix, needed for GCC 14+).
_commit='dec0b32389b670398ef1351193977daa629a6dea'
source=("${pkgname}::git+https://git.kernel.org/pub/scm/linux/storage/autofs/autofs.git#commit=${_commit}"
        'autofs-arch-configuration-path.patch')
sha256sums=('SKIP'
            '9974887b47de70f0b871230da96fa4620562289915b55401383232794578d18c')

prepare() {
  cd "${pkgname}"
  # Relocate config paths to Arch's /etc/autofs layout (matches the AUR package).
  patch --forward --strip=1 --input=../autofs-arch-configuration-path.patch
  # configure is committed upstream; refresh its mtime so make does not try to
  # regenerate it (autofs uses a hand-written build system, not automake, so no
  # autoreconf is required — a stale-timestamp regen would just fail).
  touch configure
}

build() {
  cd "${pkgname}"
  ./configure --prefix=/usr \
        --sysconfdir=/etc/autofs \
        --sbindir=/usr/bin \
        --with-mapdir=/etc/autofs \
        --with-confdir=/etc/default \
        --without-hesiod \
        --enable-ignore-busy \
        --with-libtirpc \
        --with-systemd
  make
}

package() {
  cd "${pkgname}"
  make INSTALLROOT="${pkgdir}" install install_samples
  install -dm755 "${pkgdir}/etc/autofs/auto.master.d"
}
