# SliTaz package receipt v2.

PACKAGE="filature"
VERSION="0.1"
CATEGORY="development"
SHORT_DESC="SliTaz developer platform: threads, mail, bugs, commits, news"
MAINTAINER="pankso@slitaz.org"
LICENSE="BSD"
WEB_SITE="https://filature.slitaz.org/"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WGET_URL="https://hg.slitaz.org/$PACKAGE/archive/$VERSION.tar.gz"
TAGS="development bugs forum"
HOST_ARCH="i486 x86_64"

BUILD_DEPENDS="sqlite-dev gtk+3-dev pkg-config"
SPLIT="$PACKAGE-client $PACKAGE-report"
CONFIG_FILES="/etc/filature/filature.conf"
# The desktop entry belongs to filature-report only
COOKOPTS="!menus"

# Rules to configure and make the package. The dev wrapper is also
# called fil: it waits under client/ until genpkg_rules.
compile_rules()
{
	make WERROR= &&
	make DESTDIR=$DESTDIR install &&
	make -C client WERROR= &&
	make -C client DESTDIR=$DESTDIR install-report &&
	make -C client DESTDIR=$DESTDIR/client install-client
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	case "$PACKAGE" in
	filature)
		mkdir -p $fs/usr/bin $fs/usr/share
		cp -a $install/usr/bin/fil		$fs/usr/bin
		cp -a $install/usr/share/filature	$fs/usr/share
		cp -a $install/usr/share/doc		$fs/usr/share
		cp -a $install/etc			$fs
		DEPENDS="libsqlite" ;;
	filature-client)
		SHORT_DESC="Filature client: fil commands over SSH, messages in your editor"
		CATEGORY="development"
		mkdir -p $fs/usr/bin
		cp -a $install/client/usr/bin/fil	$fs/usr/bin
		cp -a $install/client/usr/share	$fs/usr
		# The same /usr/bin/fil as the server, on purpose: a dev machine
		# never runs the server. cook's split check warns about it.
		DEPENDS="" ;;
	filature-report)
		SHORT_DESC="Report a bug to the SliTaz developers (console and GTK3)"
		CATEGORY="system-tools"
		mkdir -p $fs/usr/bin $fs/usr/share
		cp -a $install/usr/bin/filature-report*	$fs/usr/bin
		cp -a $install/usr/share/applications	$fs/usr/share
		cp -a $install/usr/share/icons		$fs/usr/share
		DEPENDS="gtk+3" ;;
	esac
}

# fil is setgid filature, the group that owns the database: no dev can
# read the private messages directly (doc/DECISIONS.md, section 5).
post_install_filature()
{
	grep -q '^filature:' "$1/etc/group" ||
		chroot "$1/" addgroup -S filature
	grep -q '^filature:' "$1/etc/passwd" ||
		chroot "$1/" adduser -S -D -H -h /var/lib/filature -s /bin/false \
			-G filature filature
	chroot "$1/" chown root:filature /usr/bin/fil
	chmod 2755 "$1/usr/bin/fil"
	mkdir -p "$1/var/lib/filature" "$1/etc/filature/hooks"
	chroot "$1/" chown root:filature /var/lib/filature
	chmod 2770 "$1/var/lib/filature"
	if [ ! -f "$1/var/lib/filature/filature.db" ]; then
		touch "$1/var/lib/filature/filature.db"
		chroot "$1/" chown filature:filature /var/lib/filature/filature.db
		chmod 660 "$1/var/lib/filature/filature.db"
	fi
	:
}
