"Fossies" - the Fresh Open Source Software Archive

Member "xarchive-0.2.8-6/wrappers/tar-gnu.src" (8 Nov 2005, 7277 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 # tar-wrap.sh - bash tar 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 tar 
   23 TAR_EXTS="tar"
   24 GZIP_EXTS="tar.gz tgz"
   25 BZIP2_EXTS="tar.bz tbz tar.bz2 tbz2"
   26 COMPRESS_EXTS="tar.z"
   27 
   28 # Setup awk program
   29 AWK_PROGS="mawk gawk awk"
   30 AWK_PROG=""
   31 for awkprog in $AWK_PROGS; do
   32     if [ "$(which $awkprog)" ]; then
   33         AWK_PROG="$awkprog"
   34         break
   35     fi
   36 done
   37 
   38 # Program to wrap
   39 TAR_PROG="tar"
   40 
   41 # setup variables opt and archive.
   42 # the shifting will leave the files passed as
   43 # all the remaining args "$@"
   44 opt="$1"
   45 shift 1
   46 archive="$1"
   47 shift 1
   48 
   49 # set up compression variables for our compression functions. 
   50 # translate archive name to lower case for pattern matching.
   51 # use compressor -c option to output to stdout and direct it where we want
   52 lc_archive="$(echo $archive|tr [:upper:] [:lower:])"
   53 for ext in $GZIP_EXTS; do
   54     if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   55         DECOMPRESS="gzip -dc"
   56         COMPRESS="gzip -c"
   57         TAR_COMPRESS_OPT="--use-compress-prog=gzip"
   58     fi
   59 done
   60 for ext in $BZIP2_EXTS; do
   61     if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   62         DECOMPRESS="bzip2 -dc" 
   63         COMPRESS="bzip2 -c"
   64         TAR_COMPRESS_OPT="--use-compress-prog=bzip2"
   65     fi
   66 done
   67 for ext in $COMPRESS_EXTS; do
   68     if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   69         DECOMPRESS="uncompress -dc" 
   70         COMPRESS="compress -c"
   71         TAR_COMPRESS_OPT="--use-compress-prog=compress"
   72     fi
   73 done
   74 
   75 # Command line options for prog functions
   76 # open and extract can use tar's cmd line option
   77 # add, new, and remove need to decompress the tar first
   78 # do their thing, than recompress the tar.
   79 OPEN_OPTS="$TAR_COMPRESS_OPT -tvf"
   80 EXTRACT_OPTS="$TAR_COMPRESS_OPT -xf"
   81 ADD_OPTS="-rf"
   82 NEW_OPTS="-cf"
   83 REMOVE_OPTS="--delete -f"
   84 
   85 # Compression functions
   86 decompress_func()
   87 {
   88     if [ "$DECOMPRESS" ]; then 
   89         tmpname="$(mktemp -t tartmp.XXXXXX)"
   90         if [ -f "$archive" ]; then 
   91             $DECOMPRESS "$archive" > "$tmpname" 
   92         fi
   93         # store old name for when we recompress
   94         oldarch="$archive"
   95         # change working file to decompressed tmp 
   96         archive="$tmpname"
   97     fi
   98 }
   99 
  100 compress_func()
  101 {
  102     if [ "$COMPRESS" ] && [ "$oldarch" ]; then
  103         [ -f "$oldarch" ] && rm "$oldarch"
  104         if $COMPRESS "$archive" > "$oldarch"; then
  105             rm "$archive"
  106         fi
  107     fi
  108 }
  109 
  110 # the option switches
  111 case "$opt" in
  112     -i) # info: output supported extentions for progs that exist
  113         if [ ! "$AWK_PROG" ]; then
  114             echo none of the awk programs $AWK_PROGS found >/dev/stderr
  115             echo extentions $EXTS ignored >/dev/stderr
  116         elif [ "$(which $TAR_PROG)" ]; then
  117             for ext in $TAR_EXTS; do
  118                 printf "%s;" $ext
  119             done
  120             for ext in $GZIP_EXTS; do
  121                 if [ "$(which gzip)" ]; then
  122                     printf "%s;" $ext
  123                 else
  124                     echo gzip not found > /dev/stderr 
  125                     echo extention $ext ignored > /dev/stderr 
  126                 fi
  127             done
  128             for ext in $BZIP2_EXTS; do
  129                 if [ "$(which bzip2)" ]; then
  130                     printf "%s;" $ext
  131                 else
  132                     echo bzip2 not found > /dev/stderr 
  133                     echo extention $ext ignored > /dev/stderr
  134                 fi
  135             done
  136             for ext in $COMPRESS_EXTS; do
  137                 if [ "$(which compress)" ] && [ "$(which uncompress)" ]; then
  138                     printf "%s;" $ext
  139                 else
  140                     echo compress and uncompress not found > /dev/stderr 
  141                     echo extention $ext ignored > /dev/stderr
  142                 fi
  143             done
  144         else
  145             echo command $TAR_PROG not found > /dev/stderr 
  146             echo extentions $TAR_EXTS ignored > /dev/stderr
  147         fi
  148         printf "\n"
  149         exit
  150         ;;
  151 
  152     -o) # open: mangle output of tar cmd for xarchive 
  153         # format of tar output:
  154 # lrwxrwxrwx USR/GRP       0 2005-05-12 00:32:03 file -> /path/to/link
  155 # -rw-r--r-- USR/GRP    6622 2005-04-22 12:29:14 file 
  156 # 1          2          3    4          5        6
  157         $TAR_PROG $OPEN_OPTS "$archive" | $AWK_PROG '
  158         {
  159           attr=$1
  160           split($2,ids,"/") #split up the 2nd field to get uid/gid
  161           uid=ids[1]
  162           gid=ids[2]
  163           size=$3
  164           date=$4
  165           time=$5
  166           
  167           #this method works with filenames that start with a space (evil!)
  168           #split line a time and a space
  169           split($0,linesplit, $5 " ")
  170           #then split the second item (name&link) at the space arrow space
  171           split(linesplit[2], nlsplit, " -> ")
  172 
  173           name=nlsplit[1]
  174           link=nlsplit[2]
  175 
  176           if (! link) {link="-"} #if there was no link set it to a dash
  177 
  178           printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
  179         }'
  180         exit
  181         ;;
  182 
  183     -a) # add to archive passed files
  184         # we only want to add the file's basename, not
  185         # the full path so...
  186         decompress_func
  187         while [ "$1" ]; do
  188             cd "$(dirname "$1")"
  189             $TAR_PROG $ADD_OPTS "$archive" "$(basename "$1")"
  190             wrapper_status=$?
  191             shift 1
  192         done
  193         compress_func
  194         exit $wrapper_status
  195         ;;
  196 
  197     -n) # new: create new archive with passed files 
  198         # create will only be passed the first file, the
  199         # rest will be "added" to the new archive
  200         decompress_func
  201         cd "$(dirname "$1")"
  202         $TAR_PROG $NEW_OPTS "$archive" "$(basename "$1")"
  203         wrapper_status=$?
  204         compress_func
  205         exit $wrapper_status
  206         ;;
  207 
  208     -r) # remove: from archive passed files 
  209         decompress_func
  210         $TAR_PROG $REMOVE_OPTS "$archive" "$@"
  211         wrapper_status=$?
  212         compress_func
  213         exit $wrapper_status
  214         ;;
  215 
  216     -e) # extract: from archive passed files 
  217         # xarchive will put is the right extract dir
  218         # so we just have to extract.
  219         $TAR_PROG $EXTRACT_OPTS "$archive" "$@" 
  220         exit 
  221         ;;
  222 
  223      *) echo "error, option $opt not supported"
  224         echo "use one of these:" 
  225         echo "-i                #info" 
  226         echo "-o archive        #open" 
  227         echo "-a archive files  #add" 
  228         echo "-n archive file   #new" 
  229         echo "-r archive files  #remove" 
  230         echo "-e archive files  #extract" 
  231         exit
  232 esac