"Fossies" - the Fresh Open Source Software Archive

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