# Maintainer: fauno <fauno@parabola.nu>

_pkgname=discosrv
pkgname=${_pkgname}-git
pkgver=2014.12.27
pkgrel=1
pkgdesc="Discovery server for syncthing"
url="https://github.com/syncthing/discosrv"
license=('GPL3' 'custom:BSD1' 'custom:BSD3' 'Apache')
arch=('i686' 'x86_64')
depends=('glibc')
makedepends=('git' 'go' 'godep')
install=${_pkgname}.install
source=(https://repo.parabola.nu/other/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        ${_pkgname}.service)
md5sums=('4ddae1dd5cb4745953e97d7537ad36c3'
         'SKIP'
         '511efdc439b909da5cc7e3037b2a4391')

mksource() {
  set -o pipefail
  mkdir -p "${pkgname}-${pkgver}"
  export GOPATH="${srcdir}/${pkgname}-${pkgver}"

  go get -d github.com/syncthing/discosrv
}

build() {
  export GOPATH="${srcdir}/${pkgname}-${pkgver}"
  cd "${srcdir}/${pkgname}-${pkgver}/src/github.com/syncthing/${_pkgname}"
  go build
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}/src/github.com/syncthing/${_pkgname}"
  install -D -m 755 ${_pkgname} "${pkgdir}/usr/bin/${_pkgname}"

  for license in "${srcdir}/${pkgname}-${pkgver}"/src/*/*/*/LICENSE; do
    local dir="$(dirname "${license}")"
    install -Dm 644 "${license}" "${pkgdir}/usr/share/licenses/${pkgname}/${dir##*/}/LICENSE"
  done

  install -dm750 --owner nobody --group nobody ${pkgdir}/var/discosrv
  install -Dm644 ${srcdir}/${_pkgname}.service ${pkgdir}/usr/lib/systemd/system/${_pkgname}.service
}
