#!/bin/sh
#
#ident	"@(#)mkarchs.sh	1.4	93/08/31 SMI"
#
# Copyright (c) 1993 by Sun Microsystems, Inc.
#
# Joe Kowalski's script to create cpio archives from a proto area
# to facilitate quick testing on various platforms.
#
# Modified to choose an instruction-set-specific set of archives
# based upon indicator directories existing in the proto area.

[ $# -ne 2 ] && {
    echo "Usage: $0 proto-area archive-home"
    exit 1
}
proto=$1
ahome=$2

[ -d $proto ] || {
	echo "Proto area directory $proto does not exist."
	exit 1
}

[ -d "$ahome" ] || {
    echo "Archive target directory $ahome needs to exist."
    exit 1
}

cd $proto

# Known kernel architectures are hardcoded here and in the filter
# for creating the generic root archive below.  The inference is
# made on the fact that kernel subdirectories only exist for
# kernel architectures appropriate to the instruction set of the
# proto area.  The KBI project will make this obsolete.
#
if ls -d sun4*/kernel > /dev/null 2>&1
then
	kernlist="`echo sun4*`"
elif ls -d i86?*/kernel > /dev/null 2>&1
then
	kernlist="`echo i86?*`"
else
	echo "Proto area incomplete or of unknown architecture"
	exit 1
fi

echo "Creating generic root archive ..."
(find . -depth -print | egrep -v '^\./sun4|^\./i86pc' | grep -v '^\./usr'
    echo "./usr" ) | cpio -ocB > ${ahome}/generic.root

echo "Creating generic usr archive .... "
find . -depth -print | grep '^\./usr' | \
  grep -v '^\./usr/share/lib/terminfo' | cpio -ocB > ${ahome}/generic.usr

echo "Creating terminfo archive ..."
tar cf ${ahome}/generic.terminfo ./usr/share/lib/terminfo

for i in $kernlist
do
    echo "Creating $i root archive ..."
    _curwd=`pwd`
    cd $i
    find . -depth -print | grep -v '^\./usr' | cpio -ocB > ${ahome}/${i}.root
    echo "Creating $i usr archive ..."
    find . -depth -print | grep '^\./usr' | cpio -ocB > ${ahome}/${i}.usr
    cd $_curwd
done

exit 0

