#!/usr/bin/sh

EXECDIR=~/.local/bin

if [ ! -e $EXECDIR/gnome-kiosk-script ]; then
    mkdir -p $EXECDIR ~/.config
    cat > $EXECDIR/gnome-kiosk-script <<- "EOF"
	#!/bin/sh
	# This script is located in ~/.local/bin.
	# It's provided as an example script to show how
	# the kiosk session works.  At the moment, the script
	# just starts a text editor open to itself, but it
	# should get customized to instead start a full screen
	# application designed for the kiosk deployment.
	gnome-text-editor ~/.local/bin/gnome-kiosk-script

	sleep 1.0
	exec "$0" "$@"
EOF

    chmod +x $EXECDIR/gnome-kiosk-script
    touch ~/.config/gnome-initial-setup-done
fi

# Copy and run the script from the XDG_RUNTIME_DIR directory if that exists
if [ -d $XDG_RUNTIME_DIR ]; then
    cp $EXECDIR/gnome-kiosk-script $XDG_RUNTIME_DIR/
    EXECDIR=$XDG_RUNTIME_DIR
fi

exec $EXECDIR/gnome-kiosk-script "$@"
