# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgname=deepin-daemon
pkgver=5.0.0
pkgrel=2
pkgdesc='Daemon handling the DDE session settings'
arch=('x86_64')
url="https://github.com/linuxdeepin/dde-daemon"
license=('GPL3')
depends=('deepin-desktop-schemas' 'deepin-api' 'gvfs' 'iso-codes' 'lsb-release'
         'mobile-broadband-provider-info' 'deepin-polkit-agent'
         'deepin-polkit-agent-ext-gnomekeyring' 'udisks2' 'upower'
         'libxkbfile' 'accountsservice' 'deepin-desktop-base' 'bamf' 'pulseaudio'
         'gnome-keyring' 'noto-fonts' 'imwheel')
makedepends=('golang-github-linuxdeepin-go-dbus-factory' 'golang-deepin-gir' 'golang-deepin-lib'
             'golang-deepin-dde-api' 'golang-github-nfnt-resize' 'sqlite' 'deepin-gettext-tools'
             'git' 'mercurial' 'python-gobject' 'networkmanager' 'bluez' 'go-pie')
optdepends=('networkmanager: for network management support'
            'bluez: for bluetooth support'
            'iw: for miracast module'
            'proxychains-ng: for proxy configuration module')
conflicts=('dde-daemon')
replaces=('dde-daemon')
groups=('deepin')
install="${pkgname}.install"
source=("$pkgname-$pkgver.tar.gz::https://github.com/linuxdeepin/dde-daemon/archive/$pkgver.tar.gz"
        https://raw.githubusercontent.com/jouyouyun/tap-gesture-patches/master/patches/dde-daemon_3.8.0.patch
        'deepin-daemon.sysusers')
sha512sums=('b0247fb8e529bac387b1ce53a448eb8078cb4b2c2dee01b9388d344b366b67abb981efc43bfdd65ff0a91102009feee3f48bc5c7af689a85f30a33a96e3d7a3b'
            '334839a8136cad44aadb4c97be29ae89f8a1106928175b9bd9115051b34d52cb468902636a67bae8685888bdfe8d8ae195cf8df2b9e93e480f3f008494942e74'
            '808c02d4fec4cbbb01119bbb10499090199e738b7dd72c28a57dde098eef6132723f3434c151f79e21d9f788c7f7bae8046573ac93ba917afe0e803fbffa6d5a')

prepare() {
  cd dde-daemon-$pkgver
  patch -p1 -i ../dde-daemon_3.8.0.patch

  export GOPATH="$srcdir/build:/usr/share/gocode"

  # golang-deepin-lib's dependency, remove when go packaging resumes
  go get github.com/cryptix/wav

  go get gopkg.in/yaml.v2 github.com/axgle/mahonia github.com/msteinert/pam github.com/gosexy/gettext

  sed -i 's#/usr/share/backgrounds/default_background.jpg#/usr/share/backgrounds/deepin/desktop.jpg#' accounts/user.go
}

build() {
  cd dde-daemon-$pkgver
  make -C network/nm_generator gen-nm-code
  make
}

package() {
  cd dde-daemon-$pkgver
  make DESTDIR="$pkgdir" PAM_MODULE_DIR=usr/lib/security install

  mv "$pkgdir"{,/usr}/lib/systemd
  rmdir "$pkgdir"/lib

  install -Dm644 ../deepin-daemon.sysusers "$pkgdir/usr/lib/sysusers.d/deepin-daemon.conf"
}
