#!/bin/sh
#
# %Z%%M% %I% %E% Copyr 1987 Sun Micro
#
# Copyright (c) 1987 by Sun Microsystems, Inc.
#
#
#	tapeimage - force alignment of an executable to a certain
#	record and pagesize
#

if [ $# -ne 2 ]
then
	echo "usage: tapeimage file blocksize"
else
	file=$1
	tbs=$2
fi


if [ -f /bin/arch -a -s /bin/arch ] 
then 
        machtype=`/bin/arch` 
        if [ -z "$machtype" ] 
        then
                pagesize=2k
        else
		case  "$machtype" in
			"sun2" )
				pagesize=2k ;;
			"sun3" | "sun3x" | "sun4" | "sun4c" | "sun4m" )   
				pagesize=8k ;;
			* )    
				pagesize=2k ;
		esac
        fi
else
        echo;echo "Error: Can't find file /bin/arch !! "
        exit 2
fi
minblksize=512

tapefile $file
case $? in
	16 | 32 )
		pagesize=8k
		skip=1
		ibs=32 ;;
	0 | 1 )
		skip=1
		pagesize=2k
		ibs=32 ;;
	2 )
		skip=1
		pagesize=2k
		ibs=$pagesize ;;
	18 | 34 )
		skip=0
		pagesize=8k
		ibs=32 ;;
	17 | 33 )
		echo "Warning: NMAGIC files cannot be executed from tape"
		exit -1 ;;
	*)
		echo $file "not an executable file";
		exit -1 ;;
esac


cp /dev/null hold.filea
cp /dev/null hold.fileb

dd if=$file of=hold.fileb ibs=$ibs obs=$pagesize skip=$skip
dd if=$file bs=$minblksize count=1 | tapeblock hold.filea $tbs
cat hold.filea hold.fileb
exit 0
