#!/bin/bash

i=$1

if [[ -z $AUTH_HEADER ]]; then
	echo "Please provide \$AUTH_HEADER";
	exit;
fi

if [[ -z $i ]]; then
    echo "Please provide index of result to send"
fi

echo "Fetching result $i...";
curl "http://localhost:5002/results/$i/results.json" -f -o result.json || {
	curl "http://localhost:5002/restart_test/$i"
	exit;
}

echo "Sending results $i...";
curl 'https://lwc.las3.de/admin/insert-result.php' \
    -f -H "$AUTH_HEADER" \
    --data "$(cat result.json)" || exit
echo "Sent.";

curl "http://localhost:5002/delete_test/$i"
