# Maintainer: moparisthebest <admin dot archlinux AT moparisthebest dot com>

pkgname=wireguard-proxy-git
pkgver=0.1.1.r21.g225d71d
pkgrel=1
pkgdesc="proxy wireguard over TCP/TLS."
url="https://code.moparisthebest.com/moparisthebest/wireguard-proxy"
depends=('openssl')
makedepends=('cargo' 'git')
provides=('wireguard-proxy')
conflicts=('wireguard-proxy')
arch=('i686' 'x86_64' 'armv7h' 'armv6h')
license=('MIT' 'Apache')
backup=('etc/wireguard-proxy/server.conf' 'etc/wireguard-proxy/client.conf')
source=("$pkgname::git+https://code.moparisthebest.com/moparisthebest/wireguard-proxy.git#branch=openssl")
validpgpkeys=('81F1C22DD41109D4A9C0A7B5B070F8D97D1A0BBA') # moparisthebest <admin AT moparisthebest.com>
sha256sums=(SKIP)
conflicts=(wireguard-proxy)
provides=(wireguard-proxy=$pkgver)

pkgver() {
  cd "$pkgname"
  git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "$pkgname"
  cargo fetch
}

build() {
  cd "$pkgname"
  cargo build --offline --release --features tls
}

package() {
  cd "$pkgname"
  install -Dm755 target/release/wireguard-proxy "$pkgdir/usr/bin/wireguard-proxy"
  # udp-test is optional, remove if you want
  install -Dm755 target/release/udp-test "$pkgdir/usr/bin/udp-test"
  install -Dm644 LICENSE-APACHE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE-APACHE"
  install -Dm644 LICENSE-MIT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE-MIT"
  install -Dm644 systemd/server.conf "${pkgdir}/etc/wireguard-proxy/server.conf"
  install -Dm644 systemd/client.conf "${pkgdir}/etc/wireguard-proxy/client.conf"
  install -Dm644 systemd/wireguard-proxy@.service "${pkgdir}/usr/lib/systemd/system/wireguard-proxy@.service"
}
