#!/bin/sh

. /var/etc/autostart/start-config
if [ $debug = 'full' ]; then
	set -x
fi

if [ $bootlogo == 'y' ]; then

	echo "[POWEROFF] start /var/etc/boot/poweroff.sh"

	if [ -e /var/swap/boot/ownpoweroffvideo.mkv ]; then
		echo "[POWEROFF] use own poweroffvideo from swapstick"

		tmpfile=/tmp/eplayer.tmp
		errfile=/tmp/eplayer.err
		touch "$tmpfile"
		(
		eplayer2 file:///var/swap/boot/ownpoweroffvideo.mkv || touch "$errfile"
			rm -f "$tmpfile"
		) > "$tmpfile" 2>&1 | tr "\r" "\n" &
		echo elpayer startet
		while [ -e "$tmpfile" ]; do
			echo while
			sleep 1
			echo elpayer running
		done
		echo elpayer closed
	elif [ -e /var/swap/boot/poweroffvideo.mkv ]; then
		echo "[POWEROFF] use poweroffvideo from swapstick"

		tmpfile=/tmp/eplayer.tmp
		errfile=/tmp/eplayer.err
		touch "$tmpfile"
		(
		eplayer2 file:///var/swap/boot/poweroffvideo.mkv || touch "$errfile"
			rm -f "$tmpfile"
		) > "$tmpfile" 2>&1 | tr "\r" "\n" &
		echo elpayer startet
		while [ -e "$tmpfile" ]; do
			echo while
			sleep 1
			echo elpayer running
		done
		echo elpayer closed
	elif [ -e /var/etc/boot/poweroff.mvi ]; then
		echo "[POWEROFF] use powerofflogo"
		showiframe -p /var/etc/boot/poweroff.mvi &
	fi	
fi