set-datetime: Make timesyncd behave in the face of broken time

The set-datetime runonce would set the time correctly for the first boot, but
subsequent boots would fail to persist the change due to broken behavior on the
part of systemd-timesyncd.

We now stop systemd-timesyncd, forcibly set its clock timestamp file, and then
reboot to avoid this broken behavior.

Change-Id: Ib5950b3ce917724e88aeff19e408d05f549f3882
diff --git a/debian/changelog b/debian/changelog
index a293f2a..1b493e3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+mendel-minimal (6-1) mendel-beaker; urgency=medium
+
+  * Updates set-datetime to sync to the hardware clock using hwclock and sets
+    systemd-timesyncd's timestamp file to ensure persistence across reboots.
+
+ -- AIY Projects <support-aiyprojects@google.com>  Thu, 21 Feb 2019 11:31:00 -0800
+
 mendel-minimal (5-1) mendel-beaker; urgency=medium
 
   * Fixes set-datetime to stop timesyncd and restart it when
diff --git a/debian/control b/debian/control
index b888240..59ba4a1 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,7 @@
 Priority: optional
 Architecture: all
 Depends: e2fsprogs(>=1.43), adduser, sudo, openssh-server, locales, avahi-daemon,
-  bluez, network-manager, passwd, python2.7, runonce, ${misc:Depends}
+  bluez, network-manager, passwd, python2.7, runonce, util-linux, ${misc:Depends}
 Description: Defines the files and packages for a minimal Mendel install
  This package contains the initial "run once" scripts that perform
  initial startup work such as resizing the root filesystem to match the emmc
diff --git a/etc/runonce.d/98-set-datetime b/etc/runonce.d/98-set-datetime
index 97c2b51..d12a019 100755
--- a/etc/runonce.d/98-set-datetime
+++ b/etc/runonce.d/98-set-datetime
@@ -1,6 +1,14 @@
 #!/bin/bash
 
+TIMESTAMP_FILE=/var/lib/systemd/clock
 PROGNAME=$(basename $(readlink -f $0))
+
 systemctl stop systemd-timesyncd
+
 date --set="$(stat /lost+found |grep Change |sed -e 's/^Change: //g' -e 's/+0000//g')"
+hwclock --systohc
+rm -f $TIMESTAMP_FILE
+touch $TIMESTAMP_FILE
+
 systemctl start systemd-timesyncd
+