#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Std;

use Ernad::Args;
use Ernad::Args;
use Ernad::Files;

if(not -d '//etc/wpa_supplicant') {
  print "You can't run me here.\n";
  exit;
}

my %o;
&Getopt::Std::getopts('n', \%o);
my $do_make_new = $o{'n'} // 0;

our ($impna, $e, $repcode, $in_file, $issuedate);
&Ernad::Args::parse();
if(not $repcode) {
  print "I need a repcode.\n";
  exit;
}

if(not $issuedate) {
  print "I need an issuedate.\n";
  exit;
}

my $search=$issuedate.'_';
my $find="find ernad/var/$impna/reports/$repcode -name '$search*'";

my @founds=`ssh ernad \"$find\"`;

foreach my $found (@founds) {
  chomp $found;
  if($found=~m|vadoc|) {
    next;
  }
  my $local='/home/ernad/$found';
  &Ernad::Files::prepare($found);
  my $s="rsync ernad\@ernad:$found ~/$found";
  print "$s\n";
  system($s);
  $s="touch ~/$found";
  print "$s\n";
  system($s);
}

exit;
