2023-01-06 10:50:34 -05:00
|
|
|
#!/bin/bash
|
2023-01-06 13:51:45 -05:00
|
|
|
## Copyright (C) 2023 - 2023 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
|
|
|
|
## Copyright (C) 2023 - 2023 Friedrich Doku <friedrichdoku@gmail.com>
|
2023-01-06 10:50:34 -05:00
|
|
|
## See the file COPYING for copying conditions.
|
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
|
|
|
|
true "env:"
|
|
|
|
env
|
|
|
|
|
|
|
|
## Debugging.
|
|
|
|
## Lets hope $1 is set to reboot, poweroff or halt by systemd.
|
|
|
|
true "1: $1"
|
|
|
|
|
2023-01-07 11:14:31 -05:00
|
|
|
|
|
|
|
# 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#")
|
|
|
|
|
|
|
|
kernel="/boot/$kernel"
|
|
|
|
initrd="/boot/$initrd"
|
2023-01-06 12:49:34 -05:00
|
|
|
|
|
|
|
if test -e $initrd; then
|
|
|
|
echo "Initrd File Found"
|
|
|
|
else
|
|
|
|
echo "Initrd File NOT FOUND"
|
2023-01-06 12:52:36 -05:00
|
|
|
exit 1
|
2023-01-06 12:49:34 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test -e $kernel; then
|
|
|
|
echo "Kernel File Found"
|
|
|
|
else
|
|
|
|
echo "Kernel File NOT FOUND"
|
2023-01-06 12:52:36 -05:00
|
|
|
exit 1
|
2023-01-06 12:49:34 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2023-01-06 21:32:57 -05:00
|
|
|
if systemctl list-jobs | grep "poweroff.target" | grep -q "start"; then
|
|
|
|
wram="yes"
|
|
|
|
wact="poweroff"
|
|
|
|
elif systemctl list-jobs | grep "reboot.target" | grep -q "start"; then
|
|
|
|
wram="yes"
|
|
|
|
wact="reboot"
|
|
|
|
elif systemctl list-jobs | grep "halt.target" | grep -q "start"; then
|
|
|
|
wram="yes"
|
|
|
|
wact="halt"
|
|
|
|
else
|
2023-01-07 11:14:31 -05:00
|
|
|
echo "No shutdown option found!"
|
|
|
|
exit 0
|
2023-01-06 21:32:57 -05:00
|
|
|
fi
|
|
|
|
|
2023-01-06 21:40:17 -05:00
|
|
|
kexec -l $kernel --initrd=$initrd --reuse-cmdline --append="wiperamexit=$wram wiperamaction=$wact"
|