# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=ppp
pkgver=%version%
pkgrel=%release%
pkgdesc="A daemon which implements the Point-to-Point Protocol for dial-up networking"
arch=(x86_64)
url="https://www.samba.org/ppp/"
license=('GPL' 'BSD')
depends=('glibc' 'libpcap' 'libxcrypt' 'openssl')
backup=(etc/ppp/{chap-secrets,ip-down,ip-down.d/00-dns.sh,ip-up,ip-up.d/00-dns.sh,ipv6-down,ipv6-up,ipv6-up.d/00-iface-config.sh,options,pap-secrets})
source=(https://download.samba.org/pub/ppp/ppp-$pkgver.tar.gz{,.asc}
        ppp-revert-var-lock.patch::https://github.com/ppp-project/ppp/commit/99cbf5e269994482edaf64624be8b1c806f9587c.patch
        ppp-utils-mkdir.patch::https://github.com/ppp-project/ppp/commit/b0e7307b3569a5dad0f2606d2736cc8317851598.patch
        ppp-create-rundir.patch::https://github.com/ppp-project/ppp/commit/3a4fec968174fd6f387d5ec872a56343f256f645.patch
        ppp-device-name-too-long.patch::https://github.com/ppp-project/ppp/commit/9d6d326b2530cffb1414e4c401675117c42d43ce.patch
        options
        ip-up
        ip-down
        ip-up.d.dns.sh
        ip-down.d.dns.sh
        ipv6-up
        ipv6-down
        ipv6-up.d.iface-config.sh
        ppp.systemd
        LICENSE)
sha512sums=('094368ea2aa6c6e8dfba4443509857a7c1c7ff839bb6d6657743802477208c01e87db31593cef0932d3725c640e9c103179da6b742825034cda82bd31ddcc2ed'
            'SKIP'
            'eaf83b5d1204032f95dce12383a45ddc8050b4f85ba45bcc77f332fcbf8b73bf5f6fcf06f97e0606d37610249a013da8b36109f42a4901a477741970711ce73b'
            '444eb247f1d3d8a83a8180b0593f2b79005fbcddfe38d33845d76324f8aa584e17fce36906b9a03b9be9092b9afbe5ebce3365d64887c08b6b4e19069a70d1fa'
            '1bff91daaa61d4e3dcce82095be35f63c7025f22b956bf8b9ee48307a2ca437b61b55fd9f0172c514f3f6bee16aa9c615e6a11aeca663032d6a6d6f9166d4341'
            '201b0a5006d62c40952ac662e3d6990f53dae379d290f27d804c71f84cb3f0ac346a5da783fc90461b5a853cad27e78e3f61896794e676c740541d780cac6ce8'
            '4324a9abe79b20735b87de2158bb73b6449415a4760f06a06b648dfb53517f8d9907b094a88d1b492b24c8720cfd9b17d491fbe236fbd51ba9042af60483b231'
            'bdaaac792dd448ff31da6da2749d8c2f9c4e0311b1d4639de7c68038fcaa333cc28e25f5a6308de0ecb24b60b2e7284a811482df990da5f54d5581a746964f3c'
            '92f3a5e383f2c888938e891ba831042e7f8c026b0ddf5ce8c3523d06ac32fa81742e638a4c665975cbc79868b98806d92574ee2ee8e034e33b065a90ee3ab28b'
            '1636b2f8e3e0b0561aae9716e62c58cc7bee06aea0cdc163e64aba17da427810b7a12e4cea3d51b7a0b212fc2f4b7890f08d35d25165cd340b93241c9fe8842c'
            '7ab85cd977333e89c1d184619a52fa46492db04760c86a44843607c68efc577a1715d0d1f827d6855184af0d87b4b4b02cf7e7102c798516238a45a3c8aa26ad'
            '256941b220ad54119daf1c76237fecd0b2e9ede1d74b0950c45e373252ce20c1d4cd35a26b4d35f94ad2b7f49569fc9050c44731d672317994b562c750020326'
            '1b8dc6300f746607c0cce835e69ed444f24ba81874ba061b2b0377f0b9c1cb41a383d6845b364dfabb249a461422972ba5010bacf55c5f85f5eb0d3c0f4c71cd'
            '5b92a05bcf3ad4b7a88434546884e088069ce7c16a10c472589ca5ecc648f86ca02c2f608fb856ac6cb6ef14b508c2e0dec146c953128693bfb6c988f1963de8'
            'a73ae90ed8b3df166123ed5b977869efb957cb9c78538ff067f230ada894741e77a72caa3f32c14319eb4d4ad739579411ec6a30d9c197bd397dae25b1d90355'
            'ab3acd0387a7966ac3d220f2b0b6880302f827125d978991f83dd3f1a30340c2a98ca5aedf0b81ec6a9e5eb49b0b0a0a5356419f3b8415c892c2df8b52d3994a')
validpgpkeys=('631E179E370CD727A7F2A33A9E4295D605F66CE9'  # Paul Mackerras (Signing key) <paulus@samba.org>
              'DE8E01561D8276A4DBFAEFCC040F1D49EC9DBB8C') # Paul Mackerras <paulus@ozlabs.org>

prepare() {
  cd $pkgname-$pkgver

  patch -Np1 -i ../ppp-revert-var-lock.patch
  patch -Np1 -i ../ppp-utils-mkdir.patch
  patch -Np1 -i ../ppp-create-rundir.patch
  patch -Np1 -i ../ppp-device-name-too-long.patch
}

build() {
  cd $pkgname-$pkgver

  ./configure --prefix=/usr --sbindir=/usr/bin --sysconfdir=/etc --runstatedir=/run \
              --enable-systemd --enable-cbcp --enable-multilink 
  make
}

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

  install -D -m644 ../options "$pkgdir"/etc/ppp/options
  install -D -m755 ../ip-up   "$pkgdir"/etc/ppp/ip-up
  install -D -m755 ../ip-down "$pkgdir"/etc/ppp/ip-down
  install -d -m755 "$pkgdir"/etc/ppp/ip-up.d
  install -d -m755 "$pkgdir"/etc/ppp/ip-down.d
  install -m755 ../ip-up.d.dns.sh   "$pkgdir"/etc/ppp/ip-up.d/00-dns.sh
  install -m755 ../ip-down.d.dns.sh "$pkgdir"/etc/ppp/ip-down.d/00-dns.sh
  install -D -m755 ../ipv6-up   "$pkgdir"/etc/ppp/ipv6-up
  install -D -m755 ../ipv6-down "$pkgdir"/etc/ppp/ipv6-down
  install -d -m755 "$pkgdir"/etc/ppp/ipv6-up.d
  install -d -m755 "$pkgdir"/etc/ppp/ipv6-down.d
  install -m755 ../ipv6-up.d.iface-config.sh "$pkgdir"/etc/ppp/ipv6-up.d/00-iface-config.sh

  install -D -m755 scripts/pon  "$pkgdir"/usr/bin/pon
  install -D -m755 scripts/poff "$pkgdir"/usr/bin/poff
  install -D -m755 scripts/plog "$pkgdir"/usr/bin/plog
  install -D -m644 scripts/pon.1 "$pkgdir"/usr/share/man/man1/pon.1
  install -D -m600 etc.ppp/pap-secrets  "$pkgdir"/etc/ppp/pap-secrets
  install -D -m600 etc.ppp/chap-secrets "$pkgdir"/etc/ppp/chap-secrets
  install -d -m755 "$pkgdir"/etc/ppp/peers
  chmod 0755 "$pkgdir"/usr/lib/pppd/$pkgver/*.so

  install -D -m644 "$srcdir"/ppp.systemd "$pkgdir"/usr/lib/systemd/system/ppp@.service

  install -Dm644 "$srcdir"/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
