"Fossies" - the Fresh Open Source Software Archive

Member "xarchive-0.2.8-6/wrappers/zip.src" (15 Nov 2005, 5130 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 # zip-wrap.sh - bash zip,unzip,zipinfo wrapper for xarchive frontend
    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 zip 
   23 EXTS="zip cbz jar"
   24 
   25 # Programs to wrap
   26 ZIP_PROG="zip"
   27 UNZIP_PROG="unzip"
   28 ZIPINFO_PROG="zipinfo"
   29 
   30 # Setup awk program
   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 
   60 # for zip, use recursive when adding files
   61 NEW_OPTS="-r"
   62 ADD_OPTS="-g -r"
   63 REMOVE_OPTS="-d"
   64 
   65 # for zipinfo, short list, no header, no tail
   66 OPEN_OPTS="-T -s-h-t"
   67 
   68 # for unzip, don't overwrite existing files, just skip the confilct.
   69 EXTRACT_OPTS="-n -P-"
   70 PASS_EXTRACT_OPTS="-n"
   71 
   72 # the option switches
   73 case "$opt" in
   74     -i) # info: output supported extentions for progs that exist
   75         if [ ! "$AWK_PROG" ]; then
   76             echo none of the awk programs $AWK_PROGS found >/dev/stderr
   77             echo extentions $EXTS ignored >/dev/stderr
   78         elif [ "$(which $UNZIP_PROG)" -a "$(which $ZIPINFO_PROG)" ]; then
   79             for ext in $EXTS; do
   80                 printf "%s;" $ext
   81             done
   82             if [ ! "$(which $ZIP_PROG)" ]; then
   83                 echo warning: $ZIP_PROG not found, extract only >/dev/stderr
   84             fi
   85         else
   86             echo commands $UNZIP_PROG  and $ZIPINFO_PROG not found >/dev/stderr 
   87             echo extentions $EXTS ignored >/dev/stderr
   88         fi
   89         printf "\n"
   90         exit
   91         ;;
   92 
   93     -o) # open: mangle output of zipinfo cmd for xarchive 
   94         # format of zipinfo -T -s-h- output:
   95         # -rw-r--r--  2.3 unx    11512 tx defN YYYYMMDD.HHMMSS file.txt 
   96         # 1           2   3      4     5  6    7               8
   97         $ZIPINFO_PROG $OPEN_OPTS "$archive" | $AWK_PROG -v uuid=${UID} '
   98         {
   99           attr=$1; size=$4
  100           
  101           year=substr($7,1,4)
  102           month=substr($7,5,2)
  103           day=substr($7,7,2)
  104           date=year "-" month "-" day
  105 
  106           hours=substr($7,10,2)
  107           mins=substr($7,12,2)
  108           secs=substr($7,14,2)
  109           time=hours ":" mins ":" secs
  110 
  111           uid=uuid; gid=uuid; link="-"
  112           #split line at the time and a space, second item is our name
  113           split($0, linesplit, ($7 " "))
  114           name=linesplit[2]
  115           printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
  116         }'            
  117         exit
  118         ;;
  119 
  120     -a) # add:  to archive passed files
  121         # we only want to add the file's basename, not
  122         # the full path so...
  123         while [ "$1" ]; do
  124             cd "$(dirname "$1")"
  125             $ZIP_PROG $ADD_OPTS "$archive" "$(basename "$1")"
  126             wrapper_status=$?
  127             shift 1
  128         done
  129         exit $wrapper_status
  130         ;;
  131 
  132     -n) # new: create new archive with passed files 
  133         # create will only be passed the first file, the
  134         # rest will be "added" to the new archive
  135         cd "$(dirname "$1")"
  136         $ZIP_PROG $NEW_OPTS "$archive" "$(basename "$1")"
  137         exit
  138         ;;
  139 
  140     -r) # remove: from archive passed files 
  141         $ZIP_PROG $REMOVE_OPTS "$archive" "$@"
  142         exit
  143         ;;
  144 
  145     -e) # extract: from archive passed files 
  146         # xarchive will put is the right extract dir
  147         # so we just have to extract.
  148         $UNZIP_PROG $EXTRACT_OPTS "$archive" "$@"
  149         if [ "$?" -ne "0" ] && [ "$XTERM_PROG" ]; then
  150             echo Probably password protected,
  151             echo Opening an x-terminal...
  152             $XTERM_PROG -e $UNZIP_PROG $PASS_EXTRACT_OPTS "$archive" "$@"
  153         fi
  154         exit
  155         ;;
  156 
  157      *) echo "error, option $opt not supported"
  158         echo "use one of these:" 
  159         echo "-i                #info" 
  160         echo "-o archive        #open" 
  161         echo "-a archive files  #add" 
  162         echo "-n archive file   #new" 
  163         echo "-r archive files  #remove" 
  164         echo "-e archive files  #extract" 
  165         exit
  166 esac