Last active
February 1, 2026 15:40
-
-
Save HenkPoley/8011cad2cf94db5e80b3e9f57849f0bd to your computer and use it in GitHub Desktop.
/usr/lib/pm-utils/sleep.d/90clock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # For older motherboards where setting the clock means you'll turn off the wakeup timer/alarm. | |
| # Such as the Asus M2NPV-VM. | |
| # Useful for MythTV's `mythshutdown` trying to start your video recording computer on time. | |
| # How to set this up on Ubuntu 22.04: | |
| # sudo dpkg-divert --add --rename --local /usr/lib/pm-utils/sleep.d/90clock | |
| # vi /usr/lib/pm-utils/sleep.d/90clock | |
| . "${PM_FUNCTIONS}" | |
| RTC_WAKE=/sys/class/rtc/rtc0/wakealarm | |
| save_alarm() { | |
| [ -w "$RTC_WAKE" ] || return 0 | |
| cat "$RTC_WAKE" 2>/dev/null | |
| } | |
| restore_alarm() { | |
| ts="$1" | |
| case "$ts" in | |
| ''|0|*[!0-9]*) return 0 ;; | |
| esac | |
| [ -w "$RTC_WAKE" ] || return 0 | |
| echo 0 > "$RTC_WAKE" | |
| echo "$ts" > "$RTC_WAKE" | |
| sleep 1 | |
| echo "$ts" > "$RTC_WAKE" | |
| } | |
| is_set "$NEED_CLOCK_SYNC" || exit $NA | |
| case "$1" in | |
| hibernate|suspend) | |
| ALARM="$(save_alarm)" | |
| /sbin/hwclock --systohc >/dev/null 2>&1 | |
| restore_alarm "$ALARM" | |
| exit 0 | |
| ;; | |
| thaw|resume) | |
| /sbin/hwclock --hctosys >/dev/null 2>&1 | |
| exit 0 | |
| ;; | |
| *) exit $NA ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment