Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 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. my (undef, $dir) = fileparse($filename);
  46. ($filename) = basename($filename);
  47. chdir $dir;
  48. system("$cmd '$filename'");
  49. my $exitvalue = $? >> 8;
  50. if ( $exitvalue )
  51. {
  52. return 1;
  53. }
  54. else
  55. {
  56. return 0;
  57. }
  58. } #to use do execdir(cmd, file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement