The Meowgorithm Dotfiles, Collectors’ Edition
#!/usr/bin/env bash
#
# Configure s2idle sleep and AMDGPU suspend/resume fixes for ASUS ROG Flow Z13
# (Strix Halo). Safe to re-run — idempotent, no-ops if already configured.
#
# Usage: sudo ./setup-sleep-state
#
set -euo pipefail
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (sudo)." >&2
exit 1
fi
SLEEP_DROPIN="/etc/systemd/sleep.conf.d/s2idle.conf"
OLD_SLEEP_DROPIN="/etc/systemd/sleep.conf.d/deep-sleep.conf"
AMDGPU_MODPROBE="/etc/modprobe.d/amdgpu-suspend.conf"
SLEEP_HOOK="/usr/lib/systemd/system-sleep/amdgpu-resume"
BOOTLOADER_CONF="/etc/default/grub"
NEEDS_UPDATE=false
ensure_kernel_param_in_grub() {
[[ -f "$BOOTLOADER_CONF" ]] || return 0
if grep -q 'mem_sleep_default=s2idle' "$BOOTLOADER_CONF"; then
echo "[✓] GRUB already defaults to s2idle"
elif grep -q 'mem_sleep_default=deep' "$BOOTLOADER_CONF"; then
sed -i 's/mem_sleep_default=deep/mem_sleep_default=s2idle/g' "$BOOTLOADER_CONF"
echo "[+] Replaced mem_sleep_default=deep with s2idle in $BOOTLOADER_CONF"
echo " → Run 'sudo grub-mkconfig -o /boot/grub/grub.cfg' to apply"
NEEDS_UPDATE=true
elif grep -q '^GRUB_CMDLINE_LINUX_DEFAULT=' "$BOOTLOADER_CONF"; then
sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT="\([^"]*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 mem_sleep_default=s2idle"/' "$BOOTLOADER_CONF"
echo "[+] Added mem_sleep_default=s2idle to $BOOTLOADER_CONF"
echo " → Run 'sudo grub-mkconfig -o /boot/grub/grub.cfg' to apply"
NEEDS_UPDATE=true
fi
}