# Maintainer: Joseph Graham <joseph@xylon.me.uk>

pkgname=pacman2pacman
pkgver=20170705.1
pkgdesc="A plugin for pacman to download packages by bittorrent and seed them back up"
url="https://wiki.parabolagnulinux.org/Pacman2pacman"
license=('GPL')

options=(emptydirs)
install=$pkgname.install
backup=('etc/pacman2pacman.conf')

pkgrel=1
arch=(any)
depends=(transmission-cli)
source=("https://repo.parabola.nu/other/$pkgname/$pkgname-$pkgver.tar.gz")
md5sums=('4ad263b2f438589567dbbfe8bfe7fe9d')

_gitver='commit=b3e6461c5b9da4612fc87be5118b848fcc22e097'
mksource=("$pkgname-$pkgver::git://git.parabola.nu/pacman2pacman.git/#$_gitver")
mkmd5sums=('SKIP')

package() {
  cd $pkgname-$pkgver

  mkdir -p "${pkgdir}/srv/pacman2pacman/torrents"

  mkdir -p "${pkgdir}/srv/pacman2pacman/dbcache"

  chown -R transmission "${pkgdir}/srv/pacman2pacman/"

  mkdir -p "${pkgdir}/usr/bin" "${pkgdir}/etc"

  cp pacman2pacman-get "${pkgdir}/usr/bin"

  cp pacman2pacman.conf "${pkgdir}/etc"

  chmod +x "${pkgdir}/usr/bin/pacman2pacman-get"

  for dir in translations/*
  do
      if [[ -d "${dir}" ]]
      then
          mkdir -p "${pkgdir}/usr/share/locale/${dir#*/}/LC_MESSAGES/"
          msgfmt -o "${pkgdir}/usr/share/locale/${dir#*/}/LC_MESSAGES/pacman2pacman-get.mo" "${dir}/pacman2pacman-get.po"
      fi
  done
}
