#!/bin/bash

pkg=orthanc-wsi
filename="dataset.json"

if [ "$AUTOPKGTEST_TMP" = ""  ]; then
	# create the tmp directory
	AUTOPKGTEST_TMP=`mktemp -d /tmp/${pkg}-test.XXXXX`

	# clean the directory upon detection of any of these signals
	trap "rm -rf $AUTOPKGTEST_TMP" 0 INT QUIT ABRT PIPE TERM

fi

# change working directory
cd $AUTOPKGTEST_TMP

# Generate sample dataset
OrthancWSIDicomizer --sample-dataset > $filename

# Check if $filename exists
if [ -f "$filename" ]; then
    echo "$filename exists, proceeding to remove it..."
    rm "$filename"
    echo "$filename removed successfully."
    # Exit with success status
    exit 0
else
    echo "$filename does not exist, script will exit with failure."
    # Exit with failure status
   exit 1
fi
