Files
omarchy/bin/omarchy-hibernation-remove
David Heinemeier Hansson 3dbebd7a4d Add option to enable/disable hibernation (#4103)
* Add option to enable/disable hibernation

* Actually do it

* Match hibernation toggle words

* Both enable and disable

* Match the tense

* Match options

* Remove excess CR
2026-01-06 22:36:40 +01:00

54 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Removes hibernation setup: disables swap, removes swapfile, removes fstab entry, and removes resume hook.
# Check if hibernation is configured
if [ ! -f /etc/mkinitcpio.conf.d/omarchy_resume.conf ] || ! grep -q "^HOOKS+=(resume)$" /etc/mkinitcpio.conf.d/omarchy_resume.conf; then
echo "Hibernation is not set up"
exit 0
fi
if gum confirm "Remove hibernation setup?"; then
SWAP_SUBVOLUME="/swap"
SWAP_FILE="$SWAP_SUBVOLUME/swapfile"
MKINITCPIO_CONF="/etc/mkinitcpio.conf.d/omarchy_resume.conf"
# Disable swap if active
if swapon --show | grep -q "$SWAP_FILE"; then
echo "Disabling swap on $SWAP_FILE"
sudo swapoff "$SWAP_FILE"
fi
# Remove swapfile
if [ -f "$SWAP_FILE" ]; then
echo "Removing swapfile"
sudo rm "$SWAP_FILE"
fi
# Remove swap subvolume
if sudo btrfs subvolume show "$SWAP_SUBVOLUME" &>/dev/null; then
echo "Removing Btrfs subvolume $SWAP_SUBVOLUME"
sudo btrfs subvolume delete "$SWAP_SUBVOLUME"
fi
# Remove fstab entry
if grep -Fq "$SWAP_FILE" /etc/fstab; then
echo "Removing swapfile from /etc/fstab"
sudo cp -a /etc/fstab "/etc/fstab.$(date +%Y%m%d%H%M%S).back"
sudo sed -i "\|$SWAP_FILE|d" /etc/fstab
# Also remove the comment line if present
sudo sed -i '/^# Btrfs swapfile for system hibernation$/d' /etc/fstab
fi
# Remove mkinitcpio resume hook
if [ -f "$MKINITCPIO_CONF" ]; then
echo "Removing resume hook from $MKINITCPIO_CONF"
sudo rm "$MKINITCPIO_CONF"
echo "Regenerating initramfs..."
sudo limine-mkinitcpio
fi
echo "Hibernation removed"
fi