#!/usr/pkg/bin/bash
MISC=/proc/sys/fs/binfmt_misc
die() {
 echo $@ >&2
 exit 1
}
if [ "$1" = "stop" ]; then
 umount $MISC
 exit
elif [ "$1" = "restart" ]; then
 $0 stop
 $0 start
 exit
fi
if [ ! -f $MISC/status ]; then
 modprobe binfmt_misc # ignore failure, maybe it's in kernel already
 mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc/
fi
if ! grep -iq '^enabled$' $MISC/status ]; then
 die binfmt_misc disabled
fi
echo ':postscript:M::%!::/usr/bin/gs-no-x11:' > $MISC/register
# you can also use GS_DEVICE=nullpage if you only have gs
# you probably also want to set GS_OPTIONS='-q -dBATCH' for console apps
