diff --git a/Makefile b/Makefile index 7e54172..45b619a 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,16 @@ sysctldir := $(shell pkg-config --define-variable=prefix=$(prefix) --variable=sy dracutmodulesdir := $(shell pkg-config --define-variable=prefix=$(prefix) --variable=dracutmodulesdir dracut 2>/dev/null \ || echo $(libdir)/dracut/modules.d/) -all: +kdump-load.sh: kdump-load.header common.sh kdump-load.sh.in + cat $^ > $@ + +module-setup.sh: module-setup.header common.sh module-setup.sh.in + cat $^ > $@ + +save-dumps.sh: save-dumps.header common.sh save-dumps.sh.in + cat $^ > $@ + +all: kdump-load.sh module-setup.sh save-dumps.sh install: all install -D -m0644 kdump-init.service $(DESTDIR)$(systemdunitsdir)/kdump-init.service diff --git a/common.sh b/common.sh new file mode 100644 index 0000000..6e378b4 --- /dev/null +++ b/common.sh @@ -0,0 +1,21 @@ + +# This function has the purpose of loading the necessary external +# variables, in the form of one (or more) configuration file(s). If the +# procedure fails, we must abort - otherwise it'll fail in a later stage. +load_kdump_config() { + HAVE_CFG_FILES=0 + shopt -s nullglob + for cfg in "/usr/share/kdump.d"/*; do + if [ -f "$cfg" ]; then + . "$cfg" + HAVE_CFG_FILES=1 + fi + done + shopt -u nullglob + + if [ ${HAVE_CFG_FILES} -eq 0 ]; then + logger "kdump: no config files in /usr/share/kdump.d/ - aborting." + exit 1 + fi +} + diff --git a/kdump-load.header b/kdump-load.header new file mode 100644 index 0000000..e728cf9 --- /dev/null +++ b/kdump-load.header @@ -0,0 +1,14 @@ +#!/bin/bash +set -uo pipefail +# +# SPDX-License-Identifier: LGPL-2.1+ +# +# Copyright (c) 2021 Valve. +# Maintainer: Guilherme G. Piccoli +# +# Script that loads the panic kdump (from within a systemd service) and/or +# configures the Pstore-RAM mechanism. If the proper parameters are passed +# also, either it creates the minimal kdump initramfs for the running kernel +# or removes all the previously created ones. Since it runs on boot time, +# extra care is required to avoid boot hangs. +# diff --git a/kdump-load.sh b/kdump-load.sh.in similarity index 86% rename from kdump-load.sh rename to kdump-load.sh.in index e3d5f77..44187c3 100644 --- a/kdump-load.sh +++ b/kdump-load.sh.in @@ -1,18 +1,3 @@ -#!/bin/bash -set -uo pipefail -# -# SPDX-License-Identifier: LGPL-2.1+ -# -# Copyright (c) 2021 Valve. -# Maintainer: Guilherme G. Piccoli -# -# Script that loads the panic kdump (from within a systemd service) and/or -# configures the Pstore-RAM mechanism. If the proper parameters are passed -# also, either it creates the minimal kdump initramfs for the running kernel -# or removes all the previously created ones. Since it runs on boot time, -# extra care is required to avoid boot hangs. -# - # This function has 2 purposes: if 'kdump' is passed as argument and we don't # have crashkernel memory reserved, we edit grub config file and recreate # grub.cfg, so next boot has it reserved; in this case, we also bail-out, @@ -86,21 +71,7 @@ cleanup_unused_initrd() { rm -f "${INSTALLED_KERNELS}" } -# Load the necessary external variables, otherwise it'll fail later. -HAVE_CFG_FILES=0 -shopt -s nullglob -for cfg in "/usr/share/kdump.d"/*; do - if [ -f "$cfg" ]; then - . "$cfg" - HAVE_CFG_FILES=1 - fi -done -shopt -u nullglob - -if [ ${HAVE_CFG_FILES} -eq 0 ]; then - logger "kdump: no config files in /usr/share/kdump.d/ - aborting." - exit 1 -fi +load_kdump_config # Find the proper mount point expected for kdump collection: DEVN_MOUNTED="$(findmnt "${MOUNT_DEVNODE}" -fno TARGET)" diff --git a/module-setup.header b/module-setup.header new file mode 100644 index 0000000..bfc5c28 --- /dev/null +++ b/module-setup.header @@ -0,0 +1,10 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1+ +# +# Copyright (c) 2021 Valve. +# Maintainer: Guilherme G. Piccoli +# +# Kdump-initrd module construction/inclusion script for +# Dracut-based initramfs. +# diff --git a/module-setup.sh b/module-setup.sh.in similarity index 68% rename from module-setup.sh rename to module-setup.sh.in index e508459..2d0b3cb 100644 --- a/module-setup.sh +++ b/module-setup.sh.in @@ -1,14 +1,3 @@ -#!/bin/bash -# -# SPDX-License-Identifier: LGPL-2.1+ -# -# Copyright (c) 2021 Valve. -# Maintainer: Guilherme G. Piccoli -# -# Kdump-initrd module construction/inclusion script for -# Dracut-based initramfs. -# - # Only include kdump if it is explicitly asked in the argument list check() { return 255 @@ -25,21 +14,7 @@ install() { exit 1 fi - # Load the necessary external variables, otherwise it'll fail later. - HAVE_CFG_FILES=0 - shopt -s nullglob - for cfg in "/usr/share/kdump.d"/*; do - if [ -f "$cfg" ]; then - . "$cfg" - HAVE_CFG_FILES=1 - fi - done - shopt -u nullglob - - if [ ${HAVE_CFG_FILES} -eq 0 ]; then - logger "kdump: no config files in /usr/share/kdump.d/ - aborting." - exit 1 - fi + load_kdump_config # First clear all unnecessary firmwares/drivers added by drm in order # to reduce the size of the minimal initramfs being created. This diff --git a/save-dumps.header b/save-dumps.header new file mode 100644 index 0000000..ea0191a --- /dev/null +++ b/save-dumps.header @@ -0,0 +1,11 @@ +#!/bin/bash +set -uo pipefail +# +# SPDX-License-Identifier: LGPL-2.1+ +# +# Copyright (c) 2021 Valve. +# Maintainer: Guilherme G. Piccoli +# +# This is the kdump/pstore log collector; this script prepares the +# collected data and save it in the local disk, in the next successful boot. +# diff --git a/save-dumps.sh b/save-dumps.sh.in similarity index 84% rename from save-dumps.sh rename to save-dumps.sh.in index 08fef74..90ae2c7 100644 --- a/save-dumps.sh +++ b/save-dumps.sh.in @@ -1,30 +1,4 @@ -#!/bin/bash -set -uo pipefail -# -# SPDX-License-Identifier: LGPL-2.1+ -# -# Copyright (c) 2021 Valve. -# Maintainer: Guilherme G. Piccoli -# -# This is the kdump/pstore log collector; this script prepares the -# collected data and save it in the local disk, in the next successful boot. -# - -# Load the necessary external variables, otherwise it'll fail later. -HAVE_CFG_FILES=0 -shopt -s nullglob -for cfg in "/usr/share/kdump.d"/*; do - if [ -f "$cfg" ]; then - . "$cfg" - HAVE_CFG_FILES=1 - fi -done -shopt -u nullglob - -if [ ${HAVE_CFG_FILES} -eq 0 ]; then - logger "kdump: no config files in /usr/share/kdump.d/ - aborting." - exit 1 -fi +load_kdump_config MAIN_FOLDER="$(cat "${MNT_TMP}")" rm -f "${MNT_TMP}"