# Packager = Tuxcore <dev@tuxcore.org> pkgname=cifs-utils
pkgver=7.0
pkgrel=3
pkgdesc="CIFS filesystem user-space tools"
arch=(x86_64)
url="https://wiki.samba.org/index.php/LinuxCIFS_utils"
license=('GPL')
depends=('libcap-ng' 'keyutils' 'krb5' 'talloc' 'pam' 'libwbclient')
makedepends=('python-docutils')
optdepends=('python: for smb2-quota and smbinfo script')
source=("https://download.samba.org/pub/linux-cifs/$pkgname/$pkgname-$pkgver.tar.bz2"{,.asc})

sha256sums=('0defaab85bd3ea46ffc45ab41fb0d0ad54d05ae2cfaa7e503de86d4f12bc8161'
            'SKIP')

prepare() {
  # Fix install to honor DESTDIR
  sed -e 's|cd \$(ROOTSBINDIR)|cd $(DESTDIR)$(ROOTSBINDIR)|g' -i $pkgname-$pkgver/Makefile.am
}

build() {
  cd "$srcdir/$pkgname-$pkgver"
  # systemd support is broken in mount.cifs
  # https://bugs.archlinux.org/task/30958
  autoreconf -i
  # https://www.spinics.net/lists/linux-cifs/msg21550.html
  # change back to libcap-ng depend when upstream is fixed
  ./configure --prefix=/usr --sbindir=/usr/bin --disable-systemd 
  make
}

package() {
  cd "$srcdir/$pkgname-$pkgver"
  make DESTDIR="$pkgdir" ROOTSBINDIR=/usr/bin install
  mkdir -p "$pkgdir"/etc/request-key.d
  install -m 644 contrib/request-key.d/cifs.idmap.conf "$pkgdir"/etc/request-key.d
  install -m 644 contrib/request-key.d/cifs.spnego.conf "$pkgdir"/etc/request-key.d
  # set mount.cifs uid, to enable none root mounting form fstab
  chmod +s "$pkgdir"/usr/bin/mount.cifs
  # fix idmap-plugin #42052
  mkdir -p "$pkgdir"/etc/cifs-utils
  ln -s /usr/lib/cifs-utils/idmapwb.so "${pkgdir}"/etc/cifs-utils/idmap-plugin
}
