-
Notifications
You must be signed in to change notification settings - Fork 0
/
undo_hib.sh
executable file
·58 lines (50 loc) · 1.41 KB
/
undo_hib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
# Script to undo hibernation setup noninteractively
shopt -s nullglob extglob
sudo pacman -S mkinitcpio
lock() {
local LOCK=/tmp/hibernator.lock
if ! mkdir "$LOCK" 2> /dev/null; then
echo "Working... $LOCK"
exit
fi
trap "rm -rf $LOCK" EXIT
}
if [[ $EUID != 0 ]]; then
echo "[hibernator-undo] must be run as root"
exit 1
fi
remove_kernel_parameters() {
if [ -e /etc/default/grub ]; then
cp /etc/default/grub /etc/default/grub.old
sed -i '/resume=/d' /etc/default/grub
update-grub
fi
if [ -e /boot/refind_linux.conf ]; then
cp /boot/refind_linux.conf /boot/refind_linux.conf.old
sed -i '/resume=/d' /boot/refind_linux.conf
fi
}
remove_resume_hook() {
if grep -qs -e resume -e systemd /etc/mkinitcpio.conf; then
cp /etc/mkinitcpio.conf /etc/mkinitcpio.conf.old
sed -i '/resume/d' /etc/mkinitcpio.conf
mkinitcpio -P
fi
}
remove_swap_file() {
if grep -qs '/swapfile' /etc/fstab; then
sed -i '/\/swapfile/d' /etc/fstab
swapoff /swapfile
rm -f /swapfile
fi
}
#############################
main() {
lock
echo "Removing kernel parameters from bootloaders" && remove_kernel_parameters
echo "Removing resume hook from initramfs" && remove_resume_hook
echo "Removing swapfile" && remove_swap_file
echo "Hibernation setup has been undone."
}
main