: ########################################################################## # Shellscript: uncpio - unpack cpio file # Version : 0.3 (beta) # Author : Heiner Steven (heiner.steven@odn.de) # Date : 23-09-94 # Category : File Utilities # SCCS-Id. : $Id: uncpio,v 1.1.1.1 1999/06/15 19:29:05 heiner Exp $ ########################################################################## # Description # # Notes # needs icat # # Changes # 17-11-94 stv changed algorithm to detect file name (0.2) # new parameters -u, -v # 19-01-95 stv Program uses "icat", if needed (0.3) ########################################################################## PN=`basename $0` # program name VER='0.3 (beta)' Usage () { echo >&2 "$PN - unarchive cpio archive, $VER (stv '95) usage: $PN [-vu] [archive...] -v print extracted file names -u unconditionally overwrite existing files If the specified archive does not exist, the files archive.cpz, archive.cpio and compressed versions of archive.cpio are also tried." exit 1 } Msg () { for i do echo "$PN: $i" >&2 done } Fatal () { Msg "$@"; exit 1; } set -- `getopt huv "$@"` CpioOpt=dm # Options for cpio while [ $# -gt 0 ] do case "$1" in -h) Usage;; -v) CpioOpt="${CpioOpt}v";; -u) CpioOpt="${CpioOpt}u";; --) shift; break;; -*) Usage;; *) break;; # File name esac shift done Err=0 if [ $# -lt 1 ] then # read from stdin -- uncompressed cpio -i$CpioOpt || Fatal "error extracting from standard input" else for file in $* # no blanks permitted in file name do if [ -f "$file" -a -r "$file" ] then # file exists # If input is no cpio-archive, try 'icat' to # uncompress input echo "$file - \c" >&2 cpio -i$CpioOpt < "$file" 2> /dev/null || icat "$file" | cpio -i$CpioOpt elif [ -f "$file.cpio" -a -r "$file.cpio" ] then cpio -i$CpioOpt < $file.cpio elif [ -f "$file.cpz" -a -r "$file.cpz" ] then # compressed echo "$file.cpz - \c" >&2 uncompress < $file.cpz | cpio -i$CpioOpt elif [ -n "`ls $file.cpio.* 2> /dev/null`" ] then icat $file.cpio.* | cpio -i$CpioOpt else Msg "$file not found - ignored" Err=`expr $Err + 1` fi done fi exit $Err