ohhdemgirls

Unrar2.sh

Nov 14th, 2013
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.37 KB | None | 0 0
  1. # put this file and xbiso.pl in the directory with your xbox game folders
  2. # warning, this code does not handle spaces in file or directory names
  3.  
  4. # Checks CRC, keeps log
  5. # Unpacks rar/iso doesn't clean up
  6.  
  7. startdir=`pwd`
  8. startdate=`date +%Y%m%d%H%M%S`
  9. startdate2=`date +%c`
  10. logfile=${startdir}"/unrar2-"${startdate}".log"
  11. logheader="Unrar2.sh run from:\n"${startdir}"\n\nThe following games failed the unrar CRC Check:\n\n\n"
  12. logfooter="\nLog created on: "
  13. logcount=0
  14. logcountfail=0
  15. logcountpass=0
  16.  
  17. for f in `find . -type f`
  18.   do
  19.  
  20.     foundpath=`dirname $f`
  21.     foundname=`basename $f`
  22.  
  23.     # Will find *.001 or *.rar, including *part01.rar or *part001.rar
  24.     # but never "part", proceeded by a number greater then 01 or 001, then ending in ".rar"
  25.     if [[ $foundname = *.rar || $foundname = *.001 ]]; then
  26.       if [[ $foundname = *part01.rar ||
  27.       $foundname = *part001.rar ||
  28.       $foundname = *.001 ||
  29.       $foundname = !(*part[0-9][0-9]|*part[0-9][0-9][0-9]).rar ]]; then
  30.  
  31.         cd $startdir/$foundpath
  32.         currentdir=${PWD##*/}
  33.         echo "FOUND!  $currentdir"
  34.         ((logcount = logcount + 1))
  35.  
  36.         # CRC check
  37.         printf 'Verifying rar...'
  38.         if [[ `unrar t -inul $foundname; echo $?` = 0 ]]; then
  39.          
  40.           ((logcountpass = logcountpass + 1))
  41.           printf 'PASS\n'
  42.          
  43.           # unrar
  44.           echo "Unpacking rar..."
  45.           unrar x -inul $foundname
  46.          
  47.           # unpack iso
  48.           echo "Unpacking iso..."
  49.           isofile=`find . -iname '*.iso'`
  50.           perl $startdir/xbiso.pl -f $isofile -d Files >/dev/null 2>&1
  51.        
  52.           # rename iso, will be the same name as the parent dir
  53.           echo "Renaming iso..."
  54.           mv $isofile $currentdir.iso
  55.        
  56.         else # crc fail
  57.  
  58.           ((logcountfail = logcountfail + 1))
  59.           printf 'FAIL\n'
  60.           if [[ $logcountfail = 1 ]]; then
  61.             echo -e $logheader >> $logfile
  62.           fi
  63.           echo -e $currentdir "\n" >> $logfile
  64.  
  65.         fi # crc end
  66.  
  67.         echo "----------------"
  68.  
  69.       fi # pack first rar end
  70.     fi # find rar end
  71.  
  72. done # find all files end
  73.  
  74. enddate=`date +%Y%m%d%H%M%S`
  75. echo -e "FINISHED!\nPass count: "${logcountpass}"\nFail count: "${logcountfail}
  76.  
  77. if [[ $logcountfail > 0 ]]; then
  78.   echo -e "\n\nTotal fail count: "${logcountfail} >> $logfile
  79.   echo -e $logfooter $startdate2 >> $logfile
  80.   echo "See log for more details"
  81. fi
Advertisement
Add Comment
Please, Sign In to add comment