"Fossies" - the Fresh Open Source Software Archive

Member "xarchive-0.2.8-6/wrappers/tar-bsd.src" (8 Nov 2005, 7220 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 #               modified to work with bsd tar and expr program
    4 # Copyright (C) 2005 Lee Bigelow <ligelowbee@yahoo.com> 
    5 # 
    6 # This program is free software; you can redistribute it and/or modify
    7 # it under the terms of the GNU General Public License as published by
    8 # the Free Software Foundation; either version 2 of the License, or
    9 # (at your option) any later version.
   10 # 
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 # 
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program; if not, write to the Free Software
   18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19 
   20 # set up exit status variables
   21 E_UNSUPPORTED=65
   22 
   23 # Supported file extentions for tar 
   24 TAR_EXTS="tar"
   25 GZIP_EXTS="tar.gz tgz"
   26 BZIP2_EXTS="tar.bz tbz tar.bz2 tbz2"
   27 COMPRESS_EXTS="tar.z"
   28 
   29 # Setup awk program
   30 AWK_PROGS="mawk gawk awk"
   31 AWK_PROG=""
   32 for awkprog in $AWK_PROGS; do
   33     if [ "$(which $awkprog)" ]; then
   34         AWK_PROG="$awkprog"
   35         break
   36     fi
   37 done
   38 
   39 # Program to wrap
   40 TAR_PROG="tar"
   41 
   42 # setup variables opt and archive.
   43 # the shifting will leave the files passed as
   44 # all the remaining args "$@"
   45 opt="$1"
   46 shift 1
   47 archive="$1"
   48 shift 1
   49 
   50 # set up compression variables for our compression functions. 
   51 # translate archive name to lower case for pattern matching.
   52 # use compressor -c option to output to stdout and direct it where we want
   53 lc_archive="$(echo $archive|tr [:upper:] [:lower:])"
   54 for ext in $GZIP_EXTS; do
   55     if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   56         DECOMPRESS="gzip -dc"
   57         COMPRESS="gzip -c"
   58         TAR_COMPRESS_OPT="-z"
   59     fi
   60 done
   61 for ext in $BZIP2_EXTS; do
   62     if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   63         DECOMPRESS="bzip2 -dc" 
   64         COMPRESS="bzip2 -c"
   65         TAR_COMPRESS_OPT="-j"
   66     fi
   67 done
   68 for ext in $COMPRESS_EXTS; do
   69     if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   70         DECOMPRESS="uncompress -dc" 
   71         COMPRESS="compress -c"
   72         TAR_COMPRESS_OPT="--use-compress-prog=compress"
   73     fi
   74 done
   75 
   76 # Command line options for prog functions
   77 # open and extract can use tar's cmd line option
   78 # add, new, and remove need to decompress the tar first
   79 # do their thing, than recompress the tar.
   80 OPEN_OPTS="$TAR_COMPRESS_OPT -tvf"
   81 EXTRACT_OPTS="$TAR_COMPRESS_OPT -xf"
   82 ADD_OPTS="-rf"
   83 NEW_OPTS="-cf"
   84 REMOVE_OPTS="--delete -f"
   85 
   86 # Compression functions
   87 decompress_func()
   88 {
   89     if [ "$DECOMPRESS" ]; then 
   90         tmpname="$(mktemp -t tartmp.XXXXXX)"
   91         if [ -f "$archive" ]; then 
   92             $DECOMPRESS "$archive" > "$tmpname" 
   93         fi
   94         # store old name for when we recompress
   95         oldarch="$archive"
   96         # change working file to decompressed tmp 
   97         archive="$tmpname"
   98     fi
   99 }
  100 
  101 compress_func()
  102 {
  103     if [ "$COMPRESS" ] && [ "$oldarch" ]; then
  104         [ -f "$oldarch" ] && rm "$oldarch"
  105         if $COMPRESS "$archive" > "$oldarch"; then
  106             rm "$archive"
  107         fi
  108     fi
  109 }
  110 
  111 # the option switches
  112 case "$opt" in
  113     -i) # info: output supported extentions for progs that exist
  114         if [ ! "$AWK_PROG" ]; then
  115             echo none of the awk programs $AWK_PROGS found >/dev/stderr
  116             echo extentions $EXTS ignored >/dev/stderr
  117         elif [ "$(which $TAR_PROG)" ]; then
  118             for ext in $TAR_EXTS; do
  119                 printf "%s;" $ext
  120             done
  121             for ext in $GZIP_EXTS; do
  122                 if [ "$(which gzip)" ]; then
  123                     printf "%s;" $ext
  124                 else
  125                     echo gzip not found > /dev/stderr 
  126                     echo extention $ext ignored > /dev/stderr 
  127                 fi
  128             done
  129             for ext in $BZIP2_EXTS; do
  130                 if [ "$(which bzip2)" ]; then
  131                     printf "%s;" $ext
  132                 else
  133                     echo bzip2 not found > /dev/stderr 
  134                     echo extention $ext ignored > /dev/stderr
  135                 fi
  136             done
  137             for ext in $COMPRESS_EXTS; do
  138                 if [ "$(which compress)" ] && [ "$(which uncompress)" ]; then
  139                     printf "%s;" $ext
  140                 else
  141                     echo compress and uncompress not found > /dev/stderr 
  142                     echo extention $ext ignored > /dev/stderr
  143                 fi
  144             done
  145         else
  146             echo command $TAR_PROG not found > /dev/stderr 
  147             echo extentions $TAR_EXTS ignored > /dev/stderr
  148         fi
  149         printf "\n"
  150         exit
  151         ;;
  152 
  153     -o) # open: mangle output of tar cmd for xarchive 
  154         # format of tar output:
  155 # lrwxrwxrwx USR/GRP       0 2005-05-12 00:32:03 file -> /path/to/link
  156 # -rw-r--r-- 0 USR GRP    6622 feb 04 12:29:14 file 
  157 # 1          2 3   4      5    6   7  8        9 
  158         $TAR_PROG $OPEN_OPTS "$archive" | $AWK_PROG '
  159         {
  160           attr=$1
  161           uid=$3
  162           gid=$4
  163           size=$5
  164           date=$6 $7
  165           time=$8
  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, $8 " ")
  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