--- /dev/null
+#!/bin/sh
+
+# Copyright (c) 2016 Samsung Electronics Co., Ltd 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.
+
+# Author: Aleksander Mistewicz <a.mistewicz@samsung.com>
+
+export TSP_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)/.."
+
+. "${TSP_DIR}/common.sh"
+
+test -n "$1" || die "Missing argument: build nr"
+
+WORKDIR="${HOME}/ws/img_test/$1"
+WORKDIR_REMOTE="${HOME}/ws/img_test_remote/$1"
+DWN_WORKDIR="${HOME}/ws/dwn/$1"
+case "$0" in
+ *odroid*)
+ BOOT_IMG="`ls ${DWN_WORKDIR}/tizen-common_*-boot-*.tar.gz`"
+ USERSPACE_IMG="`ls ${DWN_WORKDIR}/tizen-common_*-wayland-*.tar.gz`"
+ TARGET="odroid"
+ ;;
+ *minnow*)
+ USERSPACE_IMG="`ls ${DWN_WORKDIR}/tizen-common_*-wayland-*-sda.raw.bz2`"
+ USERSPACE_IMG_BMAP="`ls ${DWN_WORKDIR}/tizen-common_*-wayland-*-sda.bmap`"
+ TARGET="minnow"
+ ;;
+esac
+
+FAIL_CNT="$2"
+test -n "${FAIL_CNT}" || FAIL_CNT=0
+
+if [ "$FAIL_CNT" -ge 2 ]; then
+ # Trigger publish job
+ tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh $1
+ exit 0
+fi
+
+# Create and clean required directories on remote machine (tl-runner)
+ssh tl-runner "rm -rf \"${WORKDIR_REMOTE}\"; mkdir -p \"${WORKDIR_REMOTE}\""
+
+# Copy required files
+scp "${BOOT_IMG}" "${USERSPACE_IMG}" "${USERSPACE_IMG_BMAP}" tl-runner:"${WORKDIR_REMOTE}/"
+
+echo "start remote script"
+ssh tl-runner "TARGET=${TARGET} FAIL_CNT=${FAIL_CNT} WORKDIR_REMOTE=${WORKDIR_REMOTE} sh -s --" \
+ < "${TSP_DIR}/scripts/${TARGET}_prep_flash_conf.sh"
+echo "finish remote script"
+
+# Copy the results
+scp tl-runner:"${WORKDIR_REMOTE}/sysctl.result" .
+
+if [ "$FAIL_CNT" -ge 1 ]; then
+ echo "RETRIGGERED: ${FAIL_CNT}" >> sysctl.result
+fi
+
+# Check if they have run successfully, otherwise reschedule the job
+if grep -q "Testing failed." sysctl.result
+then
+ echo "Retrigger..."
+ tsrun_target ${TARGET} -L "RETRIGGERED_$(echo "$TARGET" | tr 'a-z' 'A-Z')_PREPARE_FLASH_CONF" \
+ sh "${TSP_DIR}/jobs/${TARGET}_prep_flash_conf.sh" $1 $(($FAIL_CNT + 1))
+ exit 0
+fi
+
+# Trigger publish job
+tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh $1