Blame | Last modification | View Log | RSS feed
#!/bin/bash################## CONFIG OPTIONS #############################################DLDIR="/home/irasnyd/downloads/usenet" # "global" download dir ###GLOGDIR=${DLDIR}/logs # "global" logdir ##################################################################################### Clean up temp files ###cleanup_temp() {rm -f parfiles;rm -f goodfiles;rm -f completefiles;rm -f currentset;};### Clean up global logs ###cleanup_logs() {rm -f $GLOGDIR/badfiles;rm -f $GLOGDIR/unextractable;};### Function which prints error logs ###print_errors() {### Print Unrepairable ###echoif [ -f $GLOGDIR/badfiles ]thenecho '****************************************'echo '*** THE FOLLOWING WERE UNREPAIRABLE ****'echo '****************************************'echocat $GLOGDIR/badfileselseecho 'No Unrepairable Files!'fiecho### Print Unextractable ###if [ -f $GLOGDIR/unextractable ]thenecho '****************************************'echo '*** THE FOLLOWING WERE UNEXTRACTABLE ***'echo '****************************************'echocat $GLOGDIR/unextractableelseecho 'No Unextractable Files!'fi};### Store the previous value of IFS (word parser) ###PREV_IFS=$IFSNEW_IFS=''### Set IFS to the newline ###### This is ugly as fuck, but it works ###IFS=$NEW_IFS### Set/Clean up the Environment ###CUR_PWD=`pwd`cd $DLDIRcleanup_tempcleanup_logs### Get a list of subdirs one level down ###ls -Fb $1 | grep \/ | sed -e 's/\/$//g' > $GLOGDIR/subdirsecho "." >> $GLOGDIR/subdirs################################################################################## The main loop that runs through the parchecking and extraction ##################################################################################for SUBDIR in `cat $GLOGDIR/subdirs`;do cd "${DLDIR}/${SUBDIR}/";### Get all of the bare par2 files (not repair volumes) ###ls *.{par2,PAR2} | grep -v vol > parfiles;### Repair everything, and sort it into "goodfiles" and "badfiles" ###for i in `cat parfiles`; \do ( par2repair $i && echo $i >> goodfiles ) || echo $i >> $GLOGDIR/badfiles; \done;### Get the filenames of the files that verified successfully ###sed 's/.par2//' goodfiles | sed 's/.PAR2//' > completefiles;### Extract files, and delete the set if it extracted correctly ###### the sed goop in the next line makes sure all spaces, [, and ] are backslashed ###for i in `sed 's/ /\\ /g' completefiles | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g'`; \# get a good working set, sans sfv and nfodo ls ${i}.* | grep -vi nfo | grep -vi jpg > currentset; \# remove pars from currentset, then get the first thing that has "rar" or "001" at the END only# store above result in EXFILE (file to extract)EXFILE=`grep -vi par2 currentset | grep -m 1 "rar$\|001$"`; \# (extract the file AND remove the current set) OR save the filename to "unextractable"( rar e ${EXFILE} && for j in `cat currentset`; do rm $j; done; ) || echo $i >> $GLOGDIR/unextractable; \done;cleanup_temp;done; # end the "subdirs" loop################################################################################## Reset IFS to it's default ###IFS=$PREV_IFS### Clean up temp files ###cleanup_temprm -f $GLOGDIR/subdirs### Go back to old pwd ###cd $CUR_PWD### Print Parting Message ###echoecho "All Finished. Good Bye!"