The first part of the script for automatic par2 repair and rar unpacking

Well, I’ve worked my way through some bits of the “Advanced Shell-Scripting Guide”, and written the first part of the script. When writing it, I experience much difficulty making it match only files ending in .par2 (e.g. “file.par2”) and not files ending in volXX+YY.par2 (e.g. “file.vol00+13.par2”). So I used grep. My style is probably not very good, and there is undoubtedly both much to improve and much to add. Hopefully I’ll learn from my mistakes.
Anyway, for the interested here is the most important bit I’ve done so far. It recursively finds all files ending in .par2, and then repairs/unpacks the binary. But it skips files with a .volXX+YY.part2 suffix, which is necessary if you do not invoke newsunpack.py with the -d option.

And as you can see, I am now able to make wordpress respect my indentations by using <pre> tags. Yay!


if [ $# -eq 2 ] && [ $1 == "-r" ] && [ -d $2 ]
then
for dir in `find $2 -type d` ;
do
ls "$dir"/*par2 | while read parfile;
do
if [[ `echo $parfile | grep '.*.vol[0-9]\++[0-9]\+.PAR2'` ]] || \
   [[ `echo $parfile | grep '.*.vol[0-9]\++[0-9]\+.par2'` ]]
then
continue
fi				
						
/usr/local/bin/newsunpack.py "$parfile"
		
done
		
done
exit 0
fi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: