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 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 ]
for dir in `find $2 -type d` ;
ls "$dir"/*par2 | while read parfile;
if [[ `echo $parfile | grep '.*.vol[0-9]\++[0-9]\+.PAR2'` ]] || \
   [[ `echo $parfile | grep '.*.vol[0-9]\++[0-9]\+.par2'` ]]
/usr/local/bin/ "$parfile"
exit 0


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: