# SliTaz package receipt.

PACKAGE="zsh"
VERSION="4.3.15"
CATEGORY="system-tools"
SHORT_DESC="Zsh shell incorporates many features of bash, ksh, and tcsh"
MAINTAINER="sandys@gmail.com"
TARBALL="$PACKAGE-$VERSION.tar.bz2"
WEB_SITE="http://zsh.sourceforge.net/"
WGET_URL="$SF_MIRROR/$PACKAGE/$TARBALL"
TAGS="shell"
BUGS="Does not support build bot: configure: error: no controlling tty\nTry running configure with --with-tcsetpgrp or --without-tcsetpgrp"

DEPENDS="ncurses zlib ncursesw"
BUILD_DEPENDS="ncurses-dev zlib-dev"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	./configure --bindir=/bin \
	--disable-dynamic --enable-multibyte \
	--enable-fndir=/usr/share/zsh/functions \
	--enable-scriptdir=/usr/share/zsh/scripts \
	$CONFIGURE_ARGS &&
	make &&
	make install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{	
	cp -a $_pkg/bin $fs

	# Config files.
	#
	mkdir $fs/etc
	cp $stuff/example.zshrc $fs/etc/zshrc
	
	#no way around this... gen_package will not automatically copy these
	mkdir -p $fs/usr/share/zsh
	cp -r $_pkg/usr/share/zsh/functions $fs/usr/share/zsh

	mkdir -p $fs/usr/share/zsh/scripts

}

# Post install commands for Tazpkg.
# Check /bin/sh stat.
#
post_install()
{
	local root
	root=$1
	echo "Processing post-install commands..."
	sh=`readlink $root/bin/sh`
	if [ ! "$sh" = "/bin/zsh" ]; then
		echo ""
		echo "**** Actual SH link : $sh"
		echo ""
		echo -n "Do you want Zsh for /bin/sh (y/N) ? : "
		read -t 30 answer < /dev/tty
		if [ "$answer" == "y" ]; then
			echo ""
			echo -n "Removin sh link to make a new one pointing on /bin/zsh..."
			rm $root/bin/sh && ln -s /bin/zsh $root/bin/sh
			status
		else
			echo ""
			echo "Leaving /bin/sh to : $sh"
		fi
	fi
}

# Restore a valid sh link if needed.
pre_remove()
{
        local root
        root=$1
        sh=`readlink $root/bin/sh`
        if [ ! "$sh" = "busybox" ]; then
                rm $root/bin/sh &&
                ln -s /bin/busybox $root/bin/sh
        fi
}