#!/bin/bash

# mandatory PHP extensions
#
exts="
    fileinfo
    gd
    iconv
    mbstring
    session
"

# optionals
#
exts="$exts
    openssl
    curl
    xml
    zip
"

if [ $# != 0 ]
then
	php_ver=$1
	shift
else
	php_ver=$(kusa-conf php.version 2>/dev/null) || {
		php_ver=$(ls /etc/php | tail -1)
	}
fi

echo "
	CHECKING EXTENSION FOR PHP VERSION: $php_ver
"

php_exts=$(php -m | fgrep -v ' ' \
	| sed -e 's/\[.*//' -e 's/^\s*$//' -e '/^$/d' \
	| tr '[A-Z]' '[a-z]' | sort -u)

for ext in $exts
do
	printf "  checking %-12s: " $ext
	pkg=$(apt-cache search php${php_ver}-$ext)
	[ "X$pkg" = "X" ] && pkg=$(apt-cache search php-$ext)
	pkg=${pkg/ */}

	printf "%-20s" "$pkg"

	echo "$php_exts" | grep -q "^$ext$" && {
		echo "ok"
		continue
	}
	echo "NOT_INSTALLED"
done

