Receipt for: cookutils

source stuff/avoid-gawk-warning.patch stuff/avoid-hard-link-exist-error.patch stuff/check-wok stuff/chown-typo.patch stuff/cook-newest.patch stuff/cookutils-doc.desktop stuff/overlayfs-support.patch stuff/pkgdb-absolute.patch stuff/pkgdb-no-parallel.patch stuff/protect-environment.patch stuff/repo-cooking stuff/rework-umount_aufs.patch stuff/wanted-version.patch
# SliTaz package receipt.

PACKAGE="cookutils"
VERSION="4.6"
CATEGORY="base-system"
SHORT_DESC="SliTaz packages builder new generation."
MAINTAINER="pankso@slitaz.org"
LICENSE="GPL3"
WEB_SITE="http://www.slitaz.org/"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WGET_URL="http://hg.slitaz.org/$PACKAGE/archive/$VERSION.tar.gz"
TAGS="slitaz"
HOST_ARCH="i486 arm x86_64"
CONFIG_FILES="/etc/slitaz/cook.site /etc/slitaz/cook.conf"

# busybox wget needs cacerts for https://
DEPENDS="sdft ncursesw rsync mercurial tazpkg tazlito \
advancecomp optipng pngquant svgcleaner gifsicle \
xmlstarlet desktop-file-utils-extra gettext xz cacerts"
BUILD_DEPENDS="ncursesw-dev"

SPLIT="cookutils-daemon"

# What is the latest version available today?
current_version()
{
	wget -O - http://hg.slitaz.org/$PACKAGE/ 2>/dev/null | \
	sed '/^Changeset/!d;s|.*">|http://hg.slitaz.org/'$PACKAGE'/rev/|;s|<.*||' | \
	xargs wget -O - 2>/dev/null | sed '/rev /!d;s|.*rev ||;s| .*||'
}

# Rules to configure and make the package.
compile_rules()
{
	mkdir -p $DESTDIR/usr/bin $DESTDIR/etc/slitaz
	# `make install` now builds and installs cook-tui (ncursesw front-end)
	# via the Makefile's install-tui target. cook-tui is the only
	# arch-specific (ELF) payload, so abort on failure rather than silently
	# shipping an "any"-tagged package.
	make DESTDIR=$DESTDIR install || return 1
	# The custom /bin/uname (fakes the build arch, installed by the Makefile)
	# only belongs on the official cooker (tank); strip it elsewhere so it
	# can't shadow the real uname on normal installs.
	case "$(hostname)" in tank*) ;; *) rm -f $DESTDIR/bin/uname ;; esac
	sed -i 's|://mirror.switch.ch/ftp/mirror|s://ftp.gnu.org|' $DESTDIR/etc/slitaz/cook.conf
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs
	cp $stuff/cookutils-doc.desktop $install/usr/share/applications
	cp -a $install/* $fs
	cp $stuff/check-wok $fs/usr/bin
	chmod 755 $fs/usr/bin/check-wok
	#Symlink cooker to busybox httpd server root
	cd $fs/var/www
	ln -s cgi-bin/cooker
	# Daemon goes in cookutils-daemon
	rm -rf $fs/etc/init.d
}

# Pre and post install commands for Tazpkg.
pre_install()
{
	cp $1/etc/slitaz/cook.conf $1/etc/slitaz/cook.conf.old 2> /dev/null
}

post_install()
{
	MD5="$(sed '/^SETUP_MD5/!d;s|.*="\(.*\)".*|\1|' \
			$1/etc/slitaz/cook.conf.old 2> /dev/null)"
	sed -i "s|^SETUP_MD5=\"\"|SETUP_MD5=\"$MD5\"|" $1/etc/slitaz/cook.conf
	[ -z "$MD5" ] && case "$(cat "$1/etc/hostname" 2> /dev/null)" in
	tank*)
		if ! chroot "$1/" tazpkg list | grep -q aufs ; then
			tazpkg get-install aufs --root="$1/"
			sed -i 's/LOAD_MODULES="/&aufs /' "$1/etc/rcS.conf"
		fi
		grep -q MAKE_BUNDLE "$1/etc/slitaz/cook.conf" ||
		cat >> "$1/etc/slitaz/cook.conf" <<EOT

# Also build bundle.tar.lzma on build host. May hang on http://mirror1.slitaz.org/
MAKE_BUNDLE="yes"
EOT
		sed -i 's|^\(MAKE_BUNDLE="\).*|\1yes"|' "$1/etc/slitaz/cook.conf"
		;;
	esac
}