Skip to content

Instantly share code, notes, and snippets.

@AlD
Created August 26, 2019 21:17
Show Gist options
  • Save AlD/26dd622eca640997ecbb8227261a2a43 to your computer and use it in GitHub Desktop.
Save AlD/26dd622eca640997ecbb8227261a2a43 to your computer and use it in GitHub Desktop.
#!/bin/bash
sleep_cfg=/etc/systemd/sleep.conf.d/hibernate-reboot.conf
cleanup_cfg=/usr/lib/systemd/system-sleep/hibernate-reboot.sh
sudo mkdir -p "$(dirname "$sleep_cfg")" "$(dirname "$cleanup_cfg")"
sudo tee "$sleep_cfg" << ''
[Sleep]
HibernateMode=reboot
<<< '#!/bin/bash
case "$1" in
pre) echo "[hibernate-reboot] Going to reboot after hibernation"
;;
post) rm "'"$sleep_cfg"'" "'"$cleanup_cfg"'" || true
;;
*) exit 1
;;
esac
' sudo tee "$cleanup_cfg" && sudo chmod +x "$cleanup_cfg"
systemctl hibernate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment