#!/bin/sh

PUBLISH_DIR=$HOME/publish

# Set up null communications (only local storage of files)
init_communication()
{
	mkdir -p $PUBLISH_DIR
}

# Store file into publish directory for latter packaging
publish()
{
	cp "$1" "$PUBLISH_DIR/`basename $1`"
}

finalize()
{
	dialog --clear --yesno "Insert USB Flash" 5 40
	if [ $? = 0 ]; then
		sleep 15
		echo -n "Mount USB Flash:"
		mount /media/usbdisk >/dev/null 2>&1 && echo_success || echo_failure
		echo
		if mount | grep -q "/media/usbdisk"; then
			pushd $HOME/
				tar -cjf /media/usbdisk/`cat $HOME/old-full-serial | tr "/" "."`-`cat $HOME/publish/PROFILE`.tar.bz2 publish
			popd
			echo -n "Unmount USB Flash:"
			umount /media/usbdisk >/dev/null 2>&1 && echo_success || echo_failure
			echo
		fi
	fi
}

plan_test_script()
{
	true
}

get_id_by_macs()
{
	# We can not get ID in LiveCD version
	echo ""
}

test_stage_advance()
{
	local stage=$1
	local type=$2
	local version=$3
	local event=$4
	local comment=`echo -n "$5" | ruby -e 'require "cgi"; print CGI::escape($stdin.read)'`

	echo -n "Test $stage Type: $type $version	$event" >>$HOME/stages.txt
	[ -z "$comment" ] || echo -n "	($comment)" >>$HOME/stages.txt
	echo "	`date`" >>$HOME/stages.txt
}

test_stage_progress()
{
	true
}

test_promise_time()
{
	true
}

submit_components()
{
	true
}

submit_additional_components()
{
	true
}

add_software_component()
{
	name=$1
	arch=$2
	version=$3

	if [ -s "$HOME/software-components.xml" ]; then
		new_components=`mktemp`

		xsltproc --stringparam name "$name" \
		         --stringparam arch "$arch" \
			 --stringparam version "$version" \
			 $SHARE_DIR/add_software_component.xslt $HOME/software-components.xml > $new_components
		mv $new_components $HOME/software-components.xml
	else
		cat > $HOME/software-components.xml <<__EOF__
<?xml version="1.0"?>
<list>
  <software-component>
    <name>$name</name>
    <arch>$arch</arch>
    <version>$version</version>
  </software-component>
</list>
__EOF__
	fi
}

# Mark current testing as finished
testing_finished()
{
	true
}

set_ip()
{
	true
}

watchdog()
{
	true
}

publish_my_ip()
{
	true
}

benchmark_submit_float()
{
	local key=$1
	local value=$2
	local units=$3

	echo "$key	$value	$units" >>$HOME/benchmarks.txt
}

benchmark_submit_string()
{
	local key=$1
	local value=$2

	echo "$key	$value" >>$HOME/benchmarks.txt
}

monitoring_submit()
{
	local key=$1
	local value=$2

	echo "$key	`date +%s`	$value" >>$HOME/monitoring_${MONITORING_ID}.txt
}

monitoring_submit_multiple()
{
	local data=$1

	cat $data >>$HOME/monitoring_${MONITORING_NAME}.txt
}

require_attention()
{
	true
}

dismiss_attention()
{
	true
}

get_needed_firmwares_list()
{
	print_red_message "get_needed_firmwares_list() is not available in LiveCD version"
	false
}

boot_from_image()
{
	print_red_message "boot_from_image() is not available in LiveCD version"
	false
}

check_audit()
{
	print_red_message "check_audit() is not available in LiveCD version"
	false
}

compare_fast()
{
	print_red_message "compare_fast() is not available in LiveCD version"
	false
}
