#!/usr/bin/perl ## ## Author: David McKeon <@bonzoli.com> ## URL: http://bonzoli.com ## Program: process_par ## Creation Date: Date: 2007/01/30 17:07:22 PST ## Last Revision: $Date$ ## Version: v.5 ############################################################################# # David McKeon <@bonzoli.com> http://bonzoli.com # # # # Copyright (C) 2007-2007 David McKeon. All rights reserved. # # # # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the # # Free Software Foundation; either version 2 of the License, or (at your # # option) any later version. # # # # This program is distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # # Public License for more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to: # # # # Free Software Foundation, Inc. # # 59 Temple Place - Suite 330 # # Boston, MA 02111-1307, USA. # # # # Or you can find the full GNU GPL online at: http://www.gnu.org # # # ############################################################################# ## Category: Perl ## Rating: 5/5 ## ## ## ## ## # $| = 1; my $USAGE="Usage: process_par2 NOTE: .par2, .PAR2, or *.PAR2 extension \n"; my $file,$TESTONLY; if (! $ARGV[0]) { print "$USAGE\n"; exit; } use Getopt::Long; use File::Path; # create paths/dirs # Directory to place part files that were used to assemble the final file # We move them here to help keep the clutter down my $DMDIR='deleteme'; # This makes the dir if it doesn't exist make_dir($DMDIR); # Set this to your par2 binary. my $PAR2BIN='/usr/local/bin/par2'; #--------------------------------------------------------------------------- Getopt::Long::Configure("no_ignore_case"); GetOptions( "h|help" => \$help, "V|version" => \$vers, #----------------------- ); #--------------------------------------------------------------------------- if($help){ exec("perldoc $0"); } if($vers){ version(); } #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- sub version { my($date) = "\$Date$_"; my($rvsn) = "First"; my($rcsd) = ".5"; $date =~ s/(.*: +)(.*?)(\s*$)/$2/g; $rvsn =~ s/(.*: +)(.*?)(\s*$)/$2/g; $rcsd =~ s/(.*: +)(.*?)(\s*$)/$2/g; print < URL: http://bonzoli.com Creation Date: 2007/01/30 17:07:22 GMT Last Revision: $date GMT Revision: $rcsd Copyright (C) 2007-2007 David McKeon. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. Or you can find the full GNU GPL online at: http://www.gnu.org EOF exit; } sub shellify_string { ########################################################################## # FUNCTION DEFINITIONS #------------------------------------------------------------------------- # FUNCTION shellify_string # RECEIVES $string # RETURNS $string # DOES Going to make this line readable by shell, so mv's and copies work. # add a backslash before unusual characters my ( $file ); # shouldn't just shift work here? $file = shift @_; #print "my file is $file \n"; #If its not one of these characters put a \ in front of it. $file =~ s|[^-a-zA-Z0-9_.,/]|\\$&|g; # backslash newline gets ignored by sh, so we have to use quotes. $file =~ s|\\\n|'\n'|g; # make sure name doesn't have a leading - $file =~ s|^-|./-|; # null name is unprintable, make it '.' if ($file eq '') { $file = "."; } return $file; } sub make_dir { ########################################################################## # FUNCTION DEFINITIONS #------------------------------------------------------------------------- # FUNCTION make_dir # RECEIVES directory including full path # DOES Makes the full path and dir needed for the deleteme files. $NEWDIR=shift; eval { mkpath("$NEWDIR", 1, 0755) }; if ($@) { print "Couldn\'t create $NEWDIR: $@"; } } ##MAIN####################################################################### foreach $file (@ARGV) { print "$file\n"; chomp $file; next if( ! -f $file || ! $file =~ /.[Pp][Aa][Rr]2$/ || -l $file ); #print "$file\n"; if (!(-d $file) && $file=~/\.[Pp][Aa][Rr]2/i) { #print "$file\n"; if ($file=~/.vol[0]{0,4}\+[0]{0,3}1/) { print "$file\n"; $file=shellify_string($file); $CMD="$PAR2BIN r $file"; print "$CMD\n"; system($CMD); # == (0) or die "system $CMD failed: $?"; } if ( -d $MVDIR ) { $file =~ s/.vol[0]{0,4}\+[0]{0,3}\*.[Pp][Aa][Rr]2$/\*/g; $CMD="mv $file $MVDIR"; print "$CMD\n"; system($CMD) == (0) or die "system $CMD failed: $?"; } } } ##End Main################################################################### #--------------------------------------------------------------------------- ## ## Use "perldoc process_par" to read the man page below. # __END__ =head1 NAME B - This program runs par2 against all the par2 file sets, this will repair file sets that are not missing to many chunks. =head1 SYNOPSIS B S<[ B<-hv> ]> S<[ I ]> =head1 DESCRIPTION B this program runs the par2 binary against a PAR2 file set. Par2 is a set of recovery archives, used to rebuild files that have become corrupted. This is a popular method to resolve issues on uunet transfered files. This program will run the par2 and try to recover your files to pristine condition, then move the .PAR2 and .par2 files to a specified directory(deleteme), which can be later easily cleaned up. Sometimes this is useful incase you did not get all the files originally. Just copy them all back to the original location, and rerun this program. =head1 QUICK START The most common usage is as follows: B *.PAR2 seems to work best. B NOTE: .par2, .PAR2, or *.PAR2 extension B *.par2 =head1 STANDARD OPTIONS B<-h --help> Prints this information. B<-v --version> Prints version information. =head1 OPTIONS =head1 EXAMPLE The example below B B<-t> I =head1 BUGS None. =head1 SEE ALSO process_par =head1 AUTHOR AND COPYRIGHT David McKeon <@bonzoli.com> http://bonzoli.com Copyright (C) 2007-2007 David McKeon. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. Or you can find the full GNU GPL online at: http://www.gnu.org =head1 VERSION Current Revision: $Revision$ Last Modification: $Date$ =pod SCRIPT CATEGORIES UNIX/System_administration =pod OSNAMES Any