# This file is sourced
# 
# Generate upstart services for all screens specified in lts.conf

for i in 01 02 03 04 05 06 07 08 09 10 11 12; do
    eval num=\$SCREEN_$screen
    [ -n "$num" ] || continue
    echo <<EOF >/etc/init/screen_session${i}.conf
# screen_session${i}.conf
#
# Automatically generated by init-ltsp.d scripts
#

description 	"LTSP screen ${i}"
author 		"Gideon Romm"

start on (filesystem
          and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
               or stopped udevtrigger))
stop on runlevel [016]

pre-start script
    [ -r "/usr/share/ltsp/ltsp_config" ] && . /usr/share/ltsp/ltsp_config 

    # Find current tty, and if it is not the same as SCREEN_DEFAULT, chvt
    if [ -n "${SCREEN_DEFAULT}" ]; then
        chvt ${SCREEN_DEFAULT}
    fi
end script

respawn
script
    if [ -r /etc/default/locale ]; then
	. /etc/default/locale
	export LANG LANGUAGE
    elif [ -r /etc/environment ]; then
	. /etc/environment
	export LANG LANGUAGE
    fi

    exec /usr/share/ltsp/screen_session ${i}
end script

EOF

done
