#! /bin/sh -e

. /lib/kickseed/kickseed.sh

ks_log () {
	logger -t kickseed "$@"
}

ks_run_script () {
	TYPE="$1"
	INTERPRETER="$2"
	CHROOTED="$3"
	SCRIPT="$4"

	if [ "$CHROOTED" = 1 ]; then
		in_target=in-target
		root=/target
	else
		in_target=
		root=
	fi

	logger -t kickseed "Running $TYPE script $SCRIPT using interpreter $INTERPRETER (chrooted: $CHROOTED):"
	cp "$SCRIPT" "$root/tmp/ks-script"
	chmod 700 "$root/tmp/ks-script"
	log-output -t kickseed --pass-stdout \
		$in_target "$INTERPRETER" /tmp/ks-script
}

ks_run_handler () {
	eval "$1"
}

kickseed_post
