From 0cfecd1024e87f965e28743f2654915b1d0f4122 Mon Sep 17 00:00:00 2001
From: Chris Jones <cmsj@tenshu.net>
Date: Thu, 4 Apr 2013 20:38:19 +0100
Subject: [PATCH] Store build-time settings

This will write two files in /etc/ that contain the environment and
command line arguments used in the creation of an image. This should
assist with later efforts to repeat the creation of an image.

Change-Id: Icdbe6693380bed6c406feee10d2cb1a88a992932
---
 bin/disk-image-create                              |  4 ++++
 elements/base/extra-data.d/50-store-build-settings |  9 +++++++++
 elements/base/install.d/50-store-build-settings    | 12 ++++++++++++
 3 files changed, 25 insertions(+)
 create mode 100755 elements/base/extra-data.d/50-store-build-settings
 create mode 100755 elements/base/install.d/50-store-build-settings

diff --git a/bin/disk-image-create b/bin/disk-image-create
index 0c9c4e482..f8923a029 100755
--- a/bin/disk-image-create
+++ b/bin/disk-image-create
@@ -21,6 +21,10 @@ set -e
 # of $LANG varying between build hosts
 export LANG=C
 
+# Store our initial environment and command line args for later
+export DIB_ARGS="$@"
+export DIB_ENV=$(export)
+
 SCRIPTNAME=$(basename $0)
 SCRIPT_HOME=$(dirname $0)
 export _LIB=$(dirname $0)/../lib
diff --git a/elements/base/extra-data.d/50-store-build-settings b/elements/base/extra-data.d/50-store-build-settings
new file mode 100755
index 000000000..27a212e67
--- /dev/null
+++ b/elements/base/extra-data.d/50-store-build-settings
@@ -0,0 +1,9 @@
+#!/bin/bash
+# Store the build-time environment and command line arguments
+
+set -e
+source $_LIB/die
+[ -n "$TMP_HOOKS_PATH." ] || die "Temp hook path not set"
+
+echo "$DIB_ENV" > $TMP_HOOKS_PATH/dib_environment
+echo "$DIB_ARGS" > $TMP_HOOKS_PATH/dib_arguments
diff --git a/elements/base/install.d/50-store-build-settings b/elements/base/install.d/50-store-build-settings
new file mode 100755
index 000000000..bb2679127
--- /dev/null
+++ b/elements/base/install.d/50-store-build-settings
@@ -0,0 +1,12 @@
+#!/bin/bash
+# Store build-time environment and command line arguments
+
+set -e
+
+if [ -e "/tmp/in_target.d/dib_environment" ]; then
+  cp /tmp/in_target.d/dib_environment /etc/
+fi
+
+if [ -e "/tmp/in_target.d/dib_arguments" ]; then
+  cp /tmp/in_target.d/dib_arguments /etc/
+fi