"Fossies" - the Fresh Open Source Software Archive

Member "xarchive-0.2.8-6/wrappers/rpm-gnu.src" (8 Nov 2005, 4399 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 # rpm-wrap.sh - bash rpm 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="rpm"
   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 RPM_PROG="rpm"
   37 RPM2CPIO_PROG="rpm2cpio"
   38 CPIO_PROG="cpio"
   39 
   40 # setup variables opt and archive.
   41 # the shifting will leave the files passed as
   42 # all the remaining args "$@"
   43 opt="$1"
   44 shift 1
   45 archive="$1"
   46 shift 1
   47 
   48 # the option switches
   49 case "$opt" in
   50     -i) # info: output supported extentions for progs that exist
   51         if [ ! "$AWK_PROG" ]; then
   52             echo none of the awk programs $AWK_PROGS found >/dev/stderr
   53             echo extentions $EXTS ignored >/dev/stderr
   54         elif [ ! "$(which $RPM2CPIO_PROG)" ]; then
   55             echo $RPM2CPIO_PROG required by $0, but not found >/dev/stderr
   56             echo extentions $EXTS ignored >/dev/stderr
   57         elif [ ! "$(which $CPIO_PROG)" ]; then
   58             echo $CPIO_PROG required by $0, but not found >/dev/stderr
   59             echo extentions $EXTS ignored >/dev/stderr
   60         elif [ "$(which $RPM_PROG)" ]; then
   61             for ext in $EXTS; do
   62                 printf "%s;" $ext
   63             done
   64         else
   65             echo program $RPM_PROG not found > /dev/stderr 
   66             echo extentions $EXTS ignored > /dev/stderr
   67         fi
   68         printf "\n"
   69         exit
   70         ;;
   71 
   72     -o) # open: mangle output of rpm cmd for xarchive 
   73         # format of output:
   74         # usr grp attr size time(epoch) name 
   75         # 1   2   3    4    5           6
   76         $RPM_PROG -q --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILEMODES:perms} %{FILESIZES} %{FILEMTIMES} %{FILENAMES}\n]' -p "$archive" | $AWK_PROG '
   77         {
   78           uid=$1
   79           gid=$2
   80           attr=$3
   81           size=$4
   82           time_cmd="date -d \"1970-01-01 UTC " $5 " seconds\" +\"%H:%M\""
   83           time_cmd | getline time
   84           close(time_cmd)
   85           date_cmd="date -d \"1970-01-01 UTC " $5 " seconds\" +\"%Y-%m-%d\""
   86           date_cmd | getline date
   87           close(date_cmd)
   88           
   89           split($0, linesplit, $5 " ")
   90           name=linesplit[2] 
   91           link="-"          
   92           printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
   93         }'
   94         exit
   95         ;;
   96 
   97     -a) # adding to archive unsupported
   98         # use appropriate rpm tools to build rpms
   99         exit $E_UNSUPPORTED
  100         ;;
  101 
  102     -n) # create new archive unsupported 
  103         # use appropriate rpm tools to build rpms
  104         exit $E_UNSUPPORTED
  105         ;;
  106 
  107     -r) # removing from archive unsupported 
  108         # use appropriate rpm tools to modify rpms
  109         exit $E_UNSUPPORTED
  110         ;;
  111 
  112     -e) # extract: from archive passed files 
  113         # convert rpm to a temporary cpio file
  114         tmpcpio="$(mktemp -t cpiotmp.XXXXXX)"
  115         $RPM2CPIO_PROG "$archive" > "$tmpcpio"
  116         # extract files from the temporary cpio
  117         while [ "$1" ]; do
  118             $CPIO_PROG --no-absolute-filenames -idv ".$1" < "$tmpcpio"
  119             shift 1
  120         done
  121         wrapper_status=$?
  122         # remove temporary cpio
  123         rm "$tmpcpio"
  124         exit $wrapper_status
  125         ;;
  126 
  127      *) echo "error, option $opt not supported"
  128         echo "use one of these:" 
  129         echo "-i                #info" 
  130         echo "-o archive        #open" 
  131         echo "-a archive files  #add" 
  132         echo "-n archive file   #new" 
  133         echo "-r archive files  #remove" 
  134         echo "-e archive files  #extract" 
  135         exit
  136 esac