Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.28 KB | None | 0 0
  1. sub checksum
  2. {
  3.     my ($dotsfv) = @_;
  4.     my $error = 0;
  5.     my $passed = 0;
  6.     foreach my $sfvfile (@dotsfv)
  7.     {
  8.         #execdir sub uses return
  9.         if ( execdir("cfv -f", $sfvfile) )
  10.         {
  11.             ++$error;
  12.         }
  13.         else
  14.         {
  15.             ++$passed;
  16.         }
  17.     }
  18.     my $total = $error + $passed;
  19.     if ( $error )
  20.     {
  21.         print colored "\n\t\t$error/$total", 'bold red';
  22.         print colored " checksums failed\n", 'bold yellow';
  23.         print "\nContinue Anyway ?\t\t\t\t\t\t[";
  24.         print colored "y ", 'bold green';
  25.         print "/";
  26.         print colored " n", 'bold red';
  27.         print "]\n";
  28.         my $accept = <>;
  29.         if ($accept =~ m/(N|n)/)
  30.         {
  31.             print colored "Aborting user chose no\n", 'bold yellow';
  32.             exit 0;
  33.         }
  34.     }
  35.     else
  36.     {
  37.         print colored "\n\t\t$passed/$total", 'bold green';
  38.         print colored " checksums passed\n", 'bold yellow';
  39.     }
  40. }
  41.  
  42. sub execdir
  43. {
  44.     my ($cmd, $filename) = @_;
  45.     ($filename, my $dir) = fileparse($filename);
  46.     chdir $dir;
  47.     system("$cmd '$filename'");
  48.     my $exitvalue  = $? >> 8;
  49.     if ( $exitvalue )
  50.     {
  51.         return 1;
  52.     }
  53.     else
  54.     {
  55.         return 0;
  56.     }
  57. } #to use do execdir(cmd, file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement