security-misc/usr/libexec/security-misc/cold-boot-attack-defense-kexec-prepare
Patrick Schleizer 996c6af2d8
lower debugging
2023-01-07 16:31:23 -05:00

47 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
## Copyright (C) 2023 - 2023 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
## Copyright (C) 2023 - 2023 Friedrich Doku <friedrichdoku@gmail.com>
## See the file COPYING for copying conditions.
#set -x
set -e
## Get the kernel command-line arguments
cmdline=$(cat /proc/cmdline)
## Get the current boot image
kernel=$(echo "$cmdline" | grep -o 'BOOT_IMAGE=\S*' | cut -d '=' -f 2)
initrd=$(echo "$kernel" | sed "s#vmlinuz#initrd.img#")
if ! test -r "$initrd"; then
echo "$0: ERROR: Initrd File '$initrd' not found or not readable!"
exit 1
fi
if ! test -r "$kernel"; then
echo "$0: ERROR: Kernel File '$kernel' not found or not readable!"
exit 1
fi
if systemctl list-jobs --no-legend | grep "poweroff.target" | grep -q "start"; then
wiperamexit="yes"
wiperamaction="poweroff"
elif systemctl list-jobs --no-legend | grep "reboot.target" | grep -q "start"; then
wiperamexit="yes"
wiperamaction="reboot"
elif systemctl list-jobs --no-legend | grep "halt.target" | grep -q "start"; then
wiperamexit="yes"
wiperamaction="halt"
else
## Could be kexec.target.
echo "$0: INFO: Neither poweroff, reboot or halt. Therefore skipping kexec load, ok."
exit 0
fi
## Debugging.
echo kexec --load "$kernel" --initrd="$initrd" --reuse-cmdline --append="wiperamexit=$wiperamexit wiperamaction=$wiperamaction"
kexec --load "$kernel" --initrd="$initrd" --reuse-cmdline --append="wiperamexit=$wiperamexit wiperamaction=$wiperamaction"
echo "$0: OK."