LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Automated .r00 extracting bash script (https://www.linuxquestions.org/questions/linux-newbie-8/automated-r00-extracting-bash-script-777683/)

dexitlv 12-23-2009 09:06 AM

Automated .r00 extracting bash script
 
Well, i red through out all the posts i possibly could finf, searched google etc, and I still can't find a solution to my painfull porblem :)

Heres the noobish script :
Code:

#!/bin/bash
clear;
TITLE="-----------    LinRar    ------------"
echo $TITLE

                echo "Enter full path to your .r00 file"
                read DIR
                echo "Checking..."
                echo
                rartest="$fullDIR2rar"
                if [ -e $rartest ]; then
                echo
                echo "Were good to go..."
                echo `rar e $fullDIR2rar`
clear;
                echo "|======================================|"
                echo "| Thanks for using this solution...... |"
                echo "|======================================|"
echo $TITLE
                else
                echo "Something went realy realy wrong..."
        fi

What i wanted to know :
  • (1) How to make BASH search for .r00 file in a specific directory
    (so i could change $fullDIR2rar to $dirWHEREtheRARisAT)
  • (2) How to teach bash to combine founded *.r00 and the given directory in to one $FULLPATH like this - $dirWHEREtheRARisAT + $r00 into one - example : /home/user/downloads/myfilm.r00
  • (3) How to insert the result $FULLPATH into RAR command so that it will extract it in the active directory, OR better if someone knows, How to Extract in a specific Directory using variables or smthing...

P.S Im a newbie in BASH'ing so your help will make me feel all fuzzy and warm inside :) And dont ask Why i need it... i just do, im sick and tired of many buggy r00's and that i cant extract them properly with PEAZIP or similar apps.

P.P.S Sorry for the bad english, and some code samples would be nice :)

Greetings from Latvia.

rweaver 12-23-2009 10:17 AM

I'm really not quite sure what you're trying to do exactly... use unrar. There was some issues a few years back of it not working but last I tried it worked with multipart archives flawlessly as long as you specify the first file in the archive.

(Edit: I would test it myself... but I don't have a multipart archive handy... also keep in mind its usually about as easy as for i in `ls filename.r??`; do cat $i >> filename.rar; done and then unrar filename.rar even if it doesn't do multiparts)

EricTRA 12-23-2009 10:22 AM

Correct! Have used it recently and
Code:

unrar e rarfilename.rar
works flawless on my Slackware laptop. So just install unrar and you're good to go.

Kind regards,

Eric

dexitlv 12-23-2009 10:36 AM

Well, the idea is to enter the Directory where the multipart rar's are, and the then BASH does all of the dirty work...

and i think
Code:

unrar e filename.rar
works the same as
Code:

rar e filename.rar

dexitlv 12-23-2009 10:45 AM

Quote:

Originally Posted by rweaver (Post 3802547)
[..]
(Edit: I would test it myself... but I don't have a multipart archive handy... also keep in mind its usually about as easy as for i in `ls filename.r??`; do cat $i >> filename.rar; done and then unrar filename.rar even if it doesn't do multiparts)

I know that i can list them, but then what ? how to make it usable further, as i said im a newbie, so a kind of a code sample could really just point in the right direction, this is my first bash script and i started only few hours ago i think 13h to be exact.

And YES i know how painfully it gets when people do not read or learn for them self, but im just asking arround, maybe someone has the time to help out...

EricTRA 12-23-2009 10:59 AM

Hi,

I think you have some errors in your script when it comes with the variables.
Code:

#!/bin/bash
clear;
TITLE="-----------    LinRar    ------------"
echo $TITLE

                echo "Enter full path to your .r00 file"
                read DIR
                echo "Checking..."
                echo
                rartest="$fullDIR2rar"
                if [ -e $rartest ]; then
                echo
                echo "Were good to go..."
                echo `rar e $fullDIR2rar`
clear;
                echo "|======================================|"
                echo "| Thanks for using this solution...... |"
                echo "|======================================|"
echo $TITLE
                else
                echo "Something went realy realy wrong..."
        fi

In your code you read from userinput (read DIR) and nowhere in your script you use the DIR variable. Then you set a variable rartest to hold the value $fullDIR2rar but where do you assign that variable and what's the use for it? Next you just check if the (I suppose) directory exists and do nothing more with it. And why would you use echo with backticks to execute a command in bash when you can just type it? Those are some pointers. Taking into account the above I took the liberty of changing your script to what's below, keeping it basic and simple without loops so you can learn from it. When writing scripts, keep them lined out correctly, it'll improve readability.
Code:

#!/bin/bash
clear;
TITLE="-----------    LinRar    ------------"
echo $TITLE
        echo "Enter full path to your .r00 file"
        read DIR
        echo "Checking..."
        echo ""
        if [ -e $DIR ]; then
                echo ""
                echo "Were good to go..."
                echo ""
                cd $DIR
                rar e *.rar
                clear;
                echo "|======================================|"
                echo "| Thanks for using this solution...... |"
                echo "|======================================|"
                echo $TITLE
        else
                echo "Something went realy realy wrong..."
        fi

Kind regards,

Eric

catkin 12-23-2009 11:17 AM

Quote:

Originally Posted by dexitlv (Post 3802491)
What i wanted to know :
  • (1) How to make BASH search for .r00 file in a specific directory
    (so i could change $fullDIR2rar to $dirWHEREtheRARisAT)
  • (2) How to teach bash to combine founded *.r00 and the given directory in to one $FULLPATH like this - $dirWHEREtheRARisAT + $r00 into one - example : /home/user/downloads/myfilm.r00
  • (3) How to insert the result $FULLPATH into RAR command so that it will extract it in the active directory, OR better if someone knows, How to Extract in a specific Directory using variables or smthing...

  1. I don't understand the question. Your English is clear :) but your meaning is not. "$fullDIR2rar" is almost certainly not what you want it to be; it is the value of a variable called $fullDIR2rar but the only variable with a value is $DIR. For debugging, you can use set -xv to trace what the shell is doing (and set +xv to turn it off) so this would help
    Code:

                    set -xv
                    rartest="$fullDIR2rar"
                    set +xv

    In case you find the set -xv output too much you could use something like
    Code:

                    rartest="$fullDIR2rar"
                    echo "DEBUG: rartest is '$rartest'"

    If you want to find .r00 files in the current directory and its subdiectories, you can use
    Code:

    find . -iname '*.r00'
  2. When you say "teach" do you mean "tell"? The find command above will generate the full path of all *.r00 files, one per line. There are many threads in LQ about using the find command in bash. Some of them are listed here.
  3. How about copying the .r00 file to where you want the extracted files to go, unrar it and then delete the copy of the .r00 file?

    EDIT: or you could try creating a symbolic link to the .r00 file from the target directory and then unrar that
    Code:

    cd <target directory>
    ln -s <source directory>/<something.r00> <something.r00>
    unrar <something.r00>


rweaver 12-23-2009 01:25 PM

The full code for a bash script that cat them into one file would be more or a less the for loop i posted plus "&& unrar e filename"

dexitlv 12-23-2009 02:19 PM

Quote:

Originally Posted by rweaver (Post 3802759)
The full code for a bash script that cat them into one file would be more or a less the for loop i posted plus "&& unrar e filename"

Could you please post the link ?

dexitlv 01-15-2010 12:58 AM

Okay i finally made it :)
It has a clan-up feature too :)
Code:

#!/bin/bash
#
# İİ Some rights reserved. This work is licensed under a
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
#
# Izveidoja: Rihards 'dExIT' Mantejs
# Versija  : 0.35
# Info    : www.geex.lv / geex.raksta.lv
# Twitter  : geexlv
# Mail    : dexit@geex.lv
#
# Autortiesības : http://creativecommons.org/licenses/by-nc-sa/3.0/
#
# Paldies saku  : Geir 'geirha' Hauge, Neil '\amethyst' Moore
#
# Programma domāta kad norāda mapi kur atrodas .r** faili un ekstrakto tos
#
while true; do
        if dir=$(zenity --title="LinRAR by dExIT" --file-selection --directory); then
                if [[ ! -d $dir ]]; then
        echo "$dir: Wrong Directory" >&2
else
( cd "$dir" && for f in *.r00; do [[ -f $f ]] || continue; rar e "$f" && rm "${f%00}"[0-9][0-9]; done )
fi
else
        echo "$bold Selection cancelled $bold_off" >&2
                exit 1
fi
        zenity --title="Givem to meh...?" --question --text="More work sire?" || break
done



All times are GMT -5. The time now is 01:41 AM.