#!@shebangdir@/execlineb -P

# ISC license.
# https://docs.kernel.org/admin-guide/binfmt-misc.html

fdmove -c 2 1

multisubstitute {
	define BINFMT_FS "/proc/sys/fs/binfmt_misc"
	define BINFMT_CONF "/etc/binfmt.d"
}

if { eltest -d ${BINFMT_FS} }
if { mount -t binfmt_misc binfmt_misc ${BINFMT_FS} }

pipeline {
	elglob -0sd '' FILES ${BINFMT_CONF}/*
	if -x0 { eltest ${FILES} }
	define -sd '' SPLITFILES ${FILES}
	cat ${SPLITFILES}
}
pipeline {
	sed
		-e "/^#/d"
		-e "s/^[[:blank:]]*//g"
		-e "s/[[:blank:]]*$//g"
		-e "/^$/d"
}
forstdin -pE LINE
	if -x0 -n { redirfd -w 1 ${BINFMT_FS}/register echo ${LINE} }
	pipeline { echo ${LINE} }
	pipeline {
		sed
			-e s/://
			-e s/:.*//
	}
	withstdinas -E TORESET
	if { redirfd -w 1 ${BINFMT_FS}/${TORESET} echo -1 }
	redirfd -w 1 ${BINFMT_FS}/register echo ${LINE}
