#!/bin/sh

base_dir=$(dirname $0)/..
cfg_dir="$base_dir/configs"
temp_dir="$base_dir/tmp"
ini_file="$cfg_dir/cnc.ini"
lcnc_lockfile=/tmp/linuxcnc.lock

if [ ! -f $lcnc_lockfile ]; then
        rm -rf ${temp_dir}/* 2>/dev/null
fi

if [ -L $ini_file ] ; then
        linuxcnc $ini_file
else
        # if xhost >& /dev/null ; then
        if xhost ; then
                title="Initial Configuration Required"
                message="Siberia-CNC requires initial configuration. Before running Siberia-CNC, ask system administrator to do all required configuration steps."
                if [ "$LANG" = "ru_RU.UTF-8" ]; then
                        title="Требуется конфигурация"
                        message="Пакет Siberia-CNC требует проведения процедуры начальной конфигурации. Обратитесь к представителю технической поддержки."
                fi
                /usr/bin/wish8.6 <<EOF
                        wm wi .
                        tk_messageBox -type ok \
                        -title Siberia-SNC -icon error -title "$title" \
                        -message {$message}
                        exit
EOF
        elif [ -t 1 ]; then
                echo "\nCNC is not configured! Please perform proper configuration first!\n"
                echo "Press any key to exit ..."
                read reply
        fi
fi
