script: ipkg-build: honour $SOURCE_DATE_EPOCH
authorJo-Philipp Wich <jo@mein.io>
Thu, 8 Nov 2018 10:52:33 +0000 (11:52 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 8 Nov 2018 10:52:33 +0000 (11:52 +0100)
When the SOURCE_DATE_EPOCH environment variable is set, use it to
override the timestamps of .ipk archive contents.

This ensures that .ipk archives built in environments without SCM
metadata (mainly the SDK) are reproducible between different runs.

Ref: https://github.com/openwrt/packages/issues/6954
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
scripts/ipkg-build

index e42da2ecbc8605c038bb457d818496514d83d537..21127f33910cabb82f6b025a1865f305c88b9c10 100755 (executable)
@@ -15,8 +15,12 @@ FIND="${FIND:-$(which gfind)}"
 TAR="${TAR:-$(which tar)}"
 GZIP="$(which gzip)"
 
+# try to use fixed source epoch
+if [ -n "$SOURCE_DATE_EPOCH" ]; then
+       TIMESTAMP=$(date --date="@$SOURCE_DATE_EPOCH")
+
 # look up date of last commit
-if [ -d "$TOPDIR/.git" ]; then
+elif [ -d "$TOPDIR/.git" ]; then
        GIT="$(which git)"
        TIMESTAMP=$(cd $TOPDIR; $GIT log -1 -s --format=%ci)
 elif [ -d "$TOPDIR/.svn" ]; then