#!/bin/bash
# vim:set sw=4 ts=4:
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005           SUSE GmbH, Nuernberg, Germany
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: ???
#

function usage () {
    echo "usage: unrpm [-v|-q] rpm-files...";
    echo "usage: unrpm [--verbose|--quiet] rpm-files...";
    echo "usage: unrpm --help
    echo "Unpack rpm files in CURRENT directory using cpio.";
}

CPIO_OPTS="--extract --unconditional --preserve-modification-time --make-directories"

RPM_ARCHIVES=""
for i in $* ; do
    case "$i" in
      -v | --verbose)
	CPIO_OPTS="$CPIO_OPTS --verbose"
        ;;
      -q | --quiet)
        CPIO_OPTS="$CPIO_OPTS --quiet"
        ;;
      -h | -\? | --\? | --help)
        usage
        exit 0;
	;;
      --* | -? ) 
        echo "unknown option $1"
        usage
        exit 2
        ;; 
      *)
        RPM_ARCHIVES="$RPM_ARCHIVES $i"
        ;;
    esac
done
if [ -z "$RPM_ARCHIVES" ]
then
   usage
   exit 1
fi

for ARCHIVE in $RPM_ARCHIVES; do
    if test "$QUIET" = "false" ; then
        echo -ne "$f:\t"
    fi
    case `rpm2cpio $ARCHIVE | file -` in
	*bzip2*) rpm2cpio $f | bunzip2 | cpio ${CPIO_OPTS} ;;
	*) rpm2cpio $f | cpio ${CPIO_OPTS} ;;
    esac
done
