diff --git a/bin/omarchy-hibernation-setup b/bin/omarchy-hibernation-setup index d88978d4..d8e32c94 100755 --- a/bin/omarchy-hibernation-setup +++ b/bin/omarchy-hibernation-setup @@ -2,13 +2,26 @@ # omarchy:summary=Set up hibernation with swap and boot resume configuration # omarchy:requires-sudo=true +# omarchy:args=[--force] [--no-rebuild] + +FORCE=false +NO_REBUILD=false +for arg in "$@"; do + case "$arg" in + --force) FORCE=true ;; + --no-rebuild) NO_REBUILD=true ;; + esac +done if [[ ! -f /sys/power/image_size ]]; then echo -e "Hibernation is not supported on your system" >&2 exit 0 fi -if ! command -v limine-mkinitcpio &>/dev/null; then +# When --no-rebuild is set, the caller is responsible for the UKI rebuild +# (e.g. running before limine-mkinitcpio-hook is installed during initial +# install), so we only require limine-mkinitcpio when we'd invoke it ourselves. +if ! $NO_REBUILD && ! command -v limine-mkinitcpio &>/dev/null; then echo "Skipping hibernation setup (requires Limine bootloader)" exit 0 fi @@ -26,15 +39,14 @@ if [[ -f $MKINITCPIO_CONF ]] && grep -q "^HOOKS+=(resume)$" "$MKINITCPIO_CONF"; echo "Fixing empty resume_offset ($RESUME_OFFSET)" sudo sed -i "s/resume_offset=\"$/resume_offset=$RESUME_OFFSET\"/" "$RESUME_DROP_IN" sudo sed -i "s/resume_offset=\"$/resume_offset=$RESUME_OFFSET\"/" /etc/default/limine - sudo limine-mkinitcpio - sudo limine-update + $NO_REBUILD || sudo limine-mkinitcpio fi fi echo "Hibernation is already set up" exit 0 fi -if [[ $1 != "--force" ]]; then +if ! $FORCE; then MEM_TOTAL_HUMAN=$(free --human | awk '/Mem/ {print $2}') if ! gum confirm "Use $MEM_TOTAL_HUMAN on boot drive to make hibernation available?"; then exit 0 @@ -105,13 +117,16 @@ if grep -q "\[s2idle\]" /sys/power/mem_sleep 2>/dev/null; then fi fi -# Regenerate initramfs and boot entry -echo "Regenerating initramfs..." -sudo limine-mkinitcpio -sudo limine-update +if ! $NO_REBUILD; then + # limine-mkinitcpio rebuilds initramfs/UKI for all kernels and updates the + # /boot/limine.conf entries via limine-entry-tool. The limine bootloader + # binary on the ESP doesn't change here, so we don't need limine-update + # (which would also re-deploy the binary and rebuild a second time). + echo "Regenerating initramfs..." + sudo limine-mkinitcpio + echo +fi -echo - -if [[ $1 != "--force" ]] && gum confirm "Reboot to enable hibernation?"; then +if ! $FORCE && ! $NO_REBUILD && gum confirm "Reboot to enable hibernation?"; then omarchy-system-reboot fi diff --git a/install/login/all.sh b/install/login/all.sh index 2c03df32..4d76d3f9 100644 --- a/install/login/all.sh +++ b/install/login/all.sh @@ -1,4 +1,5 @@ run_logged $OMARCHY_INSTALL/login/plymouth.sh run_logged $OMARCHY_INSTALL/login/default-keyring.sh run_logged $OMARCHY_INSTALL/login/sddm.sh +run_logged $OMARCHY_INSTALL/login/hibernation.sh run_logged $OMARCHY_INSTALL/login/limine-snapper.sh diff --git a/install/login/hibernation.sh b/install/login/hibernation.sh new file mode 100644 index 00000000..5983020d --- /dev/null +++ b/install/login/hibernation.sh @@ -0,0 +1,6 @@ +# Run before limine-snapper.sh so the resume hook + cmdline drop-ins are in +# place when `pacman -S limine-mkinitcpio-hook` triggers its single full UKI +# rebuild. The --no-rebuild flag tells the script to skip its own rebuild — +# limine-snapper's pacman install will produce a UKI that already includes +# hibernation. +omarchy-hibernation-setup --force --no-rebuild diff --git a/install/post-install/all.sh b/install/post-install/all.sh index d7caae25..bb5c0839 100644 --- a/install/post-install/all.sh +++ b/install/post-install/all.sh @@ -1,4 +1,3 @@ -run_logged $OMARCHY_INSTALL/post-install/hibernation.sh run_logged $OMARCHY_INSTALL/post-install/pacman.sh source $OMARCHY_INSTALL/post-install/allow-reboot.sh source $OMARCHY_INSTALL/post-install/finished.sh diff --git a/install/post-install/hibernation.sh b/install/post-install/hibernation.sh deleted file mode 100644 index 17628ead..00000000 --- a/install/post-install/hibernation.sh +++ /dev/null @@ -1,2 +0,0 @@ -# Enable hibernation -omarchy-hibernation-setup --force