package/hwclock-initscript: new package

Add a new initscript to save the date and time to the hardware clock
on shutdown.

Signed-off-by: Michael Walle <michael@walle.cc>
[Arnout:
 - package as hwclock-initscript instead of buildroot-initscripts;
 - mention in help text that it isn't needed at boot;
 - rewrite initscript according to our usual pattern;
 - fix shellcheck errors.
]
Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
This commit is contained in:
Michael Walle
2023-03-13 09:15:49 +01:00
committed by Arnout Vandecappelle
parent faf2b8a627
commit c09ee07b2c
4 changed files with 62 additions and 0 deletions

View File

@@ -2866,6 +2866,7 @@ menu "System tools"
source "package/getent/Config.in"
source "package/gkrellm/Config.in"
source "package/htop/Config.in"
source "package/hwclock-initscript/Config.in"
source "package/ibm-sw-tpm2/Config.in"
source "package/initscripts/Config.in"
source "package/iotop/Config.in"

View File

@@ -0,0 +1,10 @@
config BR2_PACKAGE_HWCLOCK_INITSCRIPT
bool "hwclock-initscript"
depends on !BR2_PACKAGE_SYSTEMD
depends on BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_UTIL_LINUX_HWCLOCK
help
Initscript to save the date and time to the hardware clock on
shutdown.
Note that the kernel already loads the time from the hwclock
at boot time, no init script is needed for that.

View File

@@ -0,0 +1,39 @@
#! /bin/sh
#
# hwclock This writes the system time to the RTC on shutdown
#
RTC_DEVICE=rtc0
DAEMON=hwclock
# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
# Quietly do nothing if /dev/rtc0 does not exist
[ -c /dev/$RTC_DEVICE ] || exit 0
start(){
: # Nothing to do on startup
}
stop(){
printf "Saving the system clock to /dev/%s\n" "${RTC_DEVICE}"
/sbin/$DAEMON -f "/dev/${RTC_DEVICE}" -w
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
;;
esac

View File

@@ -0,0 +1,12 @@
################################################################################
#
# hwclock-initscript
#
################################################################################
define HWCLOCK_INITSCRIPT_INSTALL_INIT_SYSV
$(INSTALL) -D -m 0755 $(HWCLOCK_INITSCRIPT_PKGDIR)/S20hwclock \
$(TARGET_DIR)/etc/init.d/S20hwclock
endef
$(eval $(generic-package))