From ad6507d87546e352422940554598a34bbb83c795 Mon Sep 17 00:00:00 2001 From: firecyberice <10451478+firecyberice@users.noreply.github.com> Date: Sat, 4 Jan 2020 12:56:51 +0100 Subject: [PATCH 1/3] set fake-hwclock --- flash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flash b/flash index 6c2f5f3..1374d51 100755 --- a/flash +++ b/flash @@ -681,7 +681,6 @@ mount_boot_disk "${disk}" "${boot}" cp "${FILE}" "${boot}/" fi - if [ -f "${boot}/device-init.yaml" ]; then echo "Setting device-init" if [ -n "${SD_HOSTNAME}" ]; then @@ -704,6 +703,11 @@ if [ -f "${boot}/device-init.yaml" ]; then fi fi +# set fake-hwclock +if [ -f "${boot}/fake-hwclock.data" ]; then + date --utc --rfc-3339=seconds |cut -d+ -f1 > "${boot}/fake-hwclock.data" +fi + # cloud-init if [ -f "${boot}/user-data" ]; then if [ -n "${SD_HOSTNAME}" ]; then From 515c0c4f4ae5736e7953ba5ecda37939a389afe2 Mon Sep 17 00:00:00 2001 From: Stefan Scherer Date: Mon, 6 Jan 2020 09:44:06 +0100 Subject: [PATCH 2/3] Fix date for macOS --- flash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flash b/flash index 1374d51..e926056 100755 --- a/flash +++ b/flash @@ -705,7 +705,7 @@ fi # set fake-hwclock if [ -f "${boot}/fake-hwclock.data" ]; then - date --utc --rfc-3339=seconds |cut -d+ -f1 > "${boot}/fake-hwclock.data" + TZ=UTC date '+%Y-%m-%d %H:%M:%S' > "${boot}/fake-hwclock.data" fi # cloud-init From 1ce3d5aedec49ed992707a10af9275cfb35c0714 Mon Sep 17 00:00:00 2001 From: Stefan Scherer Date: Mon, 6 Jan 2020 10:04:55 +0100 Subject: [PATCH 3/3] Add test for fake-hwclock.data --- test/fake-hwclock.bats | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/fake-hwclock.bats diff --git a/test/fake-hwclock.bats b/test/fake-hwclock.bats new file mode 100644 index 0000000..83b4e20 --- /dev/null +++ b/test/fake-hwclock.bats @@ -0,0 +1,34 @@ +load test_helper +export OS=$(uname -s) + +setup() { + if [ ! -f fake-hwclock.img ]; then + # download SD card image with cloud-init + curl -L -o download.img.zip https://github.com/hypriot/image-builder-rpi/releases/download/1.12.0-rc2/hypriotos-rpi-1.12.0-rc2.img.zip + unzip download.img.zip + # cut only 70 MByte to flash faster + dd if=hypriotos-rpi-1.12.0-rc2.img of=fake-hwclock.img bs=1048576 count=70 + fi + stub_diskutil +} + +teardown() { + umount_sd_boot /tmp/boot + rm -f $img + unstub_diskutil +} + +@test "fake-hwclock: flash updates fake-hwclock.data" { + expected=$(TZ=UTC date '+%Y-%m-%d %H:%M') + + run ./flash -f -d $img fake-hwclock.img + assert_success + + assert_output_contains Finished. + + mount_sd_boot $img /tmp/boot + run cat /tmp/boot/fake-hwclock.data + assert_output_contains "$expected" + + assert [ -e "/tmp/boot/fake-hwclock.data" ] +}