#!/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, NOEXEC
use strict;
use warnings;
use Barracuda::Sudo::Lib;

=pod

=head1 NAME

cms_make_dir

=head1 DESCRIPTION

Create a directory structure. Originally used for creating
the template repository for an account.

=cut

use File::Path qw(mkpath);

my ($location, $owner) =
    get_argv(dir_prefix(
                 "/mail/bcs_backup/", # used by BCS,
                 "/mnt/",             # used by WAF
                 "/data/templates/",  # used by WAF/BCS Templates SYNC
             ));

# If it already exists, never mind.
if (-d "$location") { exit 0; }

my (undef, undef, $uid, $gid, @rest) = getpwnam $owner;
#failwith(250, "Failed to get information for bcs_backup") if !defined $uid;
my $numdirs = mkpath($location, { verbose => "",
                                  mode => 0755,
                                  owner => int($uid),
                                  group => int($gid)});
exit +($numdirs < 1);
