#!/home/product/code/webui-perl/bin/perl -T -I /home/product/code/firmware/current/lib/perl5
#SUDOER_USERS: nobody
#SUDOER_RUNAS_USERS: root, mta
#SUDOER_TAGS: NOPASSWD, EXEC
use strict;
use warnings;
use Barracuda::Sudo::Lib;

=pod

=head1 NAME

notice_agent_init

=head1 DESCRIPTION

Wraps calls to mkdir, chmod, and ln -sf in _init in NoticeAgent.pm

=cut

my $path      = "/etc/barracuda/notices/";
my $cron_file = "/etc/cron.daily/email_notices";
my $log_file  = "/etc/barracuda/notices/notices.log"; 

if( !-e $path ) {
    my $MKDIR = "/bin/mkdir";
    my $CHMOD = "/bin/chmod";
    my $MODE  = "777";

    system_succeed($MKDIR, $path);
    system_succeed($CHMOD, $MODE, $path);

    open(my $fh, ">", $log_file) or die "Unable to create $log_file: $!";
    print $fh '';
    close $fh;

    system_succeed($CHMOD, $MODE, $log_file);
}

if( ! -e $cron_file ) {
    my $LN = "/bin/ln";
    my $OPTIONS = "-sf";
    my $EMAIL_NOTICE = "/home/product/code/firmware/current/bin/email_notices.pl";

    system_succeed($LN, $OPTIONS, $EMAIL_NOTICE, $cron_file);
}
