# SliTaz package receipt.

PACKAGE="phpmyadmin"
VERSION="3.4.10.1"
CATEGORY="misc"
SHORT_DESC="Administration of MySQL over the Web."
MAINTAINER="pascal.bellard@slitaz.org"
PHPMYADM="phpMyAdmin-$VERSION-all-languages"
TARBALL="$PHPMYADM.tar.bz2"
WEB_SITE="http://www.phpmyadmin.net/"
WGET_URL="$SF_MIRROR/$PACKAGE/$TARBALL"
SUGGESTED="php-mcrypt"
DEPENDS="php-mysqli"
CONFIG_FILES="/etc/phpmyadmin/config.inc.php"

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/share/phpmyadmin $fs/etc/phpmyadmin $fs/usr/share/applications
	cp -a $src/. $fs/usr/share/phpmyadmin
	ln -s /etc/phpmyadmin/config.inc.php $fs/usr/share/phpmyadmin/config.inc.php
	cp $src/config.sample.inc.php $fs/etc/phpmyadmin/config.inc.php
	rm -f $fs/usr/share/phpmyadmin/phpMyAdmin-$VERSION-all-languages
	cp $stuff/phpmyadmin.desktop $fs/usr/share/applications
	chown -R www.www $fs/usr/share/phpmyadmin $fs/etc/phpmyadmin
	chmod 700 $fs/etc/phpmyadmin
	chmod 644 $fs/etc/phpmyadmin/config.inc.php
	
	sed -i s'/\?>//' $fs/etc/phpmyadmin/config.inc.php
	
	cat <<"EOT">> $fs/etc/phpmyadmin/config.inc.php

$cfg['McryptDisableWarning'] = true;
// For public use you may comment the following lines 
// to enforce the security.
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;
$cfg['Servers'][$i]['AllowRoot'] = true;
?>
EOT
}

post_install()
{
	# Configure lighttpd server
	if [ -f $1/etc/lighttpd/lighttpd.conf ]; then
		if ! grep -q /usr/share/phpmyadmin/ $1/etc/lighttpd/lighttpd.conf; then
	    		sed -e 's|.*"/examples/" => "/usr/share/examples/",|    "/examples/" => "/usr/share/examples/",\n    "/phpmyadmin/" => "/usr/share/phpmyadmin/",|g' -i $1/etc/lighttpd/lighttpd.conf
			if [ -z "$1" ]; then
				# Start Web server.
				/etc/init.d/lighttpd stop
				/etc/init.d/lighttpd start
			fi
		fi
	fi
	# Configure apache server
	if [ -f $1/etc/apache/httpd.conf ]; then
		if [ ! -f $1/etc/apache/conf.d/phpmyadmin ]; then
			cat > $1/etc/apache/conf.d/phpmyadmin <<EOT
<IfModule mod_alias.c>
    Alias /phpmyadmin /usr/share/phpmyadmin
</IfModule>
<DirectoryMatch /usr/share/phpmyadmin/>
    DirectoryIndex index.php
    Options +FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</DirectoryMatch>
EOT
			if [ -z "$1" ]; then
				# Start Web server.
				/etc/init.d/apache stop
				/etc/init.d/apache start
			fi
		fi
	fi
}