#!/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

mount_sshfs

=head1 DESCRIPTION

Script to mount an sshfs partition on a device for use with the backup2
SSHFS location.

=cut

###############################################################################
my ($host_file, $port, $key_path, $host_string, $mount_path) =
    get_argv(sub { -f $_[0] },
             qr/^\d+$/,
             sub { -f $_[0] },
             qr/.*/, # not sure how to nail this down safely
             sub { -d $_[0] });

# don't try to mount an already mounted path
my $mounts = qx{mount 2>&1};
my $status = $? >> 8;
exit 1 if $status != 0;
exit 0 if $mounts =~ /$mount_path/;

system_succeed("/home/product/code/firmware/current/bin/sshfs $host_string $mount_path -o nonempty -o reconnect -o ssh_command='/usr/bin/ssh -i $key_path -o StrictHostKeyChecking=no -p $port'");

