#!/bin/bash

for dir in /work/www/*/
do
        # Wordpress
        if [ -f $dir/wp-cron.php ]
        then
                echo "Wordpress CRON $dir/wp-cron.php"
                /usr/bin/php $dir/wp-cron.php

        	if [ -f $dir/wp-config.php ]
        	then
                	# controllo la presenza del flag DISABLE_WP_CRON
                	if ! grep -q "DISABLE_WP_CRON" $dir/wp-config.php
                	then
                        	echo "" >> $dir/wp-config.php
                        	echo "define('DISABLE_WP_CRON', true);" >> $dir/wp-config.php
                	fi
	
                	# controllo la presenza del flag FS_METHOD
                	if ! grep -q "FS_METHOD" $dir/wp-config.php
                	then
                        	echo "" >> $dir/wp-config.php
                        	echo "define('FS_METHOD', 'direct');" >> $dir/wp-config.php
                	fi
	
                	# controllo la presenza del flag WP_AUTO_UPDATE_CORE
                	if ! grep -q "WP_AUTO_UPDATE_CORE" $dir/wp-config.php
                	then
                        	echo "" >> $dir/wp-config.php
                        	echo "define('WP_AUTO_UPDATE_CORE', 'minor');" >> $dir/wp-config.php
                	fi
		fi
        fi

        # vTiger
        if [ -f $dir/cron/vtigercron.sh ]
        then
                echo "vTiger CRON $dir/cron/vtigercron.sh"
                chmod 755 $dir/cron/vtigercron.sh
                $dir/cron/vtigercron.sh
        fi
done

