#!/bin/sh

export WITH_APACHE=yes
export WITH_MAILHEAD=yes

# Making pakage list
pkg_info | grep php5 | cut -d' ' -f1   > /tmp/p5list.$$


cp /usr/local/etc/php/extensions.ini /root/
mv /root/extensions.ini /root/extensions.ini1
echo "extension=pcre.so" >> /root/extensions.ini
echo "extension=spl.so" >> /root/extensions.ini
cat /root/extensions.ini1 >> /root/extensions.ini
rm /root/extensions.ini1


echo "/usr/ports/devel/php52-pcre" >> /tmp/p52list.$$
echo "/usr/ports/devel/php52-spl" >> /tmp/p52list.$$
for NAME in $(cat /tmp/p5list.$$ | grep -v 'php5-5.4'| sed 's/-5.4.*//' | sed 's/php5/php52/'); do
        PPATH=$(whereis -q $NAME | grep '/usr/ports')
        echo "$PPATH" >> /tmp/p52list.$$
done

export BATCH=yes
cat /tmp/p5list.$$ | xargs pkg_delete -f
make -C /usr/ports/lang/php52 reinstall clean

export FORCE_PKG_REGISTER=yes
cat /tmp/p52list.$$ | xargs  -n1 make install clean -C


mkdir -p /usr/local/etc/php
cp /root/extensions.ini /usr/local/etc/php/

sed -i "" -e 's|path php-extensions.*|path php-extensions  /usr/local/lib/php/20060613|' /usr/local/ispmgr/etc/ispmgr.conf
/usr/local/ispmgr/sbin/pkgctl cache
