#!/bin/bash -efu

if [ -z "${__pipeline_sh_functions-}" ]; then
__pipeline_sh_functions=1

. /.initrd/initenv
. shell-signal

handlerdir="/lib/pipeline"
mntdir="/dev/pipeline"

check_parameter()
{
	local v
	eval "v=\"\${$1-}\""
	[ -n "$v" ] ||
		fatal "Parameter '$1' required"
}

get_parameter()
{
	eval "printf '%s' \"\${${1}$callnum-}\""
}

resolve_target()
{
	local target="$1"
	case "${target%%/*}" in
		'')
			;;
		pipe[0-9]|pipe[0-9][0-9]|pipe[0-9][0-9][0-9])
			target="$mntdir/dst/$target"
			;;
		*)
			if [ -z "${prevdir-}" ]; then
				message "no previous stop to use"
				return
			fi
			target="$prevdir/${target#/}"
			;;
	esac
	printf '%s' "$target"
}

run()
{
	[ -z "${DEBUG-}" ] || message "[$callnum] RUN: $*"
	"$@"
}

fi # __pipeline_sh_functions
