# Maintainer: Márcio Silva <coadde@lavabit.com>

_pkgname=lvpn
pkgname=librevpn
pkgver=0.0.3
pkgrel=1
pkgdesc='Free Virtual Network with tinc2dot and generate-ipv6-address'
url=http://$pkgname.org.ar/
license=("AGPL3:($_pkgname, tinc2dot)" 'MIT:(generate-ipv6-address)')
arch=(mips64el x86_64 i686)
depends=(avahi bash tinc)
optdepends=(
  'graphviz: for graph and tinc2dot'
  'libnatpmp: (AUR)'
  miniupnpc
  networkmanager
  'python2: for avahi-publish-alias'
  python2-bottle
  'ruby: for graph'
  sudo
)
source=http://repo.hackcoop.com.ar/$pkgname.git/snapshot/$pkgname-$pkgver.tar.xz
sha512sums=96a0de4e35d1fd45652c4b7ee25d7335d9b3816065b48e978274845c328b68a03623abf812119af34f1856bd05170cac8ad59f233fc3dcd63ea6c84c89a80968

build() {
  cd $srcdir/$pkgname-$pkgver

  msg "BUGFIX: Fixing Makefile with sed:"
  msg " * Removing generate-ipv6-address, natpmp and upnpc build softwares"
  msg " * Fixing wrong man-pages patch"
  msg " * Removing useless pacman-scripts (or lvpn) patch (TEXTDOMAIN)"
  sed -i '\|generate-ipv6-address|d;\|natpmp|d;\|upnpc|d;
          s|/share/man1|/share/man/man1|;
          s|$(TARGET)$(TEXTDOMAINDIR)/$(TEXTDOMAIN)|$(TARGET)$(TEXTDOMAINDIR)|;
         ' Makefile

  msg "Building '$pkgname'"
  make PREFIX=/usr NETWORK=lvpn

  msg "Building 'generate-ipv6-address'"
  cd etc/generate-ipv6-address-0.1
  sed -i 's|`uname -m`-||;s|/man/man8|/share/man/man8|' Makefile
  make PREFIX=/usr
}

package() {
  cd $srcdir/$pkgname-$pkgver
  make PREFIX=$pkgdir/usr TEXTDOMAINDIR=$pkgdir/usr/share/locale install

  msg 'Installing scripts files'
  msg 'Note: graph scrip conflicts with plotutils on /usr/bin'
  install -vm755 bin/avahi-publish-alias $pkgdir/usr/bin
  install -vm755 bin/graph               $pkgdir/usr/bin/$_pkgname-graph
  install -vm755 bin/tinc2dot            $pkgdir/usr/bin # tinc2dot 0.2.1 script
  install -vm755 bin/cronjob             $pkgdir/usr/bin/fauno-cronjob # fauno script

  msg 'BUGFIX: Installing doc files'
  _doc=(es)
  for _md in ${_doc[@]};do
    install -vd $pkgdir/usr/share/{doc,$_pkgname/doc/$_md}
    install -vm644 doc/$_md/*.markdown $pkgdir/usr/share/$_pkgname/doc/$_md
    ln -vs ../$_pkgname/doc $pkgdir/usr/share/doc/$_pkgname
  done

  msg 'BUGFIX: Installing locale files'
  _locales=(en)
  for _po in ${_locales[@]}; do
    install -vd $pkgdir/usr/share/locale/$_po/LC_MESSAGES
    msgfmt -o $pkgdir/usr/share/locale/$_po/LC_MESSAGES/$_pkgname.mo locale/$_po.po
  done

  #msg 'BUGFIX: Removing useless pacman-scripts dir'
  #rmdir -v $pkgdir/usr/share/locale/pacman-scripts

  msg 'BUGFIX: Creating NetworkManager dir, due which fail without NetworkManager software'
  install -d $pkgdir/etc/NetworkManager/dispatcher.d

  msg 'Installing license files'
  install -vDm644 LICENSE $pkgdir/usr/share/licenses/$pkgname/COPYING

  msg 'Installing "generate-ipv6-address" files'
  cd etc/generate-ipv6-address-0.1
  make PREFIX=$pkgdir/usr TEXTDOMAINDIR=$pkgdir/usr/share/locale install
}

# vim:set ts=2 sw=2 et: