# Maintainer: Yurii Kolesnykov <root@yurikoles.com>
# Contributor: Jonathon Fernyhough <jonathon"m2x+dev>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Iacopo Isimbaldi <isiachi@rhye.it>
#
# Based on aur/zfs-utils by Kevin Stolp <kevinstolp@gmail.com>
# Based on archzfs/zfs-utils-git by Jan Houben <jan@nexttrex.de>
#
# Pull requests are welcome here: https://github.com/yurikoles-aur/zfs-utils-git
#

pkgname=zfs-utils-git
pkgver=2.4.99.r778.ge78fa488af
pkgrel=1
epoch=2
pkgdesc='Userspace utilities for the Zettabyte File System.'
arch=('i686' 'x86_64' 'aarch64')
url='https://zfsonlinux.org/'
license=('CDDL-1.0')
groups=('zfs-git')
makedepends=(
  'git'
  'python'
  'python-cffi'
  'python-setuptools'
)
optdepends=(
  'pam: managing encryption keys'
  'python: pyzfs and extra utilities'
  'python-cffi: pyzfs'
)
provides=("zfs-utils=${pkgver}")
conflicts=('zfs-utils')
backup=(
  'etc/default/zfs'
  'etc/zfs/zed.d/zed.rc'
)
source=(
  "git+https://github.com/openzfs/zfs.git"
  'zfs.initcpio.install'
  'zfs.initcpio.hook'
  'zfs.initcpio.zfsencryptssh.install'
)
sha256sums=('SKIP'
  '2f09c742287f4738c7c09a9669f8055cd63d3b9474cd1f6d9447152d11a1b913'
  '15b5acea44225b4364ec6472a08d3d48666d241fe84c142e1171cd3b78a5584f'
  'ac9ed396465e26fa6896762c52a93eb7aaf8af6d7b2c69bd826d219ff821b2c9')
b2sums=('SKIP'
  'cb774227f157573f960bdb345e5b014c043a573c987d37a1db027b852d77a5eda1ee699612e1d8f4a2770897624889f1a3808116a171cc4c796a95e3caa43012'
  '779c864611249c3f21d1864508d60cfe5e0f5541d74fb3093c6bdfa56be2c76f386ac1690d363beaee491c5132f5f6dbc01553aa408cda579ebca74b0e0fd1d0'
  'fcd871d72c62a7c99d6cf29cb40a4751bfc08238ff39e8c9440d119754e92ded4705414710db86e99d044011f3524e54c778bda94696dde2c06b3289da6628d0')

pkgver() {
  git -C zfs describe --long | sed 's/^zfs-//;s/-rc/rc/;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd zfs

  autoreconf -fi
}

build() {
  cd zfs

  ./configure --prefix=/usr \
    --sysconfdir=/etc \
    --sbindir=/usr/bin \
    --with-mounthelperdir=/usr/bin \
    --libdir=/usr/lib \
    --datadir=/usr/share \
    --includedir=/usr/include \
    --with-udevdir=/usr/lib/udev \
    --libexecdir=/usr/lib \
    --localstatedir=/var \
    --enable-pyzfs \
    --enable-systemd \
    --with-zfsexecdir=/usr/lib/zfs \
    --with-config=user
  make
}

package() {
  cd zfs

  make DESTDIR="${pkgdir}" install
  install -Dm644 contrib/bash_completion.d/zfs "${pkgdir}"/usr/share/bash-completion/completions/zfs

  # Remove uneeded files
  rm -r "${pkgdir}"/etc/init.d
  rm -r "${pkgdir}"/usr/lib/modules-load.d
  rm -r "${pkgdir}"/usr/share/initramfs-tools
  rm -r "${pkgdir}"/usr/share/zfs/*.sh
  rm -r "${pkgdir}"/usr/share/zfs/{runfiles,test-runner,zfs-tests}

  # Install the support files
  install -Dm644 "${srcdir}"/zfs.initcpio.hook "${pkgdir}"/usr/lib/initcpio/hooks/zfs
  install -Dm644 "${srcdir}"/zfs.initcpio.install "${pkgdir}"/usr/lib/initcpio/install/zfs
  install -Dm644 "${srcdir}"/zfs.initcpio.zfsencryptssh.install "${pkgdir}"/usr/lib/initcpio/install/zfsencryptssh

  # Install the license
  install -Dm644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}
