#!/bin/bash

warn=1

SCRIPT_PATH="$(readlink -f "$0" 2>/dev/null)"
if [ -z "$SCRIPT_PATH" ]; then
    SCRIPT_PATH="$0"
fi

if [ "$warn" = "1" ]; then
        xmessage -center -buttons OK:0 "
WARNING:

This command closes PathPilot immediately.

After this first warning, future runs will close PathPilot 
right away without showing this message again.

Click OK to continue.
"

    sed -i 's/^warn=1$/warn=0/' "$SCRIPT_PATH"
fi

# Send SIGTERM (signal 15) to tormach_mill_ui.py
PIDS=$(pgrep -f tormach_mill_ui.py)

if [ -z "$PIDS" ]; then
    echo "No tormach_mill_ui.py process found."
    exit 0
fi

echo "Sending SIGTERM to:"
echo "$PIDS"

for PID in $PIDS; do
    kill -15 "$PID"
done

echo "Done."