aboutsummaryrefslogtreecommitdiff
path: root/lib/util.bash
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-03-29 16:33:23 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-03-29 16:33:23 +0200
commit634edd83bb9ba0cc2c661fb8c6a56509c3573355 (patch)
treedf19672532ae42a9f9db07f9fa6a7de92a0c17c3 /lib/util.bash
parent8e2579ded0095706e08261302bf7202f3462372e (diff)
Make reproducible tarballs with dist
Diffstat (limited to 'lib/util.bash')
-rw-r--r--lib/util.bash16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/util.bash b/lib/util.bash
index 97131c3..a387d8b 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -33,6 +33,22 @@ config_etc_kv() {
printf "%s" "$value"
}
+# Create a datetime stamp. This is a wrapper around the date utility, ensuring
+# that the date being formatted is always in UTC and respect SOURCE_DATE_EPOCH,
+# if it is set.
+datetime() {
+ local date_opts
+
+ # Apply SOURCE_DATE_EPOCH as the date to base off of.
+ if [[ $SOURCE_DATE_EPOCH ]]
+ then
+ date_opts+=("-d@$SOURCE_DATE_EPOCH")
+ date_opts+=("-u")
+ fi
+
+ date "${date_opts[@]}" +"${1:-%FT%T}"
+}
+
# Log a message as error, and exit the program. This is intended for serious
# issues that prevent the script from running correctly. The exit code can be
# specified with -i, or will default to 1.