"Fossies" - the Fresh Open Source Software Archive

Member "xarchive-0.2.8-6/wrappers/rar.src" (14 Nov 2005, 6041 Bytes) of package /linux/privat/old/xarchive-0.2.8-6.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /path/to/bash
    2 # rar-wrap.sh - bash rar wrapper for xarchive
    3 # Copyright (C) 2005 Lee Bigelow <ligelowbee@yahoo.com> 
    4 # 
    5 # This program is free software; you can redistribute it and/or modify
    6 # it under the terms of the GNU General Public License as published by
    7 # the Free Software Foundation; either version 2 of the License, or
    8 # (at your option) any later version.
    9 # 
   10 # This program is distributed in the hope that it will be useful,
   11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 # GNU General Public License for more details.
   14 # 
   15 # You should have received a copy of the GNU General Public License
   16 # along with this program; if not, write to the Free Software
   17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18 
   19 # set up exit status variables
   20 E_UNSUPPORTED=65
   21 
   22 # Supported file extentions for rar 
   23 EXTS="rar cbr"
   24 
   25 # Program to wrap
   26 if [ "$(which rar)" ]; then
   27     RAR_PROG="rar"
   28 else
   29     RAR_PROG="unrar"
   30 fi
   31 
   32 # Setup awk program to use
   33 AWK_PROGS="mawk gawk awk"
   34 AWK_PROG=""
   35 for awkprog in $AWK_PROGS; do
   36     if [ "$(which $awkprog)" ]; then
   37         AWK_PROG="$awkprog"
   38         break
   39     fi
   40 done
   41 
   42 # Setup xterm program to use
   43 XTERM_PROGS="xterm rxvt xvt wterm aterm Eterm"
   44 XTERM_PROG=""
   45 for xtermprog in $XTERM_PROGS; do
   46     if [ "$(which $xtermprog)" ]; then
   47         XTERM_PROG="$xtermprog"
   48         break
   49     fi
   50 done
   51 
   52 # setup variables opt and archive.
   53 # the shifting will leave the files passed as
   54 # all the remaining args "$@"
   55 opt="$1"
   56 shift 1
   57 archive="$1"
   58 shift 1
   59 
   60 # Command line options for prog functions
   61 # disable comments when opening
   62 OPEN_OPTS="v -c-"
   63 ADD_OPTS="a"
   64 NEW_OPTS="a"
   65 REMOVE_OPTS="d"
   66 EXTRACT_OPTS="x -o- -p-"
   67 PASS_EXTRACT_OPTS="x -o-"
   68 
   69 # the option switches
   70 case "$opt" in
   71     -i) # info: output supported extentions for progs that exist
   72         if [ ! "$AWK_PROG" ]; then
   73             echo none of the awk programs $AWK_PROGS found >/dev/stderr
   74             echo extentions $EXTS ignored >/dev/stderr
   75         elif [ "$(which $RAR_PROG)" ]; then
   76             for ext in $EXTS; do
   77                 printf "%s;" $ext
   78             done
   79         else
   80             echo command $RAR_PROG not found > /dev/stderr 
   81             echo extentions $EXTS ignored > /dev/stderr 
   82         fi
   83         printf "\n"
   84         exit
   85         ;;
   86 
   87     -o) # open: mangle output of rar cmd for xarchive 
   88         # format of rar output:
   89 #-------------------------------------
   90 # bookmarks/mozilla_bookmarks.html
   91 #            11512     5231  45% 28-02-05 16:19 -rw-r--r-- F3F3477F m3b 2.9
   92 #       (or  11512     5231  45% 28-02-05 16:19 .D....     00000000 m3b 2.9)
   93 #       (or  11512     5231  45% 28-02-05 16:19 .....S     F3F3477F m3b 2.9)
   94 #            1         2     3   4        5     6          7        8   9
   95 #-------------------------------------
   96         
   97         $RAR_PROG $OPEN_OPTS "$archive" | $AWK_PROG -v uuid=${UID} '
   98         # The body of info we wish to process starts with a dashed line 
   99         # so set a flag to signal when to start and stop processing.
  100         # The name is on one line with the info on the next so toggle
  101         # a line flag letting us know what kinda info to get.  
  102         BEGIN { flag=0; line=0 }
  103         /^------/ { flag++; if (flag > 1) exit 0; next} #line starts with dashs
  104         {
  105           if (flag == 0) next #not in the body yet so grab the next line
  106           if (line == 0) #this line contains the name
  107           { 
  108             name=substr($0,2) #strip the single space from start of name
  109             line++  #next line will contain the info so increase the flag
  110             next
  111           }
  112           else #we got here so this line contains the info
  113           {
  114             size=$1
  115             date=$4
  116             time=$5
  117             
  118             #modify attributes to read more unix like if they are not
  119             if (index($6, "D") != 0) {attr="drwxr-xr-x"}
  120             else if (index($6, ".") != 0) {attr="-rw-r--r--"}
  121             else {attr=$6}
  122 
  123             uid=uuid
  124             gid=uuid
  125             link="-"
  126 
  127             printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
  128             line=0 #next line will be a name so reset the flag
  129           }
  130         }'
  131         exit
  132         ;;
  133 
  134     -a) # add:  to archive passed files
  135         # we only want to add the file's basename, not
  136         # the full path so...
  137         if [ "$RAR_PROG" = "unrar" ]; then
  138             exit $E_UNSUPPORTED
  139         fi
  140         while [ "$1" ]; do
  141             cd "$(dirname "$1")"
  142             $RAR_PROG $ADD_OPTS "$archive" "$(basename "$1")"
  143             wrapper_status=$?
  144             shift 1
  145         done
  146         exit $wrapper_status
  147         ;;
  148 
  149     -n) # new: create new archive with passed files 
  150         # create will only be passed the first file, the
  151         # rest will be "added" to the new archive
  152         if [ "$RAR_PROG" = "unrar" ]; then
  153             exit $E_UNSUPPORTED
  154         fi
  155         cd "$(dirname "$1")"
  156         $RAR_PROG $NEW_OPTS "$archive" "$(basename "$1")"
  157         exit
  158         ;;
  159 
  160     -r) # remove: from archive passed files 
  161         if [ "$RAR_PROG" = "unrar" ]; then
  162             exit $E_UNSUPPORTED
  163         fi
  164         $RAR_PROG $REMOVE_OPTS "$archive" "$@"
  165         exit
  166         ;;
  167 
  168     -e) # extract: from archive passed files 
  169         # xarchive will put is the right extract dir
  170         # so we just have to extract.
  171         $RAR_PROG $EXTRACT_OPTS "$archive" "$@"
  172         if [ "$?" -ne "0" ] && [ "$XTERM_PROG" ]; then
  173             echo Probably password protected,
  174             echo Opening an x-terminal...
  175             $XTERM_PROG -e $RAR_PROG $PASS_EXTRACT_OPTS "$archive" "$@"
  176         fi
  177         exit
  178         ;;
  179 
  180      *) echo "error, option $opt not supported"
  181         echo "use one of these:" 
  182         echo "-i                #info" 
  183         echo "-o archive        #open" 
  184         echo "-a archive files  #add" 
  185         echo "-n archive file   #new" 
  186         echo "-r archive files  #remove" 
  187         echo "-e archive files  #extract" 
  188         exit
  189 esac