"Fossies" - the Fresh Open Source Software Archive

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