#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobcore/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=ppp
pkgver=2.4.9
pkgrel=03
pkgdesc="A daemon which implements the Point-to-Point Protocol for dial-up networking - no ipv6 w/o systemd"
arch=(x86_64)
url="https://www.samba.org/ppp/"
depends=('glibc' 'libpcap' 'libxcrypt' 'openssl')
backup=(etc/ppp/{chap-secrets,pap-secrets,options,ip-up,ip-down,ip-down.d/00-dns.sh,ip-up.d/00-dns.sh,ipv6-up.d/00-iface-config.sh})
source=(https://download.samba.org/pub/ppp/ppp-$pkgver.tar.gz{,.asc}
        ppp-2.4.6-makefiles.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
        LICENSE)

prepare() {
  cd $pkgname-$pkgver

  patch -p1 -i "$srcdir"/ppp-2.4.6-makefiles.patch

  # enable active filter
  sed -i "s:^#FILTER=y:FILTER=y:" pppd/Makefile.linux
  # enable ipv6 support
# sed -i "s:^#HAVE_INET6=y:HAVE_INET6=y:" pppd/Makefile.linux
  # Enable Microsoft proprietary Callback Control Protocol
  sed -i "s:^#CBCP=y:CBCP=y:" pppd/Makefile.linux
}

build() {
  cd $pkgname-$pkgver

  # -D_GNU_SOURCE is needed for IPv6 to work apparently
##  CFLAGS="$CPPFLAGS $CFLAGS -D_GNU_SOURCE" LDFLAGS="$LDFLAGS" ./configure --prefix=/usr
  CFLAGS="$CPPFLAGS $CFLAGS" LDFLAGS="$LDFLAGS" ./configure --prefix=/usr
  make
}

package() {
  cd $pkgname-$pkgver
  make INSTROOT="$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
}


backup=(etc/ppp/{chap-secrets,pap-secrets,options,ip-up,ip-down,ip-down.d/00-dns.sh,ip-up.d/00-dns.sh,ipv6-up.d/00-iface-config.sh})
#        ipv6-up
#        ipv6-down
#        ipv6-up.d.iface-config.sh
#  # enable ipv6 support
#  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 /
#        ppp.systemd
#  install -D -m644 "$srcdir"/ppp.systemd "$pkgdir"/usr/lib/systemd/system/ppp@.service
#  install -D -m644 "$srcdir"/ppp.systemd "$pkgdir"/usr/lib/systemd/system/ppp@.service

#---- license gpg-key sha256sums ----

license=('GPL' 'BSD')

validpgpkeys=('631E179E370CD727A7F2A33A9E4295D605F66CE9'  # Paul Mackerras (Signing key) <paulus@samba.org>
              'DE8E01561D8276A4DBFAEFCC040F1D49EC9DBB8C') # Paul Mackerras <paulus@ozlabs.org>

sha256sums=(f938b35eccde533ea800b15a7445b2f1137da7f88e32a16898d02dee8adc058d # ppp-2.4.9.tar.gz
	9f5cc230f2b2d750135bee36ec8e3c86fbf76428b9fc66b11442c585c83398e6 # ppp-2.4.9.tar.gz.asc
	91acaa378a052ac4fb0c3df20c4c5fcdb416ee437777d6668a946d27cf12ef5f # ppp-2.4.6-makefiles.patch
	c74f0e09724b90d9fbdbb921b5d6f27812d650945d6d8015f4f06089f5562d9c # options
	ddef42b2cc5d49e81556dc9dbacf5ee3bf8dc32704f3670c2233eed42c4a4efd # ip-up
	658630ba4c5cb583df80af6d4df81df8ae20798f63cc4b9cec8d4dad13a6a897 # ip-down
	aafb75b978aa13225444dc6b914fab324d686821be93c49e893800e647aa7648 # ip-up.d.dns.sh
	17b486fa69a71dafcbe543dc4f2b8cb9ed31e675aabc5f6c98ef94dbc1561c85 # ip-down.d.dns.sh
	96fd35104e3d0ec472517afecead88419913ae73ae0189476d5dad9029c2be42) #  LICENSE

