#!/bin/bash

. /usr/share/dosis2/bin/shell-support-functions

enforce_root

OS="`getos`"

# Export Xauthority file and Display which are required
# for GUI launch authority.
if [ "${OS}" = "Ubuntu" ]; then
    export DISPLAY=:0
    export XAUTHORITY="/run/user/`id -u dosis-guest`/gdm/Xauthority"
elif [ "${OS}" = "CentOS" ]; then
    export DISPLAY=:0.0
    export XAUTHORITY="`ls /var/run/gdm/auth-for-xguest-*/database`"
else
    abort 2 "Unknown OS: ${OS}"
fi

if [ "${OS}" = "Ubuntu" ]; then
    /opt/dosis2/bin/evdev-touchscreen-calibrator
elif [ "${OS}" = "CentOS" ]; then
    # Launch the appropriate touchscreen calibration utility
    if [ -f "/usr/bin/eGalaxCalib" ]; then
        /usr/bin/eGalaxCalib Linz9 &
    elif [ -f "/usr/bin/eCalib" ]; then
        /usr/bin/eCalib Linz9 &
    else
        /usr/bin/eGTouchU &
    fi

    # Set the firefox window to be below all other windows.
    # (Give the above layer priority to eGTouch).
    wmctrl -r "Mozilla Firefox" -b remove,above
    wmctrl -r "Mozilla Firefox" -b add,below
else
    abort 2 "Unknown OS: ${OS}"
fi
