# Maintainer: David P. <megver83@parabola.nu>
# Maintainer (Arch): David Runge <dvzrv@archlinux.org>

_pkgname=mkinitcpio-archiso

pkgname=mkinitcpio-parabolaiso
pkgver=68
_commit=2ac885187f6dc610254c2fd1a6bb8e13f6e739fa  #refs/tags/v68
pkgrel=1.1
pkgdesc="Initcpio scripts used by parabolaiso"
arch=(any)
url="https://gitlab.archlinux.org/mkinitcpio/mkinitcpio-archiso"
license=(GPL3)
depends=(bash device-mapper mkinitcpio)
makedepends=(git)
checkdepends=(shellcheck shfmt)
optdepends=(
  'curl: for PXE over HTTP'
  'gnupg: for PGP signature verification of rootfs over PXE'
  'mkinitcpio-nfs-utils: for PXE over NFS'
  'nbd: for PXE over NBD'
  'openssl: for CMS signature verification of rootfs over PXE'
  'pv: for status display during copy to RAM'
)
source=("${pkgname}::git+https://gitlab.archlinux.org/mkinitcpio/${_pkgname}.git#tag=$_commit?signed")
sha256sums=('SKIP')
validpgpkeys=(
  '991F6E3F0765CF6295888586139B09DA5BF0D338'  # David Runge <dvzrv@archlinux.org>
  'BB8E6F1B81CF0BB301D74D1CBF425A01E68B38EF'  # nl6720 <nl6720@archlinux.org>
)

provides=("$_pkgname=$pkgver")
conflicts=("$_pkgname")
replaces=("${conflicts[@]}")

prepare() {
  find $pkgname -type l -o -type f -not -path "$pkgname/.*" | while read -r file; do
    if [[ -f "$file" ]]; then
      sed -i "$file" -e '
        s|Arch Linux|Parabola GNU/Linux-libre|g;
        s|archiso|parabolaiso|g;
        s|ARCHISO|PARABOLAISO|g;
        s|ARCH|PARA|g;
        s|parabolaisobasedir=".*"|parabolaisobasedir="parabola"|;
        s|dm_snap_prefix=".*"|dm_snap_prefix="parabola"|;
        s|/arch/|/parabola/|;
        '
    fi
    if [[ "$file" =~ "archiso" ]]; then
      mv -v "$file" "${file/archiso/parabolaiso}"
    fi
  done
}

check() {
  make -k check -C $pkgname
}

package() {
  make DESTDIR="$pkgdir/" PREFIX=/usr install -C $pkgname
}

