#!/bin/bash
# Make a directory from a cpio archive
if [ -z "$1" ] ; then 
	echo "need <arg1>.ext where ext = cpio.gz or cpio"; 
	exit 1
fi

if [ -z "$2" ] ; then
	DEST=$1
else
	DEST=$2
fi

if [ -e $1.cpio.gz ] ; then 
	FILE=$1.cpio.gz
	CAT=zcat
elif [ -e $1.cpio ] ; then 
	FILE=$1.cpio
	CAT=cat
else
	echo "need <arg1>.ext where ext = cpio.gz or cpio"
	exit 1
fi

if [ -d $DEST ] ; then
    rm -rf $DEST
fi
mkdir -p $DEST
if [ ! -d $DEST ] ; then
    echo could not create dir $DEST
    exit 1
fi
(cd $DEST; $CAT ../$FILE | cpio -i)


