# Copyright     : Obarun
#------------------------
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
#----------------
# Pkgbuild Src  : https://git.obarun.org/pkg/obcore/rpcbind
#--------------------------------------------------------------
# DESCRIPTION ]

pkgname=rpcbind
pkgver=1.2.6
pkgrel=3
pkgdesc="portmap replacement which supports RPC over various protocols"
url='http://rpcbind.sourceforge.net'

source=(
    "https://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver.tar.bz2"
    rpcbind-sunrpc.patch
    rpcbind.conf
    rpcbind.tmpfiles
    rpcbind.sysusers
    CVE-2017-8779.diff
)   ## see also http://git.linux-nfs.org/?p=steved/rpcbind.git;a=summary

#----------------------
# BUILD CONFIGURATION ]

depends=(
    'bash'
    'glibc'
    'libtirpc'
)
backup=(
    'etc/conf.d/rpcbind'
)
replaces=(
    'portmap'
)

#----------------
# BUILD PREPARE ]

prepare() {
    cd $pkgname-$pkgver

    ## patch for iana services file # FS#20273
    patch -Np1 -i ../rpcbind-sunrpc.patch

    ## http://seclists.org/oss-sec/2017/q2/209
    patch -Np1 -i ../CVE-2017-8779.diff
}

#----------------
# BUILD CONTROL ]

_flags=(
    --prefix=/usr
    --sbindir=/usr/bin
    --with-rpcuser=rpc
    --enable-warmstarts
    --with-statedir=/var/lib/rpcbind
    --enable-rmtcalls
    --with-systemdsystemunitdir=no
)

#--------
# BUILD ]

build() {
    cd $pkgname-$pkgver

    ./configure "${_flags[@]}"
    make
}

#----------
# PACKAGE ]

package() {
    cd $pkgname-$pkgver

    make DESTDIR="$pkgdir" install

    ## install rpcbind config file
    install -D -m644 "$srcdir"/rpcbind.conf "$pkgdir"/etc/conf.d/rpcbind

    ## install missing man page - https://bugs.archlinux.org/task/21271
    install -m644 man/rpcinfo.8 "$pkgdir"/usr/share/man/man8/

    ## add state directory
    #install -d -m 700 -o 32 -g 32 "$pkgdir"/var/lib/rpcbind

    install -D -m644 "$srcdir"/rpcbind.tmpfiles "$pkgdir"/usr/lib/tmpfiles.d/rpcbind.conf
    install -D -m644 "$srcdir"/rpcbind.sysusers "$pkgdir"/usr/lib/sysusers.d/rpcbind.conf

    ## install license
    install -D -m644 COPYING "$pkgdir"/usr/share/licenses/rpcbind/COPYING
}

#--------------------
# ARCH LICENSE AUTH ]

arch=(x86_64)
license=(custom)

sha512sums=('')
