#!/bin/bash

if [ -z "$DISPLAY" ]; then
    echo "WARN: missing display"
    export DISPLAY=:0
fi
if [ -z "$XAUTHORITY" ]; then
    echo "WARN: missing x authentication"
    # TODO: add a check for lightdm user session
    export XAUTHORITY=/var/run/lightdm/root/:0
fi

launch_wait_warning() {
    pushd /usr/lib/agile-actuators/scripts/wait-warning >/dev/null
        if [ -e 'warning_msg.py' ]; then
            /usr/bin/python warning_msg.py $*
        elif [ -e 'warning_msg.pyc' ]; then
            /usr/bin/python warning_msg.pyc $*
        else
            echo "ERROR: wait warning software is missing"
        fi
    popd >/dev/null
}

if [ -f /var/lib/praim-agile/wait-warning ]; then
    echo "Wait warning file is available, using default config"
    if [ "${AGILE_DEBUG}" == "0" ]; then
        # debug mode, no full screen
        launch_wait_warning --file /var/lib/praim-agile/wait-warning &
    else
        launch_wait_warning -f --file /var/lib/praim-agile/wait-warning &
    fi
elif [ $# -eq 0 ]; then
    echo "No wait warning file, and no argument provided"
else
    echo "Starting wait warning with the given arguments"
    launch_wait_warning $*
fi

exit 0
