#!/bin/bash # unpackdcrar sourcefile destdir # unrars sourcefile, unrars that, then renames copies resulting .cso to proper name in destination # unpack double rars # uses unrar and unrar-free RARFILE=$1 DESTDIR=$2 TEMPDIR1=/tmp/dcrar1 TEMPDIR2=/tmp/dcrar2 # set up mkdir -p $TEMPDIR1 mkdir -p $TEMPDIR2 rm -f $TEMPDIR1/* rm -f $TEMPDIR2/* # Name we want is name of input before _USA string #building newname N1=$1 #echo N1 $N1 N2=`echo "$N1" | sed -rn 's/(.*)\_USA.*/\1/p'` if [ "$N2" == "" ] then # echo excepton n2 $N2 N2=$N1 fi echo N2 $N2 N3=`echo $N2 | tr "_" " "` echo $N3 #echo "Need to deal with CDI, Bin/CUE - name in the cue will be shitty" #So, we extract to temp2 directory, then we look in there to see if we have a cue file #If we do, we move bin and cue to target directory, also we grep and replace the cue with the right bin name # #If we have a CDI, we move it to the destination folder with the right name #six posibilities, cdi, bin, cue, CDI, BIN, CUE. What is wrong with just moving all combinations? OUTNAMECDI="$N3 (USA).cdi" OUTNAMEBIN="$N3 (USA).bin" OUTNAMECUE="$N3 (USA).bin" echo $OUTNAMECDI # unrar original into TEMPDIR1 #echo unrar --force --extract-no-paths "$RARFILE" "$TEMPDIR1" #unrar-free --force --extract-no-paths "$RARFILE" "$TEMPDIR1" echo unrar x "$RARFILE" "$TEMPDIR1" unrar x "$RARFILE" "$TEMPDIR1" # unrar that into TEMPDIR2 echo unrar x $TEMPDIR1/*.001 "$TEMPDIR2" unrar x $TEMPDIR1/*.rar "$TEMPDIR2" unrar x $TEMPDIR1/*.001 "$TEMPDIR2" #copy # Copy iso into Destination echo $TEMPDIR2/* "$DESTDIR/$OUTNAME" mv $TEMPDIR2/*.CDI "$DESTDIR/$OUTNAMECDI" mv $TEMPDIR2/*.cdi "$DESTDIR/$OUTNAMECDI" exit exit N3=`echo "$N2" | sed -rn 's/ \[NTSC-U\]/ \[U\]/p'` if [ "$N3" == "" ] then # echo excepton n3 $N3 N3=$N2 fi #echo N3 $N3 N4=`echo "$N3" | sed -rn 's/ \[U\]/ (USA)/p'` if [ "$N4" == "" ] then # echo excepton n4 $N4 N4=$N3 fi #echo N4 $N4 N5=`echo "$N4" | sed -rn 's/ \[SLUS.*\]//p'` if [ "$N5" == "" ] then # echo excepton n5 $N5 N5=$N4 fi #echo N5 $N5 N6=`echo "$N5" | sed -rn 's/\[SLCS.*\]//p'` if [ "$N6" == "" ] then # echo excepton n6 $N6 N6=$N5 fi #echo N6 $N6 N7=`echo "$N6" | sed -rn 's/\[SCUS.*\]//p'` if [ "$N7" == "" ] then # echo excepton n7 $N7 N7=$N6 fi #echo N7 $N7' BASENAME=`echo "$N7" | awk '{$1=$1}1'` NEWNAME=`echo "$BASENAME" | sed -rn 's/(.*)/\1.pbp/p'` IMAGEBASENAME=`echo "$BASENAME" | sed -rn 's/ \(USA\)//p'` if [ "$IMAGEBASENAME" == "" ] then echo exception IMAGEBASENAME $IMAGEBASENAME IMAGEBASENAME=$BASENAME fi #echo orig: $1 blah #echo here: $NEWNAME blah #echo "$DESTDIR/$NEWNAME" blah #exit # remove SLUS #extract rar file to /tmp directory echo unrar --force --extract-no-paths "$RARFILE" "$TEMPDIR" unrar --force --extract-no-paths "$RARFILE" "$TEMPDIR" #move eboot to destination directory echo mv "$TEMPDIR/$ORIGNAME" "$DESTDIR/$NEWNAME" mv "$TEMPDIR/$ORIGNAME" "$DESTDIR/$NEWNAME" #Move Cover to destination directory echo mv "${TEMPDIR}/${IMAGEBASENAME}"*.jpg "$DESTDIR/$BASENAME-image.jpg" mv "${TEMPDIR}/${IMAGEBASENAME}"*.jpg "$DESTDIR/$BASENAME-image.jpg"