#!/bin/sh
#
#ident	"@(#)mkcpio.sh	1.12	93/08/31 SMI"
#
# Copyright (c) 1993 by Sun Microsystems, Inc.
#
# Used to generate the cpio archives, this is a wrapper for Joe Kowalski's
# mkarchs script.  If cpiotemplate is missing, this script will tar it
# from the reference location specified in <env_file> as CPIOTEMPLATE.

USAGE='usage:	mkcpio [-d] <env_file>

	-d  use daily subdirectories (Monday Tuesday ...) with symlinks
	    to a common cpiotemplate directory
'
while getopts d FLAG
do
	case $FLAG in
	  d )	d_FLAG=y;;
	 \? )	echo "$USAGE"
		exit 1 ;;
	esac
done

# correct argument count after options
shift `expr $OPTIND - 1`

# test that the path to the environment-setting file was given
if [ $# -ne 1 ]
then
	echo "$USAGE"
	exit 1
fi

# setup environmental variables
. $1

# chose cpio destination directory (daily or not)
if [ "$d_FLAG" = "y" ]
then
	TODAY=`date +%A`
	CPIODEST=$CPIODIR/$TODAY
else
	CPIODEST=$CPIODIR
fi

# clear out former archives, if any
if [ -d $CPIODEST ]; then
	rm -f $CPIODEST/sun* $CPIODEST/i86pc* $CPIODEST/generic*
else
	mkdir -p $CPIODEST
fi

mkbfu $ROOT $CPIODEST

