#!/bin/bash

. /etc/odemis.conf

export PYTHONPATH

# Call the MODEL_SELECTOR if needed
if [ -z "$MODEL" -a -n "MODEL_SELECTOR" ]; then
    MODEL="$($MODEL_SELECTOR)"
    if [ "$?" -ne 0 ]; then
       read -p "Failed to select microscope file."
       exit 1
    fi
fi

odemis-sudo-gedit "$MODEL"

# TODO: validate the new microscope file even if backend is running
odemisd --validate "$MODEL"
if [ "$?" -eq 127 ]; then
    echo
    read -p "Microscope file seems to contain error, check it."
fi
