瀏覽代碼

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>
Michael Walle 2 年之前
父節點
當前提交
c09ee07b2c

+ 1 - 0
package/Config.in

@@ -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"

+ 10 - 0
package/hwclock-initscript/Config.in

@@ -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.

+ 39 - 0
package/hwclock-initscript/S20hwclock

@@ -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

+ 12 - 0
package/hwclock-initscript/hwclock-initscript.mk

@@ -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))