# Maintainer: Thomas Bächler <thomas@archlinux.org>

pkgname=openvpn
pkgver=2.1.4
pkgrel=1
pkgdesc="An easy-to-use, robust, and highly configurable VPN (Virtual Private Network)"
arch=('i686' 'x86_64')
url="http://openvpn.net/index.php/open-source.html"
depends=('openssl' 'lzo2')
license=('custom')
backup=('usr/share/openvpn/easy-rsa/vars'
        'usr/share/openvpn/easy-rsa/openssl.cnf')
source=("http://swupdate.openvpn.net/community/releases/openvpn-$pkgver.tar.gz"
        "rc.$pkgname")
md5sums=('96a11868082685802489254f03ff3bde'
         'd8f9c4b986fd6bac247c97ed4fa83e43')

build() {
  cd $srcdir/$pkgname-$pkgver
  
  # Build and install openvpn
  CFLAGS="$CFLAGS -DPLUGIN_LIBDIR=\\\"/usr/lib/openvpn\\\"" ./configure --prefix=/usr --enable-password-save --mandir=/usr/share/man
  make
}

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

  install -dm755 $pkgdir/etc/openvpn

  # Install examples
  install -dm755 $pkgdir/usr/share/openvpn
  cp -r sample-config-files $pkgdir/usr/share/openvpn/examples
  find $pkgdir/usr/share/openvpn -type f -exec chmod 644 {} \;
  find $pkgdir/usr/share/openvpn -type d -exec chmod 755 {} \;
  
  # Install license
  install -Dm644 COPYING $pkgdir/usr/share/licenses/$pkgname/COPYING
  
  # Build and install plugins
  for plug in auth-pam down-root ; do
    cd $srcdir/$pkgname-$pkgver/plugin/$plug
    make
    install -Dm755 $pkgname-$plug.so $pkgdir/usr/lib/$pkgname/$pkgname-$plug.so
  done
  
  # Install easy-rsa
  cd $srcdir/$pkgname-$pkgver
  make -C easy-rsa/2.0 install DESTDIR=$pkgdir PREFIX=usr/share/openvpn/easy-rsa
  
  # Install rc scripts
  install -Dm755 $srcdir/rc.$pkgname $pkgdir/etc/$pkgname/rc.openvpn.TEMPLATE
}

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