Put version info into /etc/os-release

We will use these data for showing meaningful and (mostly) accurate
version information via NETCONF, eventually.

I a;sp want the version info to be visible in actual binaries as well,
so let's instruct Buildroot to keep .git around. That is not as simple
as, e.g.:

 CLA_SYSREPO_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS = --include .git

...because in the CI setup, these directories are already git submodules
of something, and therefore their .git uses a relative path, and one
cannot easily copy it around. Instead, query the actual original path
and put the result into a new .gitdir file. That should work on both the
CI system and a random developer's setup which might not be using
submodules for projects they are working on.

Change-Id: I4760d0ecaa23a1ea5cf591a6cf76bc76d5139b9b
diff --git a/board/czechlight/common/os-release.sh b/board/czechlight/common/os-release.sh
new file mode 100755
index 0000000..516852b
--- /dev/null
+++ b/board/czechlight/common/os-release.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+function czechlight_describe_git {
+	echo $(git --git-dir=${1}/.git --work-tree=${1} describe --dirty 2>/dev/null || git --git-dir=${1}/.git rev-parse --short HEAD)
+}
+
+function czechlight_query_local_make_var {
+	echo $(sed -n -e "s/\\s*$1\\s*=\\s*\\(.*\\)/\\1/p" ${BASE_DIR}/local.mk)
+}
+
+CLA_BR2_EXTERNAL_REV=$(czechlight_describe_git ${BR2_EXTERNAL_CZECHLIGHT_PATH})
+CLA_SYSREPO_REV=$(czechlight_describe_git $(czechlight_query_local_make_var CLA_SYSREPO_OVERRIDE_SRCDIR))
+NETCONF_CLI_REV=$(czechlight_describe_git $(czechlight_query_local_make_var NETCONF_CLI_OVERRIDE_SRCDIR))
+CLA_CPP_DEPENDENCIES_REV=$(czechlight_describe_git $(czechlight_query_local_make_var CLA_SYSREPO_OVERRIDE_SRCDIR)/submodules/dependencies)
+
+sed -i \
+	-e 's/^VERSION_ID=/BUILDROOT_VERSION_ID=/' \
+	-e 's/^VERSION=/BUILDROOT_VERSION=/' \
+	-e '/^NAME=/d' -e '/^PRETTY_NAME=/d' \
+	$TARGET_DIR/etc/os-release
+
+cat >> ${TARGET_DIR}/etc/os-release <<EOF
+NAME=CzechLight
+# When building under CI, these git revisions might not necessarily refer to
+# something that is available from Gerrit's git repositories. If the job which
+# produced this image is a result of a Zuul job tree with speculatively merged
+# changes, then these refs are private to Zuul mergers.
+PRETTY_NAME="Czech Light ${CLA_BR2_EXTERNAL_REV}"
+VERSION=${CLA_BR2_EXTERNAL_REV}
+CLA_SYSREPO_VERSION=${CLA_SYSREPO_REV}
+NETCONF_CLI_VERSION=${NETCONF_CLI_REV}
+CPP_DEPENDENCIES_VERSION=${CLA_CPP_DEPENDENCIES_REV}
+EOF