"Fossies" - the Fresh Open Source Software Archive

Member "xarchive-0.2.8-6/wrappers/arj.src" (15 Nov 2005, 5106 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 # arj-wrap.sh - bash arj wrapper for xarchive frontend
    3 # Copyright (C) 2005 Michael Shigorin <mike@altlinux.org> 
    4 # based on zip-wrap.sh Copyright (C) 2005 Lee Bigelow <ligelowbee@yahoo.com>
    5 # and uarj mcextfs by Viatcheslav Odintsov (2:5020/181)
    6 #                  (C) 2002 ARJ Software Russia.
    7 #
    8 # This program is free software; you can redistribute it and/or modify
    9 # it under the terms of the GNU General Public License as published by
   10 # the Free Software Foundation; either version 2 of the License, or
   11 # (at your option) any later version.
   12 # 
   13 # This program is distributed in the hope that it will be useful,
   14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16 # GNU General Public License for more details.
   17 # 
   18 # You should have received a copy of the GNU General Public License
   19 # along with this program; if not, write to the Free Software
   20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21 
   22 # set up exit status variables
   23 E_UNSUPPORTED=65
   24 
   25 # Supported file extentions for arj
   26 EXTS="arj"
   27 
   28 # Programs to wrap
   29 ARJ_PROG="arj -+ -ja1 -r"
   30 
   31 # Awk program to use
   32 AWK_PROGS="mawk gawk awk"
   33 AWK_PROG=""
   34 for awkprog in $AWK_PROGS; do
   35     if [ "$(which $awkprog)" ]; then
   36         AWK_PROG="$awkprog"
   37         break
   38     fi
   39 done
   40 
   41 # Setup xterm program to use
   42 XTERM_PROGS="xterm rxvt xvt wterm aterm Eterm"
   43 XTERM_PROG=""
   44 for xtermprog in $XTERM_PROGS; do
   45     if [ "$(which $xtermprog)" ]; then
   46         XTERM_PROG="$xtermprog"
   47         break
   48     fi
   49 done
   50 
   51 # setup variables opt and archive.
   52 # the shifting will leave the files passed as
   53 # all the remaining args: "$@"
   54 opt="$1"
   55 shift 1
   56 archive="$1"
   57 shift 1
   58 
   59 # Command line options for prog functions
   60 NEW_OPTS="a"
   61 ADD_OPTS="a"
   62 REMOVE_OPTS="d"
   63 OPEN_OPTS="v"
   64 EXTRACT_OPTS="x -y"
   65 PASS_EXTRACT_OPTS="x -y -g?"
   66 
   67 # the option switches
   68 case "$opt" in
   69     -i) # info: output supported extentions for progs that exist
   70         if [ ! "$AWK_PROG" ]; then
   71             echo none of the awk programs $AWK_PROGS found >/dev/stderr
   72             echo extentions $EXTS ignored >/dev/stderr
   73         elif [ "$(which $ARJ_PROG)" ]; then
   74             for ext in $EXTS; do
   75                 printf "%s;" $ext
   76             done
   77         else
   78             echo command $ARJ_PROG not found >/dev/stderr 
   79             echo extentions $EXTS ignored >/dev/stderr
   80         fi
   81         printf "\n"
   82         exit
   83         ;;
   84 
   85     -o) # open: mangle output of arj cmd for xarchive 
   86         # format of arj output:
   87         # 001) ANKETA.FRG
   88         #   3 MS-DOS          356        121 0.340 92-04-12 11:39:46                  1  
   89         
   90 	$ARJ_PROG $OPEN_OPTS "$archive" | $AWK_PROG -v uuid=${UID-0} '{ 
   91 		if (($0 ~ /^[0-9]+\) .*/)||($0 ~ /^------------ ---------- ---------- -----/)){
   92 			if (filestr ~ /^[0-9]+\) .*/) {
   93 				printf "%s;%d;%s;%d;%d;%02d-%02d-%02d;%02d:%02d;%s\n", file, size, perm, uid, gid, date[1], date[3], date[2], time[1], time[2], symfile
   94 				perm=""
   95 				file=""
   96 				symfile=""
   97 				filestr=""
   98 			}
   99 		}
  100 
  101 		if ($0 ~ /^[0-9]+\) .*/) {
  102 			filestr=$0
  103 			sub(/^[0-9]*\) /, "")
  104 			file=$0
  105 			uid=uuid
  106 			gid=0
  107 		}
  108 
  109 		if ($0 ~ /^.* [0-9]+[\t ]+[0-9]+ [0-9]\.[0-9][0-9][0-9] [0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9].*/) {
  110 			size=$3
  111 			split($6, date, "-")
  112 			split($7, time, ":")
  113 			if ($8 ~ /^[rwx-]/) {perm=$8;} else {perm="-rw-r--r--"}
  114 		}
  115 
  116 		if ($0 ~ /^[\t ]+SymLink -> .*/) {
  117 			symfile = $3
  118 			perm="l"substr(perm, 2)
  119 		} else {symfile="-"}
  120 
  121 		if ($0 ~ /^[\t ]+Owner: UID [0-9]+\, GID [0-9]+/) {
  122 			uid=$3
  123 			gid=$5
  124 			owner=1
  125 		}
  126 	}'
  127 	exit
  128 	;;
  129 
  130     -a) # add:  to archive passed files
  131         # we only want to add the file's basename, not
  132         # the full path so...
  133         while [ "$1" ]; do
  134             cd "$(dirname "$1")"
  135             $ARJ_PROG $ADD_OPTS "$archive" "$(basename "$1")"
  136             wrapper_status=$?
  137             shift 1
  138         done
  139         exit
  140         ;;
  141 
  142     -n) # new: create new archive with passed files 
  143         # create will only be passed the first file, the
  144         # rest will be "added" to the new archive
  145         cd "$(dirname "$1")"
  146         $ARJ_PROG $NEW_OPTS "$archive" "$(basename "$1")"
  147         exit
  148         ;;
  149 
  150     -r) # remove: from archive passed files 
  151         $ARJ_PROG $REMOVE_OPTS "$archive" "$@"
  152         exit
  153         ;;
  154 
  155     -e) # extract: from archive passed files 
  156         # xarchive will put is the right extract dir
  157         # so we just have to extract.
  158         $ARJ_PROG $EXTRACT_OPTS "$archive" "$@"
  159         if [ "$?" -ne "0" ] && [ "$XTERM_PROG" ]; then
  160             echo Probably password protected,
  161             echo Opening an x-terminal...
  162             $XTERM_PROG -e $ARJ_PROG $PASS_EXTRACT_OPTS "$archive" "$@"
  163         fi
  164         exit
  165         ;;
  166 
  167      *) echo "error, option $opt not supported"
  168         echo "use one of these:" 
  169         echo "-i                #info" 
  170         echo "-o archive        #open" 
  171         echo "-a archive files  #add" 
  172         echo "-n archive file   #new" 
  173         echo "-r archive files  #remove" 
  174         echo "-e archive files  #extract" 
  175         exit
  176 esac