From d37d5515f5b2d31b2875365dd724dd504e136a83 Mon Sep 17 00:00:00 2001 From: Patrick Vogelaar Date: Tue, 9 Jan 2024 15:56:28 +0100 Subject: [PATCH] feat: set default time for initial startup * all creation dates of the files are set to the 01.01. of the current year * the file /usr/lib/clock-epoch is created. It is used by timedatectl to get the initial time and date (creation time of file). * a sanity check was added to check if the hardcoded timestamp is outdated --- .../classes/coreos-sanity.bbclass | 17 ++++++++++++++--- .../conf/distro/belden-coreos.conf | 5 +++++ .../recipes-core/systemd/systemd_%.bbappend | 10 ++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 layers/meta-belden-coreos/recipes-core/systemd/systemd_%.bbappend diff --git a/layers/meta-belden-coreos/classes/coreos-sanity.bbclass b/layers/meta-belden-coreos/classes/coreos-sanity.bbclass index 5c56e3c..44dcf15 100644 --- a/layers/meta-belden-coreos/classes/coreos-sanity.bbclass +++ b/layers/meta-belden-coreos/classes/coreos-sanity.bbclass @@ -13,6 +13,8 @@ addhandler check_coreos_sanity_eventhandler check_coreos_sanity_eventhandler[eventmask] = "bb.event.SanityCheck" python check_coreos_sanity_eventhandler() { + import datetime + # Checks related to the distribution configuration files # ========================================================================== @@ -29,13 +31,22 @@ python check_coreos_sanity_eventhandler() { "systemd is not set as `INIT_MANAGER`. " "Using SystemD is mandatory on CoreOS based distribution" ) - + if e.data.getVar("TCLIBC") != "glibc": bb.fatal( "glibc is not set as `TCLIBC`. " "Using glibc is mandatory on CoreOS based distribution" ) - + + # Check if the timestamp for REPRODUCIBLE_TIMESTAMP_ROOTFS is still up to date + first_of_year = datetime.datetime(datetime.date.today().year, 1, 1, tzinfo=datetime.timezone.utc) + foy_ts = str(int(first_of_year.timestamp())) + if e.data.getVar("REPRODUCIBLE_TIMESTAMP_ROOTFS") != foy_ts: + bb.warn( + "`REPRODUCIBLE_TIMESTAMP_ROOTFS` outdated!" + "Set to current 01. january of the year." + ) + # Checks related to the machine configuration files # ========================================================================== @@ -47,7 +58,7 @@ python check_coreos_sanity_eventhandler() { "CoreOS recommands to use compressed wic image, please add " "`wic.xz` to your machine `IMAGE_FSTYPES` variables" ) - + if not "wic.bmap": bb.warn( "wic image should be flashed with bmaptools, but this require " diff --git a/layers/meta-belden-coreos/conf/distro/belden-coreos.conf b/layers/meta-belden-coreos/conf/distro/belden-coreos.conf index 4eec78e..015caa3 100644 --- a/layers/meta-belden-coreos/conf/distro/belden-coreos.conf +++ b/layers/meta-belden-coreos/conf/distro/belden-coreos.conf @@ -7,3 +7,8 @@ MAINTAINER = "Belden CoreOS Team" DISTRO_VERSION = "0.0.1" DISTRO_CODENAME = "kirkstone" + +# This TS represents 01.01.2024 generating it dynamically would cause a lot of +# things to get re-build, we need a good solution for this or change it every +# year +REPRODUCIBLE_TIMESTAMP_ROOTFS = "1704067200" \ No newline at end of file diff --git a/layers/meta-belden-coreos/recipes-core/systemd/systemd_%.bbappend b/layers/meta-belden-coreos/recipes-core/systemd/systemd_%.bbappend new file mode 100644 index 0000000..18d1afc --- /dev/null +++ b/layers/meta-belden-coreos/recipes-core/systemd/systemd_%.bbappend @@ -0,0 +1,10 @@ + +do_install:append(){ + # the creation date/time of this file will be used as initial boot time. + # Creation time will be set to REPRODUCIBLE_TIMESTAMP_ROOTFS + # More info about the date/time handling here: + # https://www.freedesktop.org/software/systemd/man/latest/systemd-timesyncd.service.html + touch ${D}/${base_libdir}/clock-epoch +} + +FILES:${PN} += "${base_libdir}/clock-epoch"