"Fossies" - the Fresh Open Source Software Archive

Member "xarchive-0.2.8-6/wrappers/deb.src" (8 Nov 2005, 4522 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 # deb-wrap.sh - bash deb 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 EXTS="deb"
   24 
   25 # Setup awk program
   26 AWK_PROGS="mawk gawk awk"
   27 AWK_PROG=""
   28 for awkprog in $AWK_PROGS; do
   29     if [ "$(which $awkprog)" ]; then
   30         AWK_PROG="$awkprog"
   31         break
   32     fi
   33 done
   34 
   35 # Programs to wrap
   36 DEB_PROG="dpkg-deb"
   37 TAR_PROG="tar"
   38 
   39 # setup variables opt and archive.
   40 # the shifting will leave the files passed as
   41 # all the remaining args "$@"
   42 opt="$1"
   43 shift 1
   44 archive="$1"
   45 shift 1
   46 
   47 
   48 # Command line options for prog functions
   49 # open and extract can use tar's cmd line option
   50 # add, new, and remove need to decompress the tar first
   51 # do their thing, than recompress the tar.
   52 OPEN_OPTS="-c"
   53 CONVERT_OPTS="--fsys-tarfile"
   54 TAR_EXTRACT_OPTS="-xf"
   55 
   56 # the option switches
   57 case "$opt" in
   58     -i) # info: output supported extentions for progs that exist
   59         if [ ! "$AWK_PROG" ]; then
   60             echo none of the awk programs $AWK_PROGS found >/dev/stderr
   61             echo extentions $EXTS ignored >/dev/stderr
   62         elif [ ! "$(which $TAR_PROG)" ]; then
   63             echo $TAR_PROG required by $0, but not found >/dev/stderr
   64             echo extentions $EXTS ignored >/dev/stderr
   65         elif [ "$(which $DEB_PROG)" ]; then
   66             for ext in $EXTS; do
   67                 printf "%s;" $ext
   68             done
   69         else
   70             echo program $DEB_PROG not found > /dev/stderr 
   71             echo extentions $EXTS ignored > /dev/stderr
   72         fi
   73         printf "\n"
   74         exit
   75         ;;
   76 
   77     -o) # open: mangle output of dpkg-deb cmd for xarchive 
   78         # format of output:
   79 # lrwxrwxrwx USR/GRP       0 2005-05-12 00:32:03 file -> /path/to/link
   80 # -rw-r--r-- USR/GRP    6622 2005-04-22 12:29:14 file 
   81 # 1          2          3    4          5        6
   82         $DEB_PROG $OPEN_OPTS "$archive" | $AWK_PROG '
   83         {
   84           attr=$1
   85           split($2,ids,"/") #split up the 2nd field to get uid/gid
   86           uid=ids[1]
   87           gid=ids[2]
   88           size=$3
   89           date=$4
   90           time=$5
   91           
   92           #this method works with filenames that start with a space (evil!)
   93           #split line a time and a space
   94           split($0,linesplit, $5 " ")
   95           #then split the second item (name&link) at the space arrow space
   96           split(linesplit[2], nlsplit, " -> ")
   97 
   98           name=nlsplit[1]
   99           link=nlsplit[2]
  100 
  101           if (! link) {link="-"} #if there was no link set it to a dash
  102 
  103           printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
  104         }'
  105         exit
  106         ;;
  107 
  108     -a) # adding to archive unsupported
  109         # use appropriate dpkg tools to build debs
  110         exit $E_UNSUPPORTED
  111         ;;
  112 
  113     -n) # create new archive unsupported 
  114         # use appropriate dpkg tools to build debs
  115         exit $E_UNSUPPORTED
  116         ;;
  117 
  118     -r) # removing from archive unsupported 
  119         # use appropriate dpkg tools to modify debs
  120         exit $E_UNSUPPORTED
  121         ;;
  122 
  123     -e) # extract: from archive passed files 
  124         # convert deb to a temporary tar file
  125         tmptar="$(mktemp -t tartmp.XXXXXX)"
  126         $DEB_PROG $CONVERT_OPTS "$archive" > "$tmptar"
  127         # extract files from the temporary tar
  128         $TAR_PROG $TAR_EXTRACT_OPTS "$tmptar" "$@"
  129         wrapper_status=$?
  130         # remove temporary tar
  131         rm "$tmptar"
  132         exit $wrapper_status
  133         ;;
  134 
  135      *) echo "error, option $opt not supported"
  136         echo "use one of these:" 
  137         echo "-i                #info" 
  138         echo "-o archive        #open" 
  139         echo "-a archive files  #add" 
  140         echo "-n archive file   #new" 
  141         echo "-r archive files  #remove" 
  142         echo "-e archive files  #extract" 
  143         exit
  144 esac