A shell script for recursively repairing and unrarring usenet binaries

After downloading binaries with pan, I still need to verify their integrity, repair them if necessary with par2repair, then unrar them. This is something that *must* be automated. After failing to find a replacement for the excellent auto unpack program available for Windows users, I decided to use hellanzb for this too. You can invoke hellanzb like this to check a directory and repair the files:

$ hellanzb.py -L -p /path/to/files

But hellanzb (AFAIK) can only be invoked on a single directory, it does not work recursively. Hopefully, that will be fixed in the next version. I sometimes have downloads in more than twenty sub-directories that I want to repair and unpack! So I decided to write a little script, which I will copy/paste here, in case anyone wants to use it as an excellent example of bad shell scripting practices.
The dependency for use is, obviously, hellanzb. Please keep in mind that you are always yourself responsible for the code you execute on your system! I should also mention that, even though it seems to work for me, it is NOT finished, but I thought it might be interesting for someone else in the mean time.
Anyway, here it is:



if [ -z $1 ]
echo "No arguments provided. Usage: extract.sh [-r] {directory}"
exit 1

if [ "$#" -gt "$MAX_ARGS" ]
echo "Usage: extract.sh [-r] {directory}"
echo "The script expects one or two arguments, no more, no less."
exit 1

#normal repair/unrar functionality
if [[ "$#" == "1" && -d $1 ]]
/usr/bin/hellanzb.py -L -p $1
exit 0

if [[ $1 -eq "-r" && -d $2 ]]
# recursive way
for dir in `find $2 -type d` ;
/usr/bin/hellanzb.py -L -p $dir
exit 0

Enjoy! And sorry about the formatting, even using code tags does not prevent WordPress from ruining my pretty formatting with indentations.


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 )

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: