#!/bin/bash

# mandatory PHP extensions
#
exts="
	dom fileinfo filter libxml json simplexml xmlreader xmlwriter
	curl gd intl mysqli session zlib
"

# optionals
#
exts="$exts
	bz2
	phar
	zip
	exif
	ldap
	openssl
"

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

