#----------------------------------------------------------------------
#
# copyright (C) Decaux Nicolas Aka 'GawiNDX'
# contributor: Nicolas Decaux <decauxnico@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#----------------------------------------------------------------------
#Mozus Download Update Script
{
	use esmith::db;
    use esmith::config;
    use esmith::ConfigDB;
	
	$OUT = "";
	my $mozus_db = esmith::ConfigDB->open_ro('Mozus');
	
	my $schedule_mode = $mozus_db->get_prop('Scheduler', 'Mode') || 'Monthly';
	my $moz_daily = $mozus_db->get_prop('Scheduler', 'Daily') || '0,0';
	my $moz_weekly =$mozus_db->get_prop('Scheduler', 'Weekly') || '0,0,0';
	my $moz_dweekly = $mozus_db->get_prop('Scheduler', 'DWeekly') || '0,0,0';
	my $moz_monthly = $mozus_db->get_prop('Scheduler', 'Monthly') || '1,0,0';
	my $Boot_sync = $mozus_db->get_prop('Scheduler', 'Boot_Sync') || 'enabled';
	my @Daily = split(',',$moz_daily);
	my @Weekly = split(',',$moz_weekly);
	my @DWeekly = split(',',$moz_dweekly);
	my @Monthly = split(',',$moz_monthly);
	my $cron_hour = "*";
	my $cron_minutes = "*";
	my $cron_day = "*";
	my $cron_month ="*";
	my $cron_day_week ="*";
	my $reboot = "\@reboot";
	my $cmdline = "/opt/mozilla-updates/mozmirrorupdates update";
	
	if ( $Boot_sync eq 'enabled'){
		$OUT .= "$reboot root sleep 60 && $cmdline\n";
	}
	if ($schedule_mode ne 'None'){
		if ( $schedule_mode eq 'Daily'){
			$cron_hour = $Daily[0];
			$cron_minutes = $Daily[1];
		}elsif ( $schedule_mode eq 'Weekly' ){
			$cron_day_week = $Weekly[0];
			$cron_hour = $Weekly[1];
			$cron_minutes = $Weekly[2];
		}elsif ( $schedule_mode eq 'DoubleWeekly' ){
			$cron_day = "1-7,15-21";
			$cron_day_week = "$DWeekly[0]";
			$cron_hour = $DWeekly[1];
			$cron_minutes = $DWeekly[2];
		}elsif ( $schedule_mode eq 'Monthly' ){
			$cron_day = $Monthly[0];
			$cron_hour = $Monthly[1];
			$cron_minutes = $Monthly[2];
		}
		$OUT .= "$cron_minutes $cron_hour $cron_day $cron_month $cron_day_week root $cmdline\n";
	}
}

