Bug#1089042: refuses to run hook scripts written in anything but sh
Package: initramfs-tools-core
Version: 0.145
Severity: normal
Tags: patch
Hi,
in /usr/share/initramfs-tools/hook-functions, line 926, you invoke sh -n on hook scripts and skip hook scripts that fail to validate as sh scripts. This makes it effectively impossible to use a hook written in anything other than sh.
However, the section on hook scripts in initramfs-tools(8) doesn't say that scripts have to be valid Bourne shell scripts in order to be run.
I think it would be best to let the user deal with errors in their own hook scripts instead of almost-silently skipping the ones that were written in something other than `sh`.
The next-best thing would be to only invoke `sh -n` on sh scripts; e.g. something like this:
# skip bad syntax
if head -n 1 "${si_x}" | grep -Eq '^#!/bin/sh([[:space:]].*?)'; then
if ! sh -n "${si_x}" ; then
[ "${verbose}" = "y" ] \
&& echo "$si_x ignored: bad syntax" >&2
continue
fi
fi
As a last resort, you could amend the documentation to say that all hook scripts *must* be valid Bourne sh scripts; but I think it would be pretty backwards to forbid running "plugins" whose syntax the main script can't validate.
(Re "almost silently": I don't know where the "ignored: bad syntax" message goes, but it doesn't make it to the console. All I had was '/etc/initramfs-tools/hooks/myhook: 50: Syntax error: "(" unexpected'.)
András
-- System Information:
Debian Release: trixie/sid
APT prefers stable-security
APT policy: (500, 'stable-security'), (350, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 6.11.10-amd64 (SMP w/8 CPU threads; PREEMPT)
Init: runit (via /run/runit.stopit)
--
Moses was the first person to use Control-C as a shortcut.
Reply to: