head	1.2;
access;
symbols;
locks
	bsittler:1.2; strict;
comment	@# @;


1.2
date	2000.11.09.20.04.22;	author bsittler;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.09.20.03.48;	author bsittler;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Added an RCS Id tag.
@
text
@#!/bin/sh --

# $Id$
#
# This script registers the SMOKE-16 emulator with the Linux
# binfmt_misc binary emulation subsystem. The special 'emu--'
# version of the emulator is used because it won't treat a
# filename as a parameter accidentally.
#
# NOTE: This script must be run as root!
#

# Set this to the complete path and filename for 'emu--'
emu="`pwd`/bin/emu--"

# This is the location of the binfmt_misc registry:
regdir="/proc/sys/fs/binfmt_misc"

# This prefix is used to register SMOKE-16 binaries:
prefix="smoke16"

# These versions are used to register SMOKE-16 binaries
versions="v0 v1"

# These are the version descriptions, magic numbers and suffices

v0_desc='SMOKE-16 "v0"'
v0_magic="\x00\x78"
v0_suffices="NMAGIC OMAGIC JMAGIC"

v1_desc='SMOKE-16 v1'
v1_magic="\x01\x78"
v1_suffices="NMAGIC OMAGIC JMAGIC"

# These are the suffix descriptions and magic numbers

OMAGIC_desc="impure executable"
OMAGIC_magic="\x01\x07"

NMAGIC_desc="pure executable"
NMAGIC_magic="\x01\x08"

JMAGIC_desc="split I&D executable"
JMAGIC_magic="\x01\x09"

##
## Here begins the actual script logic
##

# Check to see if we have proper permissions...
if ! [ -d "$regdir" ]
then
   echo "Directory $regdir does not exist."
   exit 1
fi

# Check to see if we have proper permissions...
if ! [ -w "$regdir"/register ]
then
   echo "Can't write to $regdir/register -- perhaps you're not root?"
   exit 1
fi

# Register each SMOKE-16 binary type:
echo "Registering SMOKE-16 binary formats..."

for version in $versions
do
   eval version_desc='"$'$version'_desc"'
   eval suffices='"$'$version'_suffices"'
   eval version_magic='"$'$version'_magic"'

   for suffix in $suffices
   do
      eval desc='"$version_desc $'$suffix'_desc"'
      eval magic='"$version_magic$'$suffix'_magic"'

      name="${prefix}-${version}-${suffix}"
      echo "$desc ($suffix)"
      if [ -r "$regdir"/"$name" ]
      then
         echo " + Removing previous registration"
	 echo "-1" > "$regdir"/"$name" ||
	 echo "   Failed!" >&2
      fi
      echo " + Registering"
      echo ":$name:M::$magic:\x7f\xff\xff\xff:$emu:" > "$regdir"/register ||
      echo "   Failed!" >&2

   done
done

echo "Done."
@


1.1
log
@Initial revision
@
text
@d3 1
@
