+#!/bin/bash
+
+# ============LICENSE_START=======================================================
+# Copyright (C) 2019 The Nordix Foundation. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+
+# NOTE (fdegir): we do not need to do anything for the changes coming to infra/engine repo
+if [[ "$GERRIT_PROJECT" == "infra/engine" ]]; then
+ exit 0
+fi
+
+echo "Info : Cloning infra/engine repository"
+cd "$HOME" && /bin/rm -rf "$WORKSPACE"
+git clone -q "$ENGINE_REPO_URL" "$WORKSPACE"
+
+export SDF_ORIGINAL="$WORKSPACE/engine/inventory/group_vars/all/sdf.yaml"
+export SDF_PATCHSET="/tmp/sdf.yaml.$GERRIT_CHANGE_NUMBER"
+
+/bin/rm -rf "$SDF_PATCHSET"
+
+export TOOL_TYPE="${GERRIT_PROJECT//*\//}"
+export TOOL_MATCH="false"
+echo "Info : Tool type is $TOOL_TYPE"
+echo "Info : Updating SDF with change SHA and refspec"
+while IFS= read -r line; do
+ if [[ "$TOOL_MATCH" == "true" && "$line" =~ "version" ]]; then
+ echo "$line" | sed "s#version:.*#version: $GERRIT_PATCHSET_REVISION\n refspec: $GERRIT_REFSPEC#g" >> "$SDF_PATCHSET"
+ export TOOL_MATCH="false"
+ continue
+ fi
+ if [[ "$line" =~ "$TOOL_TYPE:" && "$TOOL_MATCH" == "false" ]]; then
+ export TOOL_MATCH="true"
+ fi
+ echo "$line" >> "$SDF_PATCHSET"
+done < "$SDF_ORIGINAL"
+# NOTE (fdegir): log the diff for possible troubleshooting
+echo
+echo "Info : Diff between original SDF and SDF generated for the change"
+echo "-------------------------------------------------------------------------"
+diff "$SDF_ORIGINAL" "$SDF_PATCHSET"
+echo "-------------------------------------------------------------------------"
+echo
+
+# NOTE (fdegir): move SDF generated for the change into the original SDF
+/bin/mv -f "$SDF_PATCHSET" "$SDF_ORIGINAL"
+
+# NOTE (fdegir): log the final SDF
+echo
+echo "Info : Generated SDF content"
+echo "-------------------------------------------------------------------------"
+cat "$SDF_ORIGINAL"
+echo "-------------------------------------------------------------------------"
+echo