From c51013909b5eb64671902e02b9a19d0fd11fbd46 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Tue, 26 Apr 2022 18:30:05 +0200 Subject: Check for kernel source directory Some commands need to be launched inside the kernel source directory. Even though the manual points this out, users may not know or forget. Make sure to refuse working on a non-kernel directory: this will point users in the right direction and avoid doing unnecessary work. To detect a kernel source tree, check for existence of the 'Kbuild' and 'Kconfig' files. --- kern | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kern b/kern index cdd2d8d..0f19772 100755 --- a/kern +++ b/kern @@ -13,6 +13,10 @@ errx() { exit 1 } +need_kernel_source() { + test -r Kbuild -a -r Kconfig || errx "current directory does not contain a kernel source tree, refusing" +} + has_boot_mount() { awk '{print $2}' /etc/fstab | grep -q ^/boot$ } @@ -65,6 +69,7 @@ set_kernel() { } config_kernel() { + need_kernel_source host=${1:-$(hostname)} test -d "$KERNFRAG" || errx "No such file or directory: $KERNFRAG" @@ -76,6 +81,7 @@ config_kernel() { } diff_kernel() { + need_kernel_source diff=${1:-$(get_running_config)} if command -v git >/dev/null; then @@ -86,10 +92,12 @@ diff_kernel() { } build_kernel() { + need_kernel_source make -j"$(nproc)" } install_kernel() { + need_kernel_source mount_boot_on_demand sudo make install modules_install } -- cgit v1.2.3-2-gb3c3