# Maintainer: Valeria Fadeeva <valeria@fadeeva.me>

_gitname="$(basename $(pwd))"
pkgname=("$_gitname")
pkgver=1.23
pkgrel=1
pkgdesc="$(head -n 2 README.md | tail -n 1)"
arch=('any')
url="https://git.melawy.ru/Updater/$_gitname"
license=('AGPL')
depends=("pacman" "gnupg")
optdepends=()
makedepends=("git")
backup=()
provides=("${pkgname}")
conflicts=("${pkgname}")
source=("git+$url.git")
sha256sums=("SKIP")
validpgpkeys=('BC8B600E8DDA1F4CB77B10D2BA803A261A5EE6B8')

# pkgver() {
#       cd "$srcdir/$_gitname"
#       printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
# }

pkgver() {
        cd "$srcdir/$_gitname"
        printf "1.%s" "$(git rev-list --count HEAD)"
}

build() {
  cd "$_gitname"
  cargo build --release
}

package() {
  install -dm755 "${pkgdir}/etc/arch-linux-updater/"
  install -m644 "${srcdir}/$_gitname/.env" "${pkgdir}/etc/arch-linux-updater/"

  install -dm755 "${pkgdir}/usr/bin/"
  install -m755 "${srcdir}/$_gitname/target/release/arch-linux-updater" "${pkgdir}/usr/bin/"

  install -dm755 "${pkgdir}/usr/share/arch-linux-updater/"
  cp -rf "${srcdir}/$_gitname/assets" "${pkgdir}/usr/share/arch-linux-updater/"

  install -dm750 "${pkgdir}/etc/sudoers.d/"
  install -m644 "${srcdir}/$_gitname/melawy-arch-linux-updater" "${pkgdir}/etc/sudoers.d/"
}
