summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Kaspar Rudert (mortzu)2020-06-01 15:39:20 +0200
committerMoritz Kaspar Rudert (mortzu)2020-06-01 15:40:43 +0200
commit16aa73a92645ba816f8abe1fe2114fcc4bc5c38a (patch)
tree6e792f6a865705aa6d591150910c8e56a573ca68
downloadaur-16aa73a92645ba816f8abe1fe2114fcc4bc5c38a.tar.gz
Initial commit
-rw-r--r--.SRCINFO18
-rw-r--r--PKGBUILD26
-rw-r--r--fake-hwclock-save.service9
-rw-r--r--fake-hwclock-save.timer10
-rw-r--r--fake-hwclock.install10
-rw-r--r--fake-hwclock.service12
-rw-r--r--fake-hwclock.sh37
7 files changed, 122 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..ac09fd4abdd6
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,18 @@
+pkgbase = fake-hwclock
+ pkgdesc = Saves time on shutdown and restores it on boot from a file
+ pkgver = 0.3
+ pkgrel = 1
+ install = fake-hwclock.install
+ arch = any
+ license = GPL
+ source = fake-hwclock.sh
+ source = fake-hwclock.service
+ source = fake-hwclock-save.service
+ source = fake-hwclock-save.timer
+ md5sums = ebba7a7f7e4018dc756aab29877bec39
+ md5sums = fa52aac3db246575c3cc8c1bf608766c
+ md5sums = 9f93ed2b74260d204a9c285d35ee2daa
+ md5sums = b2b494cb4ba99eb12df3cb4188902ca4
+
+pkgname = fake-hwclock
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..1cc5b4f0261b
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,26 @@
+pkgname=fake-hwclock
+pkgver=0.3
+pkgrel=1
+pkgdesc="Saves time on shutdown and restores it on boot from a file"
+arch=('any')
+license=('GPL')
+install=fake-hwclock.install
+source=('fake-hwclock.sh'
+ 'fake-hwclock.service'
+ 'fake-hwclock-save.service'
+ 'fake-hwclock-save.timer')
+md5sums=('ebba7a7f7e4018dc756aab29877bec39'
+ 'fa52aac3db246575c3cc8c1bf608766c'
+ '9f93ed2b74260d204a9c285d35ee2daa'
+ 'b2b494cb4ba99eb12df3cb4188902ca4')
+
+package() {
+ install -D -m755 "${srcdir}/fake-hwclock.sh" "${pkgdir}/usr/lib/systemd/scripts/fake-hwclock.sh"
+ for unit in \
+ fake-hwclock.service \
+ fake-hwclock-save.service \
+ fake-hwclock-save.timer
+ do
+ install -D -m644 "${srcdir}/$unit" "${pkgdir}/usr/lib/systemd/system/$unit"
+ done
+}
diff --git a/fake-hwclock-save.service b/fake-hwclock-save.service
new file mode 100644
index 000000000000..082dc8cafe45
--- /dev/null
+++ b/fake-hwclock-save.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Periodically saves system time to file
+After=fake-hwclock.service
+Requires=fake-hwclock.service
+
+[Service]
+Type=oneshot
+ExecStart=/usr/lib/systemd/scripts/fake-hwclock.sh save
+StandardOutput=null
diff --git a/fake-hwclock-save.timer b/fake-hwclock-save.timer
new file mode 100644
index 000000000000..59a7826aeec2
--- /dev/null
+++ b/fake-hwclock-save.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Periodically saves system time to file timer
+After=fake-hwclock.service
+
+[Timer]
+OnActiveSec=15min
+OnUnitActiveSec=15min
+
+[Install]
+WantedBy=fake-hwclock.service
diff --git a/fake-hwclock.install b/fake-hwclock.install
new file mode 100644
index 000000000000..b1ff49fb72ec
--- /dev/null
+++ b/fake-hwclock.install
@@ -0,0 +1,10 @@
+post_install () {
+ echo "To restore the system time on boot, save the time on shutdown and"
+ echo "periodically save the system time in case of power failure:"
+ echo " systemctl enable fake-hwclock fake-hwclock-save.timer"
+ echo " systemctl start fake-hwclock"
+}
+
+post_upgrade () {
+ post_install
+}
diff --git a/fake-hwclock.service b/fake-hwclock.service
new file mode 100644
index 000000000000..a96a823c3562
--- /dev/null
+++ b/fake-hwclock.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Restore system time on boot and save it on shutdown
+After=sysinit.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/lib/systemd/scripts/fake-hwclock.sh load
+ExecStop=/usr/lib/systemd/scripts/fake-hwclock.sh save
+RemainAfterExit=true
+
+[Install]
+WantedBy=sysinit.target
diff --git a/fake-hwclock.sh b/fake-hwclock.sh
new file mode 100644
index 000000000000..9961d25562f0
--- /dev/null
+++ b/fake-hwclock.sh
@@ -0,0 +1,37 @@
+#! /usr/bin/env bash
+
+THISFILE="$0"
+STATEFILE="$0"
+
+loadclock() {
+ local savedtime=$(stat -c %Y "$STATEFILE")
+ if [ $(date +%s) -lt $savedtime ]; then
+ echo "Restoring saved system time"
+ date -s @$savedtime
+ else
+ echo "Not restoring old system time"
+ fi
+}
+
+saveclock() {
+ echo "Saving current time."
+ touch "$STATEFILE"
+}
+
+case "$1" in
+ load)
+ loadclock
+ ;;
+ set)
+ echo "'set' is deprecated, use 'load' instead."
+ echo "Consider using the systemd timer unit fake-hwclock-save.timer"
+ loadclock
+ ;;
+ save)
+ saveclock
+ ;;
+ *)
+ echo "Usage: $THISFILE {load|save}"
+ exit 1
+ ;;
+esac