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

pkgname=vpnc
_vpnc_commit=46b8335b6e0df577fd3c40e87362ed8c5724c8df
_vpncscripts_commit=22756827315bc875303190abb3756b5b1dd147ce
pkgver=%version%
pkgrel=%release%
epoch=1
pkgdesc='VPN client for cisco3000 VPN Concentrators'
url='https://github.com/streambinder/vpnc'
arch=('x86_64')
license=('GPL')
depends=('libgcrypt' 'openssl' 'iproute2' 'which')
optdepends=('perl: for pcf2vpnc')
makedepends=('git')
optdepends=('openresolv: Let vpnc manage resolv.conf')
backup=('etc/vpnc/default.conf')
source=("vpnc::git+https://github.com/streambinder/vpnc#commit=${_vpnc_commit}"
        "vpnc-scripts::git+https://gitlab.com/openconnect/vpnc-scripts.git#commit=${_vpncscripts_commit}"
        git+https://github.com/streambinder/vpnc.wiki.git
        vpnc.conf
        vpnc@.service)
sha512sums=('SKIP'
            'SKIP'
            'SKIP'
            'ac70712192c01ff638a9badc5cff7105bee5c4fed5d3a3b728e9597661952d156041c82fe1e544e2bab602d193d4105d3689c79c46d964623f6ce38dd89f0ea7'
            'cafcab676986c1a2e49441f01d61997f1c6b54bbb68661b9af007d4816f8e76eee6b7ac2dfab55b55965fa407e8331c663cf11aa79384c30b0c9049c1477b791')

pkgver() {
  cd ${pkgname}
  printf "%s.r%s.r%s" "$(grep '^VERSION' Makefile|sed 's|VERSION := ||')" \
    "$(git -C ../vpnc rev-list --count HEAD)" \
    "$(git -C ../vpnc-scripts rev-list --count HEAD)"
}

prepare() {
  cd ${pkgname}

  git submodule init
  git config submodule."src/doc".url "${srcdir}/vpnc.wiki"
  git -c protocol.file.allow=always submodule update --recursive

  # Build hybrid support
  sed 's|^#OPENSSL|OPENSSL|g' -i Makefile
  # fix resolvconf location for community/openresolv
  sed 's|/sbin/resolvconf|/usr/bin/resolvconf|g' -i ../vpnc-scripts/vpnc-script
  ln -sf ../../vpnc-scripts/vpnc-script src
  ln -sf ../../vpnc.conf src
}

build() {
  make -C ${pkgname}
}

check() {
  make -C ${pkgname} test
}

package() {
  cd ${pkgname}
  install -d "${pkgdir}/usr/share/doc/${pkgname}"
  make DESTDIR="${pkgdir}" PREFIX=/usr SBINDIR=/usr/bin install
  install -Dm 755 ../vpnc-scripts/vpnc-script -t "${pkgdir}/etc/vpnc"
  install -Dm 644 ../vpnc@.service -t "${pkgdir}/usr/lib/systemd/system"
  install -Dm 644 .github/README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
