[make-initrd] [PATCH v1 30/41] fork pipeline: bootchain-sh-functions: API extended

Leonid Krivoshein klark.devel at gmail.com
Fri Sep 24 18:58:38 MSK 2021


---
  .../data/bin/bootchain-sh-functions           | 128 ++++++++++++++++++
  1 file changed, 128 insertions(+)

diff --git 
a/make-initrd/features/bootchain-core/data/bin/bootchain-sh-functions 
b/make-initrd/features/bootchain-core/data/bin/bootchain-sh-functions
index 35cee1e..f8a6e30 100644
--- a/make-initrd/features/bootchain-core/data/bin/bootchain-sh-functions
+++ b/make-initrd/features/bootchain-core/data/bin/bootchain-sh-functions
@@ -3,14 +3,38 @@
  if [ -z "${__bootchain_sh_functions-}" ]; then
  __bootchain_sh_functions=1
  +BC_DEBUG=
+BC_LOG_VT=3
+
+[ ! -s /etc/sysconfig/bootchain ] ||
+	. /etc/sysconfig/bootchain
+
  . /.initrd/initenv
  . shell-signal
  +message_time=1
+
+if [ "${ROOT-}" = pipeline ]; then
+	BC_LOGFILE="${BC_LOGFILE:-/var/log/pipelined.log}"
+	mntdir="${mntdir:-/dev/pipeline}"
+	pipeline_mode=1
+else
+	BC_LOGFILE="${BC_LOGFILE:-/var/log/bootchained.log}"
+	mntdir="${mntdir:-/dev/bootchain}"
+	pipeline_mode=
+fi
+
+[ -n "$BC_DEBUG" ] && BC_FGVT_ACTIVATE=1 ||
+	BC_FGVT_ACTIVATE="${BC_FGVT_ACTIVATE:-7}"
+BC_NEXTCHAIN=/.initrd/bootchain/bootchain.next
+BC_PASSED=/.initrd/bootchain/passed
  handlerdir=/lib/bootchain
  +
  check_parameter()
  {
  	local _v
+
  	eval "_v=\"\${$1-}\""
  	[ -n "${_v}" ] ||
  		fatal "Parameter '$1' required"
@@ -50,10 +74,114 @@ resolve_target()
  	printf '%s' "$target"
  }
  +debug()
+{
+	[ -z "$BC_DEBUG" ] ||
+		message "[$callnum] $*"
+}
+
+enter()
+{
+	debug "ENTER: $*"
+}
+
+leave()
+{
+	debug "LEAVE: $*"
+}
+
  run()
  {
  	debug "RUN: $*"
  	"$@" || return $?
  }
  +fdump()
+{
+	[ -n "$BC_DEBUG" ] && [ -f "$1" ] ||
+		return 0
+	{ printf '============================================================\n'
+	  cat -- "$1" ||:
+	  printf 
'============================================================\n\n'
+	} 1>&2
+}
+
+assign()
+{
+	local _v="" _k="$1" _e="${2-}"
+
+	eval "_v=\"${_e}\""
+	eval "${_k}=\"${_e}\""
+	debug "LET: ${_k}=\"${_v}\""
+}
+
+next_bootchain()
+{
+	local _v="${1-}"
+
+	printf 'chainsteps="%s"\n' "${_v}" >>"$BC_NEXTCHAIN"
+	debug "BOOTCHAIN REPLACED: '${_v}'"
+}
+
+is_step_passed()
+{
+	[ -f "$BC_PASSED/$PROG" ] ||
+		return 1
+}
+
+launch_step_once()
+{
+	[ ! -f "$BC_PASSED/$PROG" ] ||
+		fatal "this step has been already passed"
+}
+
+break_bc_loop()
+{
+	enter "break_bc_loop"
+
+	:> "$BC_PASSED/bootchain-loop"
+
+	leave "break_bc_loop"
+}
+
+bc_reboot()
+{
+	enter "bc_reboot"
+
+	reboot -f -d
+}
+
+bypass_results()
+{
+	enter "bypass_results"
+
+	local realdir="${1-}"
+	local srcdir="${realdir:-$prevdir}"
+
+	if [ -n "$srcdir" ] && [ "$srcdir" != "$destdir" ]; then
+		if [ -d "$realdir" ] || [ -L "$prevdir" ] ||
+			[ "$srcdir" = "${srcdir#$mntdir/}" ]
+		then
+			run rmdir -- "$destdir" ||:
+			run ln -snf -- "$(readlink-e "$srcdir")" "$destdir"
+		elif mountpoint -q -- "$prevdir"; then
+			run mkdir -p -- "$destdir"
+			run mount --move -- "$prevdir" "$destdir"
+		else
+			run rmdir -- "$destdir" ||:
+			run mv -f -- "$prevdir" "$destdir"
+		fi
+	fi
+
+	leave "bypass_results"
+}
+
+initrd_version()
+{
+	[ ! -s /etc/initrd-release ] ||
+		. /etc/initrd-release
+	local __version="${VERSION_ID-}"
+	printf '%s' "INITRAMFS${__version:+ $__version}"
+}
+
  fi # __bootchain_sh_functions
-- 
2.21.0




More information about the Make-initrd mailing list