Message ID | 934f188717e95b8c019736e4546d57e90a247327.1731358224.git.jan.kiszka@siemens.com |
---|---|
State | Superseded, archived |
Headers | show |
Series | [1/7] initramfs-hook: Add infrastructure to ease writing hooks | expand |
On 11/11/24 21:50, Jan Kiszka wrote: > From: Jan Kiszka <jan.kiszka@siemens.com> > > xxx Some Documentation is missing > > Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> > --- > .../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++ > .../initramfs-hook/files/script-header.tmpl | 26 +++++++ > .../recipes-initramfs/initramfs-hook/hook.inc | 74 +++++++++++++++++++ > 3 files changed, 139 insertions(+) > create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl > create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl > create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc > > diff --git a/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl > new file mode 100644 > index 00000000..ee30d691 > --- /dev/null > +++ b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl > @@ -0,0 +1,39 @@ > +#!/bin/sh > +# > +# Copyright (c) Siemens AG, 2024 > +# > +# Authors: > +# Jan Kiszka <jan.kiszka@siemens.com> > +# > +# SPDX-License-Identifier: MIT > +# > + > +set -e > + > +prereqs() > +{ > + echo "${HOOK_PREREQ}" > +} > + > +case $1 in > +prereqs) > + prereqs > + exit 0 > + ;; > +esac > + > +. /usr/share/initramfs-tools/hook-functions > + > +for module in ${HOOK_ADD_MODULES}; do > + manual_add_modules $module > +done > + > +for executable in ${HOOK_COPY_EXECS}; do > + if exec_path=$(command -v $executable 2>/dev/null); then > + copy_exec "$exec_path" > + else > + echo "(ERROR): Unable to copy $executable" >&2 > + exit 1 > + fi > +done > + > diff --git a/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl > new file mode 100644 > index 00000000..faa1a644 > --- /dev/null > +++ b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl > @@ -0,0 +1,26 @@ > +#!/bin/sh > +# > +# Copyright (c) Siemens AG, 2024 > +# > +# Authors: > +# Jan Kiszka <jan.kiszka@siemens.com> > +# > +# SPDX-License-Identifier: MIT > +# > + > +set -e > + > +prereqs() > +{ > + echo "${SCRIPT_PREREQ}" > +} > + > +case $1 in > +prereqs) > + prereqs > + exit 0 > + ;; > +esac > + > +. /scripts/functions > + > diff --git a/meta/recipes-initramfs/initramfs-hook/hook.inc b/meta/recipes-initramfs/initramfs-hook/hook.inc > new file mode 100644 > index 00000000..5509c074 > --- /dev/null > +++ b/meta/recipes-initramfs/initramfs-hook/hook.inc > @@ -0,0 +1,74 @@ > +# > +# Copyright (c) Siemens AG, 2024 > +# > +# Authors: > +# Jan Kiszka <jan.kiszka@siemens.com> > +# > +# SPDX-License-Identifier: MIT > +# > + > +FILESPATH:append := ":${FILE_DIRNAME}/files" > + > +inherit dpkg-raw > + > +SRC_URI = " \ > + file://hook-header.tmpl \ > + file://script-header.tmpl" > + > +TEMPLATE_FILES = " \ > + hook-header.tmpl \ > + script-header.tmpl" > + > +TEMPLATE_VARS:append = " \ > + HOOK_PREREQ \ > + HOOK_ADD_MODULES \ > + HOOK_COPY_EXECS \ > + SCRIPT_PREREQ" > + > +HOOK_PREREQ ?= "" > +HOOK_ADD_MODULES ?= "" > +HOOK_COPY_EXECS ?= "" > +SCRIPT_PREREQ ?= "" > + > +DEBIAN_DEPENDS = "initramfs-tools" > + > +def get_initramfs_hook_name(d): > + name = d.getVar('BPN') > + if name.startswith("initramfs-"): > + name = name[10:] > + if name.endswith("-hook"): > + name = name[:-5] > + return name > + > +INITRAMFS_HOOK_NAME ?= "${@get_initramfs_hook_name(d)}" > + > +do_install() { > + if [ -f "${WORKDIR}/hook" ] || [ -n "${HOOK_COPY_EXECS}" ] || \ > + [ -n "${HOOK_ADD_MODULES}" ]; then > + rm -rf "${D}/usr/share/initramfs-tools/hooks" > + install -d -m 0755 "${D}/usr/share/initramfs-tools/hooks" > + > + install -m 0755 "${WORKDIR}/hook-header" \ > + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" > + if [ -f "${WORKDIR}/hook" ]; then > + cat "${WORKDIR}/hook" >> \ > + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" > + else > + echo "exit 0" >> \ > + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" > + fi > + fi > + > + for script in init-top init-premount local-top nfs-top local-block \ > + local-premount nfs-premount local-bottom nfs-bottom \ > + init-bottom; do > + if [ ! -f "${WORKDIR}/$script" ]; then > + continue > + fi > + > + rm -rf "${D}/usr/share/initramfs-tools/scripts/$script" > + install -d -m 0755 "${D}/usr/share/initramfs-tools/scripts/$script" > + install -m 0755 "${WORKDIR}/$script" \ > + "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}" > + done > +}
On 11/11/24 21:50, Jan Kiszka wrote: > From: Jan Kiszka <jan.kiszka@siemens.com> > > xxx > > Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> > --- > .../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++ > .../initramfs-hook/files/script-header.tmpl | 26 +++++++ > .../recipes-initramfs/initramfs-hook/hook.inc | 74 +++++++++++++++++++ > 3 files changed, 139 insertions(+) > create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl > create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl > create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc > > diff --git a/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl > new file mode 100644 > index 00000000..ee30d691 > --- /dev/null > +++ b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl > @@ -0,0 +1,39 @@ > +#!/bin/sh > +# > +# Copyright (c) Siemens AG, 2024 > +# > +# Authors: > +# Jan Kiszka <jan.kiszka@siemens.com> > +# > +# SPDX-License-Identifier: MIT > +# > + > +set -e > + > +prereqs() > +{ > + echo "${HOOK_PREREQ}" > +} > + > +case $1 in > +prereqs) > + prereqs > + exit 0 > + ;; > +esac > + > +. /usr/share/initramfs-tools/hook-functions > + > +for module in ${HOOK_ADD_MODULES}; do > + manual_add_modules $module > +done > + > +for executable in ${HOOK_COPY_EXECS}; do > + if exec_path=$(command -v $executable 2>/dev/null); then > + copy_exec "$exec_path" > + else > + echo "(ERROR): Unable to copy $executable" >&2 > + exit 1 > + fi > +done > + > diff --git a/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl > new file mode 100644 > index 00000000..faa1a644 > --- /dev/null > +++ b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl > @@ -0,0 +1,26 @@ > +#!/bin/sh > +# > +# Copyright (c) Siemens AG, 2024 > +# > +# Authors: > +# Jan Kiszka <jan.kiszka@siemens.com> > +# > +# SPDX-License-Identifier: MIT > +# > + > +set -e > + > +prereqs() > +{ > + echo "${SCRIPT_PREREQ}" > +} > + > +case $1 in > +prereqs) > + prereqs > + exit 0 > + ;; > +esac > + > +. /scripts/functions > + > diff --git a/meta/recipes-initramfs/initramfs-hook/hook.inc b/meta/recipes-initramfs/initramfs-hook/hook.inc > new file mode 100644 > index 00000000..5509c074 > --- /dev/null > +++ b/meta/recipes-initramfs/initramfs-hook/hook.inc > @@ -0,0 +1,74 @@ > +# > +# Copyright (c) Siemens AG, 2024 > +# > +# Authors: > +# Jan Kiszka <jan.kiszka@siemens.com> > +# > +# SPDX-License-Identifier: MIT > +# > + > +FILESPATH:append := ":${FILE_DIRNAME}/files" > + > +inherit dpkg-raw > + > +SRC_URI = " \ > + file://hook-header.tmpl \ > + file://script-header.tmpl" > + > +TEMPLATE_FILES = " \ > + hook-header.tmpl \ > + script-header.tmpl" > + > +TEMPLATE_VARS:append = " \ > + HOOK_PREREQ \ > + HOOK_ADD_MODULES \ > + HOOK_COPY_EXECS \ > + SCRIPT_PREREQ" > + > +HOOK_PREREQ ?= "" > +HOOK_ADD_MODULES ?= "" > +HOOK_COPY_EXECS ?= "" > +SCRIPT_PREREQ ?= "" > + > +DEBIAN_DEPENDS = "initramfs-tools" > + > +def get_initramfs_hook_name(d): > + name = d.getVar('BPN') > + if name.startswith("initramfs-"): > + name = name[10:] > + if name.endswith("-hook"): > + name = name[:-5] > + return name > + > +INITRAMFS_HOOK_NAME ?= "${@get_initramfs_hook_name(d)}" > + > +do_install() { > + if [ -f "${WORKDIR}/hook" ] || [ -n "${HOOK_COPY_EXECS}" ] || \ > + [ -n "${HOOK_ADD_MODULES}" ]; then > + rm -rf "${D}/usr/share/initramfs-tools/hooks" > + install -d -m 0755 "${D}/usr/share/initramfs-tools/hooks" > + > + install -m 0755 "${WORKDIR}/hook-header" \ > + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" > + if [ -f "${WORKDIR}/hook" ]; then > + cat "${WORKDIR}/hook" >> \ > + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" > + else > + echo "exit 0" >> \ > + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" > + fi > + fi > + > + for script in init-top init-premount local-top nfs-top local-block \ > + local-premount nfs-premount local-bottom nfs-bottom \ > + init-bottom; do This supports only on file per folder is this intentional? Quirin > + if [ ! -f "${WORKDIR}/$script" ]; then > + continue > + fi > + > + rm -rf "${D}/usr/share/initramfs-tools/scripts/$script" > + install -d -m 0755 "${D}/usr/share/initramfs-tools/scripts/$script" > + install -m 0755 "${WORKDIR}/$script" \ > + "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}" > + done > +}
On 12.11.24 11:14, Quirin Gylstorff wrote: > > > On 11/11/24 21:50, Jan Kiszka wrote: >> From: Jan Kiszka <jan.kiszka@siemens.com> >> >> xxx Oops, forgotten to finish this. >> >> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> >> --- >> .../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++ >> .../initramfs-hook/files/script-header.tmpl | 26 +++++++ >> .../recipes-initramfs/initramfs-hook/hook.inc | 74 +++++++++++++++++++ >> 3 files changed, 139 insertions(+) >> create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook- >> header.tmpl >> create mode 100644 meta/recipes-initramfs/initramfs-hook/files/ >> script-header.tmpl >> create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc >> >> diff --git a/meta/recipes-initramfs/initramfs-hook/files/hook- >> header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/hook- >> header.tmpl >> new file mode 100644 >> index 00000000..ee30d691 >> --- /dev/null >> +++ b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl >> @@ -0,0 +1,39 @@ >> +#!/bin/sh >> +# >> +# Copyright (c) Siemens AG, 2024 >> +# >> +# Authors: >> +# Jan Kiszka <jan.kiszka@siemens.com> >> +# >> +# SPDX-License-Identifier: MIT >> +# >> + >> +set -e >> + >> +prereqs() >> +{ >> + echo "${HOOK_PREREQ}" >> +} >> + >> +case $1 in >> +prereqs) >> + prereqs >> + exit 0 >> + ;; >> +esac >> + >> +. /usr/share/initramfs-tools/hook-functions >> + >> +for module in ${HOOK_ADD_MODULES}; do >> + manual_add_modules $module >> +done >> + >> +for executable in ${HOOK_COPY_EXECS}; do >> + if exec_path=$(command -v $executable 2>/dev/null); then >> + copy_exec "$exec_path" >> + else >> + echo "(ERROR): Unable to copy $executable" >&2 >> + exit 1 >> + fi >> +done >> + >> diff --git a/meta/recipes-initramfs/initramfs-hook/files/script- >> header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/script- >> header.tmpl >> new file mode 100644 >> index 00000000..faa1a644 >> --- /dev/null >> +++ b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl >> @@ -0,0 +1,26 @@ >> +#!/bin/sh >> +# >> +# Copyright (c) Siemens AG, 2024 >> +# >> +# Authors: >> +# Jan Kiszka <jan.kiszka@siemens.com> >> +# >> +# SPDX-License-Identifier: MIT >> +# >> + >> +set -e >> + >> +prereqs() >> +{ >> + echo "${SCRIPT_PREREQ}" >> +} >> + >> +case $1 in >> +prereqs) >> + prereqs >> + exit 0 >> + ;; >> +esac >> + >> +. /scripts/functions >> + >> diff --git a/meta/recipes-initramfs/initramfs-hook/hook.inc b/meta/ >> recipes-initramfs/initramfs-hook/hook.inc >> new file mode 100644 >> index 00000000..5509c074 >> --- /dev/null >> +++ b/meta/recipes-initramfs/initramfs-hook/hook.inc >> @@ -0,0 +1,74 @@ >> +# >> +# Copyright (c) Siemens AG, 2024 >> +# >> +# Authors: >> +# Jan Kiszka <jan.kiszka@siemens.com> >> +# >> +# SPDX-License-Identifier: MIT >> +# >> + >> +FILESPATH:append := ":${FILE_DIRNAME}/files" >> + >> +inherit dpkg-raw >> + >> +SRC_URI = " \ >> + file://hook-header.tmpl \ >> + file://script-header.tmpl" >> + >> +TEMPLATE_FILES = " \ >> + hook-header.tmpl \ >> + script-header.tmpl" >> + >> +TEMPLATE_VARS:append = " \ >> + HOOK_PREREQ \ >> + HOOK_ADD_MODULES \ >> + HOOK_COPY_EXECS \ >> + SCRIPT_PREREQ" >> + >> +HOOK_PREREQ ?= "" >> +HOOK_ADD_MODULES ?= "" >> +HOOK_COPY_EXECS ?= "" >> +SCRIPT_PREREQ ?= "" >> + >> +DEBIAN_DEPENDS = "initramfs-tools" >> + >> +def get_initramfs_hook_name(d): >> + name = d.getVar('BPN') >> + if name.startswith("initramfs-"): >> + name = name[10:] >> + if name.endswith("-hook"): >> + name = name[:-5] >> + return name >> + >> +INITRAMFS_HOOK_NAME ?= "${@get_initramfs_hook_name(d)}" >> + >> +do_install() { >> + if [ -f "${WORKDIR}/hook" ] || [ -n "${HOOK_COPY_EXECS}" ] || \ >> + [ -n "${HOOK_ADD_MODULES}" ]; then >> + rm -rf "${D}/usr/share/initramfs-tools/hooks" >> + install -d -m 0755 "${D}/usr/share/initramfs-tools/hooks" >> + >> + install -m 0755 "${WORKDIR}/hook-header" \ >> + "${D}/usr/share/initramfs-tools/hooks/ >> ${INITRAMFS_HOOK_NAME}" >> + if [ -f "${WORKDIR}/hook" ]; then >> + cat "${WORKDIR}/hook" >> \ >> + "${D}/usr/share/initramfs-tools/hooks/ >> ${INITRAMFS_HOOK_NAME}" >> + else >> + echo "exit 0" >> \ >> + "${D}/usr/share/initramfs-tools/hooks/ >> ${INITRAMFS_HOOK_NAME}" >> + fi >> + fi >> + >> + for script in init-top init-premount local-top nfs-top local-block \ >> + local-premount nfs-premount local-bottom nfs-bottom \ >> + init-bottom; do > This supports only on file per folder is this intentional? Yes, until someone can tell me a valid use case where one hook would need multiple boot scripts (not talking about helpers that would be called by the a boot script). Jan >> + if [ ! -f "${WORKDIR}/$script" ]; then >> + continue >> + fi >> + >> + rm -rf "${D}/usr/share/initramfs-tools/scripts/$script" >> + install -d -m 0755 "${D}/usr/share/initramfs-tools/scripts/ >> $script" > >> + install -m 0755 "${WORKDIR}/$script" \ >> + "${D}/usr/share/initramfs-tools/scripts/$script/ >> ${INITRAMFS_HOOK_NAME}" >> + done >> +} >
diff --git a/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl new file mode 100644 index 00000000..ee30d691 --- /dev/null +++ b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Copyright (c) Siemens AG, 2024 +# +# Authors: +# Jan Kiszka <jan.kiszka@siemens.com> +# +# SPDX-License-Identifier: MIT +# + +set -e + +prereqs() +{ + echo "${HOOK_PREREQ}" +} + +case $1 in +prereqs) + prereqs + exit 0 + ;; +esac + +. /usr/share/initramfs-tools/hook-functions + +for module in ${HOOK_ADD_MODULES}; do + manual_add_modules $module +done + +for executable in ${HOOK_COPY_EXECS}; do + if exec_path=$(command -v $executable 2>/dev/null); then + copy_exec "$exec_path" + else + echo "(ERROR): Unable to copy $executable" >&2 + exit 1 + fi +done + diff --git a/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl new file mode 100644 index 00000000..faa1a644 --- /dev/null +++ b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl @@ -0,0 +1,26 @@ +#!/bin/sh +# +# Copyright (c) Siemens AG, 2024 +# +# Authors: +# Jan Kiszka <jan.kiszka@siemens.com> +# +# SPDX-License-Identifier: MIT +# + +set -e + +prereqs() +{ + echo "${SCRIPT_PREREQ}" +} + +case $1 in +prereqs) + prereqs + exit 0 + ;; +esac + +. /scripts/functions + diff --git a/meta/recipes-initramfs/initramfs-hook/hook.inc b/meta/recipes-initramfs/initramfs-hook/hook.inc new file mode 100644 index 00000000..5509c074 --- /dev/null +++ b/meta/recipes-initramfs/initramfs-hook/hook.inc @@ -0,0 +1,74 @@ +# +# Copyright (c) Siemens AG, 2024 +# +# Authors: +# Jan Kiszka <jan.kiszka@siemens.com> +# +# SPDX-License-Identifier: MIT +# + +FILESPATH:append := ":${FILE_DIRNAME}/files" + +inherit dpkg-raw + +SRC_URI = " \ + file://hook-header.tmpl \ + file://script-header.tmpl" + +TEMPLATE_FILES = " \ + hook-header.tmpl \ + script-header.tmpl" + +TEMPLATE_VARS:append = " \ + HOOK_PREREQ \ + HOOK_ADD_MODULES \ + HOOK_COPY_EXECS \ + SCRIPT_PREREQ" + +HOOK_PREREQ ?= "" +HOOK_ADD_MODULES ?= "" +HOOK_COPY_EXECS ?= "" +SCRIPT_PREREQ ?= "" + +DEBIAN_DEPENDS = "initramfs-tools" + +def get_initramfs_hook_name(d): + name = d.getVar('BPN') + if name.startswith("initramfs-"): + name = name[10:] + if name.endswith("-hook"): + name = name[:-5] + return name + +INITRAMFS_HOOK_NAME ?= "${@get_initramfs_hook_name(d)}" + +do_install() { + if [ -f "${WORKDIR}/hook" ] || [ -n "${HOOK_COPY_EXECS}" ] || \ + [ -n "${HOOK_ADD_MODULES}" ]; then + rm -rf "${D}/usr/share/initramfs-tools/hooks" + install -d -m 0755 "${D}/usr/share/initramfs-tools/hooks" + + install -m 0755 "${WORKDIR}/hook-header" \ + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" + if [ -f "${WORKDIR}/hook" ]; then + cat "${WORKDIR}/hook" >> \ + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" + else + echo "exit 0" >> \ + "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}" + fi + fi + + for script in init-top init-premount local-top nfs-top local-block \ + local-premount nfs-premount local-bottom nfs-bottom \ + init-bottom; do + if [ ! -f "${WORKDIR}/$script" ]; then + continue + fi + + rm -rf "${D}/usr/share/initramfs-tools/scripts/$script" + install -d -m 0755 "${D}/usr/share/initramfs-tools/scripts/$script" + install -m 0755 "${WORKDIR}/$script" \ + "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}" + done +}