From 5b289323280a3ead2440dc7022f89a29f5debe88 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 6 Oct 2019 12:57:26 -0400 Subject: initramfs hook: improve error reporting --- initramfs-tools/hooks/samizdat | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'initramfs-tools') diff --git a/initramfs-tools/hooks/samizdat b/initramfs-tools/hooks/samizdat index edbfb6d..2ab2333 100755 --- a/initramfs-tools/hooks/samizdat +++ b/initramfs-tools/hooks/samizdat @@ -2,7 +2,10 @@ # TODO: check samizdat source to see what it copies [ "$1" = prereqs ] && { echo; exit; } -CopyExec() { copy_exec "$@" || exit 1; } +die() { printf 'Error: generating initramfs: %s\n' "$*" >&2; exit 1; } + +CopyExec() { copy_exec "$@" || die "failed to copy_exec $*"; } +CopyExecE() { [ "$2" ] || die "cannot find binary to copy: $1"; shift; CopyExec "$@"; } . /usr/share/initramfs-tools/hook-functions PATH=/usr/local/lib/samizdat-rhizome/initrd:/usr/local/bin:$PATH @@ -26,19 +29,19 @@ absolute_path_copies='/lib/terminfo/l/linux /usr/bin/gpg-agent' modules='loop xts dm-crypt hfs hfsplus' modules_dirs='kernel/drivers/net/ethernet kernel/fs/nls' - - - for f in $repo_execs; do CopyExec "$f" /bin; done -for c in $path_execs; do CopyExec "$(which $c)" /bin; done +for c in $path_execs; do + s=$(which $c) + CopyExecE "$c" "$s" /bin; +done for f in $absolute_path_copies; do CopyExec "$f" "$f"; done -for m in $modules; do force_load "$m" || exit 1; done -for dir in $modules_dirs; do copy_modules_dir "$dir" || exit 1; done +for m in $modules; do force_load "$m" || die "command failed: force_load $m"; done +for dir in $modules_dirs; do copy_modules_dir "$dir" || die "command failed: copy_modules_dir $dir"; done for e in $graft_paths; do case "$e" in - *=*) CopyExec "${e#*=}" "${e%%=*}" ;; - *) exit 1 ;; + *=*) CopyExecE "graft_path $e" "${e#*=}" "${e%%=*}" ;; + *) die "(BUG) invalid graft_path: $e" ;; esac done -- cgit v1.2.3