#!/bin/sh

export LANG=C


if [ "X${SB_CONFIGURE_VERBOSE}" = "X1" ]; then
    set -xv
fi

MODE=$2

deinstall_etc() {
    rm -f /etc/swsoft/sitebuilder/sitebuilder.conf
    # Attempt to remove sitebuilder directory, should successed
    rmdir /etc/swsoft/sitebuilder || true
    # Attempt  to remove swsoft directory, may fail if plesk is installed
    rmdir /etc/swsoft || true
}

deinstall_cron() {
    local FILE_CRONTAB="/etc/crontab"
    if grep -q "tasksmng.php" $FILE_CRONTAB; then
	sed -i '' \
	    -e '/update_key.php/d' \
	    -e '/sip2.php/d' \
    	    -e '/sip1.php/d' \
	    -e '/tasksmng.php/d' \
	    -e '/clear_trial_sites.php/d' $FILE_CRONTAB
    fi
}

# only post deinstall
case "X$MODE" in
    XPOST-DEINSTALL)
		deinstall_etc ;
		deinstall_cron ;
		rm -f /usr/local/bin/sb_config	
	;;
    XDEINSTALL)
		:
	;;
    *)
		:
	;;
esac

exit 0
