# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=rauc
pkgver=1.11.3
pkgrel=1
pkgdesc="Safe and secure software updates for embedded Linux"
arch=(x86_64 aarch64)
url="https://rauc.io"
license=(LGPL-2.1-or-later)
depends=(
  gcc-libs
  glibc
  libnl
  openssl
  sh
)
makedepends=(
  curl
  dbus
  glib2
  json-glib
  meson
  python
  systemd
  util-linux
  python-packaging
)
checkdepends=(squashfs-tools)
optdepends=(
  'casync: for casync conversion support'
  'cryptsetup: for disk encryption support'
  'dosfstools: for creating and checking FAT filesystems'
  'e2fsprogs: for creating and checking ext2/3/4 filesystems'
  'efibootmgr: for interacting with EFI boot manager'
  'grub: for GRUB support'
  'mtd-utils: for interacting with MTD devices'
  'squashfs-tools: for creating and inspecting bundles'
  'uboot-tools: for u-boot support'
)
source=(
  https://github.com/rauc/rauc/releases/download/v$pkgver/$pkgname-$pkgver.tar.xz{,.asc}
  $pkgname.tmpfiles
)
sha512sums=('3ba3050045bfc14ba93f5f13e1257e2fa486039e9fcd76fafa2604daf5955e67cadabf2d178e6ecd025e9b683a41677694fff15c0f1b9c48ffa08bb012bc8887'
            'SKIP'
            '35173525a8529c4d5a227186db353107193bf8cdd3e8ab0cd94c418b34187be50fe379bcabf623bfddbf1916e8e7e965800a269e823f7ee9c26f44ac1f689c94')
b2sums=('da488d23d28b66e20cf69d2d9465612ca8a22faaf4a77676303d1363807e90b3f77294a63a3f1b71e7bf90801ddcba231e416d93bfd9be8a23505fefeab0e253'
        'SKIP'
        'e970b292f89cf4663b4ea318965444dc9bb47ef5f937143f180a372c5906f534e7c2f234dfa824b70434011069ea7758e4d6c8afd73dd5c4d92337da7e281eca')
validpgpkeys=("977843FD5C3EBF76BAD4008EA58CC53DBF05E090")  # Jan Lübbe <jlu@pengutronix.de>

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build

}

check() {
  local meson_tests=($(meson test -C build --list))
  # disable broken tests
  local disabled_tests=()
  for target in "${disabled_tests[@]}"; do
    for i in "${!meson_tests[@]}"; do
      if [[ ${meson_tests[i]} = $target ]]; then
        unset 'meson_tests[i]'
      fi
    done
  done

  meson test -C build "${meson_tests[@]}"
}

package() {
  depends+=(
    curl libcurl.so
    glib2 lib{gobject,gio,glib}-2.0.so
    json-glib libjson-glib-1.0.so
    util-linux-libs libfdisk.so
  )

  meson install -C build --destdir "$pkgdir"
  install -vdm 755 "$pkgdir/etc/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/contrib/{grub.conf,uboot.sh} -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 $pkgname.tmpfiles "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
}
