#!/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;
use Barracuda::Environment;
use IPC::Run qw(run);

###############################################################################

=pod

=head1 NAME

tw_cli_export

=head1 DESCRIPTION

Wraps several calls to /bin/tw_cli to rebuild raid

=cut

###############################################################################

my ($tw_scsihost_switch, $baddrive) = get_argv( qr/^\/c/, qr/^\/u\d+$/ );
my $tw_cli = "${Barracuda::Environment::path_firmware}/bin/tw_cli";

die 'Execution file ' . $tw_cli . 'does not exist' if ! -f $tw_cli;

system_succeed($tw_cli, $tw_scsihost_switch, 'flush');

my @argv = ("${tw_scsihost_switch}/p$baddrive", 'export');
my $input = 'Y';

my $status = run([$tw_cli, @argv], \$input);

exit !$status;

