# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=pacrunner
pkgver=0.19
pkgrel=4
pkgdesc="Proxy configuration daemon"
arch=(x86_64 aarch64)
url="https://git.kernel.org/pub/scm/network/connman/pacrunner.git"
license=(GPL-2.0-only)
depends=(
  curl
  dbus
  duktape
  glib2
  glibc
)
makedepends=(git)
source=(
  "git+https://git.kernel.org/pub/scm/network/connman/pacrunner.git#tag=$pkgver"
  0001-Link-duktape-dynamically.patch
)
b2sums=('c7fdb1641c5933a62d99c696c77d6edabc9d2a6b47b52f2e7434bed874c063a3000ccc47c09bd7e2c6829937d5cd05e083f752d3cda7b6e52d00211f17ef4802'
        '97700f151a95badde24c110659c1e95a8656cb021a54de3627ced2bb792cc65c0a35ea330302ae125ce1b9713077293e6f6073599e6b71d6180b8f366754c5d8')

prepare() {
  cd $pkgname

  # Use our system duktape
  git apply -3 ../0001-Link-duktape-dynamically.patch

  ./bootstrap
}

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --localstatedir=/var
    --sbindir=/usr/bin
    --libexecdir=/usr/lib
    --with-dbusconfdir=/usr/share
    --enable-pie
    --enable-duktape
    --enable-curl
  )

  cd $pkgname
  ./configure "${configure_options[@]}"
  make
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install

  install -Dm644 /dev/stdin "$pkgdir/usr/lib/systemd/system/pacrunner.service" <<END
[Unit]
Description=Proxy configuration daemon
Before=network.target
Wants=network.target

[Service]
Type=dbus
BusName=org.pacrunner
ExecStart=/usr/bin/pacrunner

[Install]
WantedBy=multi-user.target
END

  install -Dm644 /dev/stdin "$pkgdir/usr/share/dbus-1/system-services/org.pacrunner.service" <<END
[D-BUS Service]
Name=org.pacrunner
Exec=/usr/bin/pacrunner
User=root
SystemdService=pacrunner.service
END
}

# vim:set sw=2 sts=-1 et:
