#!/bin/sh

if [ -x ~/.icewm/startup ] ; then
	~/.icewm/startup
fi

DEBVER="`head -c 2 /etc/debian_version`"

# Protect unexpected command when LCD screen is in power save mode 
if   [ "$DEBVER" != "3." ] ; then
	# only for debian etch systems
	if [ -x /doremi/X11R6/bin/drmxssd.out ]; then
		killall -KILL drmxssd.out
		/doremi/X11R6/bin/drmxssd.out &
	fi
fi

# Bring a popup if shutdown/reboot method is invalid
if [ -x /doremi/X11R6/bin/drmbootseq.out ]; then
	/doremi/X11R6/bin/drmbootseq.out &
fi

# Run a popup window if repository needs cleanup/migration
if [ -e /data/maps/.refuse_ingest ] ; then
        /doremi/X11R6/bin/drmpopup.out "Ingest service disabled" "Repository state does not allow ingesting contents.<br>$(cat /data/maps/.refuse_ingest)" --warning
fi

# Run a popup window if station is running a none product SecurityManager
if [ -e /tmp/SMProductError.txt ] ; then
        /doremi/X11R6/bin/drmpopup.out "$(head -1 /tmp/SMProductError.txt)" "$(head -2 /tmp/SMProductError.txt | tail -1)" "$(tail -1 /tmp/SMProductError.txt)"
fi

# Run a popup window if station SM is not audio_mapping capable and configured audio_map is not "disabled"
if [ -e /tmp/AudiomapError.txt ] ; then
  /doremi/X11R6/bin/drmpopup.out "Audio mapping issue" "<p align="center">Connected SecurityModule does not support audio mapping.<br>Configured audio mapping will have no effect</p>" --warning
fi

# Start "Password Manager" and check if the default password is used
if [ -x /doremi/X11R6/bin/drmpasswd.out ] ; then
        /doremi/X11R6/bin/drmpasswd.out --check
fi

# Start the popup alert notifier
if [ -x /doremi/X11R6/bin/drmpopupd.out ] ; then
	killall -KILL drmpopupd.out
	/doremi/X11R6/bin/drmpopupd.out &
fi

# Start the auto backup checks
if [ -x /doremi/X11R6/bin/drmbackup.out ]; then
	killall -KILL drmbackup.out
	/doremi/X11R6/bin/drmbackup.out --auto &
fi

# Run doremi X11 handlers
if [ -d /doremi/etc/x11.d ]; then
	run-parts -arg=start -- /doremi/etc/x11.d &
fi

if [ "`whoami`" = "doremi" ] ; then
	if [ -x /doremi/X11R6/bin/cinelister.out ] ; then
		/doremi/X11R6/bin/cinelister.out
	fi
fi 
