#!/bin/sh
#
# Apply the currently declared kiosk URL. Restarts the X session (which
# re-reads /etc/mymo-kiosk.conf and /etc/mymo-kiosk.conf.d/) only when
# the URL differs from the one the running session started with, so
# routine package upgrades don't flash the display.
#
# Application packages call this from their postinst after shipping a
# URL drop-in.

KIOSK_URL=
if [ -f /etc/mymo-kiosk.conf ]; then
    . /etc/mymo-kiosk.conf
fi
for _conf in /etc/mymo-kiosk.conf.d/*.conf; do
    if [ -f "$_conf" ]; then
        . "$_conf"
    fi
done

declared="KIOSK_URL=$KIOSK_URL"

if [ "$declared" = "$(cat /tmp/mymo-kiosk.urls 2>/dev/null)" ]; then
    exit 0
fi

pkill -u kiosk Xorg || true
