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

pkgname=mkinitcpio-parabolaiso
pkgver=58
pkgrel=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'
  'mkinitcpio-nfs-utils: for PXE over NFS'
  'nbd: for PXE over NBD'
  'pv: for status display during copy to RAM'
)
source=("${pkgname}::git+https://gitlab.archlinux.org/mkinitcpio/mkinitcpio-archiso.git#tag=v${pkgver}?signed")
sha256sums=('SKIP')
validpgpkeys=('C7E7849466FE2358343588377258734B41C31549') # David Runge <dvzrv@archlinux.org>

provides=("mkinitcpio-archiso=$pkgver")
conflicts=('mkinitcpio-archiso')
replaces=(${conflicts[@]})

check() {
  cd "$pkgname"
  make -k check
}

prepare() {
  local rebrand
  rebrand='
  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/|;
  '

  cd "$pkgname"
  sed -i "$rebrand" script/* Makefile hooks/* docs/* install/*

  for f in hooks/* install/* script/*; do
    mv "$f" "${f/archiso/parabolaiso}"
  done
}

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