Hello there,
I am working on a shell script that will enable me to:

1. Create various types of archives
2. Extract Various types of archives
3. Move various types of files

----------------------------------------
This script I am trying to build is supposed to use core utilities so that even in Ubuntu 9.04 I could use it without installing any additional packages...

Functions that don't work will be bold:
Code:
#!/bin/bash
# Command to execute is as follows
#Enter directory with this script, then
#sh extract.sh /DIRECTORY/WITH/ALL/FOLDERS/CONTAINING/RAR/FILES/
#DO NOT FORGET THE LAST SLASH
#For numbers 4-6 you need to edit the path to your own preferred directory...

if [ $# -ne 1 ]
then
  echo "You forgot to enter directory where i should work!"
  exit
fi

while 
mesg="\n==============================================\n
  01.. Check .sfv files.\n
  02.. Unrar all rar files.\n
  03.. Delete rar and sfv files.\n
  04.. Extract TAR files.\n
  05.. Extract TAR.GZ files.\n
  06.. Gunzip ZIP files.\n
  07.. Move AVI files to your location.\n
  08.. Move MP4 files to your location.\n
  09.. Move MKV files to your location.\n
  10.. Exit
  \n==============================================\n
Select: \c"
do
  echo -e $mesg
  read selection
  case $selection in
  01)
    cd $1
    cfv -r ;;
  02)
    for r in `find $1 -wholename *.rar`
    do
      echo "Unpacking in directory: "`dirname $r`
      unrar e -v $r `dirname $r`
    done ;;
  03)
    for g in `find $1 -wholename *.r01`
    do 
      cd `dirname $g`
      echo "Deleting in directory: "`dirname $g`
      rm *.r?? *.url *.sfv imdb.nfo
      rm -r Sample/
    done ;;
  04)
    for f in `find $1 -wholename *.tar`
    do
      echo "Unpacking in directory: "`dirname $f`
      tar -xvf $f `dirname $f`
    done ;;
  05)
    for f in `find $1 -wholename *.tar.gz`
    do
      echo "Unpacking in directory: "`dirname $f`
      find $1/ -name "*.tar.gz"
      tar -xvf $f
    done ;;
  06)
    for z in `find $1 -wholename *.zip`
    do
      echo "Unpacking in directory: "`dirname $z`
      gunzip -d -v -r $z `dirname $z`
    done ;;
  07)
      for f in `find $1 -wholename *.avi`
    do
      echo "Moving AVI files from: `dirname $f` to /home/masterchief/MOVETESTING"
      find $1/ -name "*.avi"
      mv $f /home/masterchief/MOVETESTING
    done ;;
  08)
      for f in `find $1 -wholename *.mp4`
    do
      echo "Moving MP4 files from: `dirname $f` to /home/masterchief/MOVETESTING"
      find $1/ -name "*.mp4"
      mv $f /home/masterchief/MOVETESTING
    done ;;
  09)
      for f in `find $1 -wholename *.mkv`
    do
      echo "Moving MKV files from: `dirname $f` to /home/masterchief/MOVETESTING"
      find $1/ -name "*.mkv"
      mv $f /home/masterchief/MOVETESTING
    done ;;
  10) 
    exit;;
  esac
done
Can anyone help me there? This is my first real script, and it's driving me crazy. I think that the bold section(s) contain key elements for me to expand on my script the way I am hoping... I basically took bits and pieces from other scripts, and commands to get it together.
I can move the files (it searches in sub-directories and moves them even from there) and the RAR functions all seem to work properly - I haven't tried the GUNZIP function yet, but it should...
If possible could someone take the script and test it? The main focus is intended for a Folder with (MANY) sub-directories... The script is supposed to look through all of them, and find the files. Depending on the script option it's supposed to execute the commands - so far the TAR functions are not working...


I am using gnome-terminal and Gedit for this script. To easily read the functions of the script I am using the Gedit cobalt theme -- for example tar turns orange, echo green etc. so it is more easily read...