# SliTaz package receipt.

PACKAGE="cups-pam"
VERSION="1.4.6"
CATEGORY="system-tools"
SHORT_DESC="Common UNIX Printing System with pam support."
MAINTAINER="pascal.bellard@slitaz.org"
DEPENDS="openssl slitaz-base-files gnutls ghostscript dbus jpeg libpng tiff \
zlib pam libcomerr libkrb5 acl libcomerr3"
BUILD_DEPENDS="openssl-dev gnutls-dev ghostscript dbus-dev pam pam-dev acl-dev"
SOURCE="cups"
TARBALL="$SOURCE-$VERSION-source.tar.bz2"
WEB_SITE="http://www.cups.org/"
WGET_URL="http://ftp.rz.tu-bs.de/pub/mirror/ftp.easysw.com/ftp/pub/cups/$VERSION/$TARBALL"
PROVIDE="cups:pam"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--enable-static \
		--enable-pam \
		--disable-ldap \
		--with-cups-user=nobody \
		--with-cups-group=nogroup \
		--with-languages="de es fr" \
		$CONFIGURE_ARGS &&
	make &&
	make BUILDROOT=$PWD/_pkg install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/etc $fs/usr/lib $fs/usr/share/pixmaps
	
	cp -a $_pkg/etc/cups $fs/etc
	cp -a $_pkg/etc/dbus* $fs/etc
	cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/sbin $fs/usr
	cp -a $_pkg/usr/lib/*.so* $fs/usr/lib
	cp -a $_pkg/usr/lib/cups $fs/usr/lib
	cp -a $_pkg/usr/share/cups $fs/usr/share
	cp -a $_pkg/usr/share/icons/hicolor/32x32/apps/cups.png \
		 $fs/usr/share/pixmaps
	cp -a $_pkg/var $fs
	
	# We need the doc for CSS, images and help in the web interface.
	cp -a $_pkg/usr/share/doc $fs/usr/share

	# tazwok does not strip files other than .so in usr/lib
		
	for dir in $fs/usr/lib/cups
	do
		if [ -d "$dir" ]; then
			find $dir -type f -exec strip -s '{}' 2>/dev/null \;
		fi
	done
	
	# PAM conf
	cp -a $stuff/* $fs

	# Daemon script
	cp -a $WOK/cups/stuff/etc $fs
}

# Start cups daemon and edit daemons.conf.
post_install()
{
	local root
	root=$1
	if [ -z "$root" ]; then
		/etc/init.d/cupsd start || continue
	fi
	if ! grep -q ^CUPSD_OPTIONS $root/etc/daemons.conf; then
		echo '# Cups printing daemon options.' >> $root/etc/daemons.conf
		echo 'CUPSD_OPTIONS=""' >> $root/etc/daemons.conf
		echo '' >> $root/etc/daemons.conf
	fi
}

# Stop cups daemon before rm.
pre_remove()
{
	/etc/init.d/cupsd stop
}

# Overlap busybox
pre_install()
{
	rm -f $1/usr/bin/lpr
}

post_remove()
{
	ln -s /bin/busybox /usr/bin/lpr
}