# SliTaz package receipt.

PACKAGE="ocsinventory-agent"
VERSION="2.0.4"
CATEGORY="network"
SHORT_DESC="OCS Inventory NG agent for Linux."
MAINTAINER="erjo@slitaz.org"
SOURCE="Ocsinventory-Unix-Agent"
TARBALL="$SOURCE-$VERSION.tar.gz"
DEPENDS="perl perl-libwww perl-uri dmidecode"
SUGGESTED="nmap perl-net-ssleay"
BUILD_DEPENDS="perl wget"
WEB_SITE="http://www.ocsinventory-ng.org/"
WGET_URL="https://launchpad.net/ocsinventory-unix-agent/stable-2.0/2.0.4/+download/$TARBALL"

# Rules to configure and make the package.
compile_rules()
{
	cp $stuff/Slitaz.pm $src/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB
	cp $stuff/Tazpkg.pm $src/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging
	
	cd $src
	
	# don't run postinstall script
	rm -f run-postinst
	for p in $stuff/ocsinventory-agent-1.1.2.1.u
	do
		[ -f done.$(basename $p) ] && continue
		patch -p1 -i $p || return 1
		touch done.$(basename $p)
	done
	perl Makefile.PL 
	rm -f run-postinst
	make && make DESTDIR=$PWD/_pkg install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr \
		$fs/etc/ocsinventory-agent \
		$fs/var/lib/ocsinventory-agent
		
	cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/lib $fs/usr
}

post_install(){
	echo "Processing post-install commands..."
	cat > $1/etc/ocsinventory-agent/ocsinventory-agent.cfg <<EOT
basevardir=/var/lib/ocsinventory-agent
server=http://localhost/ocsinventory
EOT
	# We need fix missing status for dpkg
	# So we can Ocs agent can run Tazpkg.pm
	if [ ! -d $1/var/lib/dpkg ]; then
		install -o root -g root -m 0755 -d $1/var/lib/dpkg
		touch $1/var/lib/dpkg/status
	fi
}