#!/bin/sh

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

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

	echo "[BOOTLOGO] start /var/etc/boot/bootlogo.sh"
	blc=`ls /var/swap/boot/bootlogo*.mvi 2>/dev/null | wc -l`

	if [ -e /var/swap/boot/ownbootvideo.mkv ]; then
		echo "[BOOTLOGO] use own bootvideo from swapstick"
		eplayer2 file:///var/swap/boot/ownbootvideo.mkv
		showiframe -p /var/swap/boot/ownbootvideo.mvi
	elif [ -e /var/swap/boot/bootvideo.mkv ]; then
		echo "[BOOTLOGO] use bootvideo from swapstick"
		eplayer2 file:///var/swap/boot/bootvideo.mkv
		showiframe -p /var/swap/boot/bootvideo.mvi
	elif [ $blc -gt 0 ]; then
		echo "[BOOTLOGO] use random bootlogo"
		if [ $blc -gt 100 ]; then blc=100; fi
		zz=`head -n1 /dev/urandom | cut -c 1 | hexdump -d | head -n1 | cut -c 14-15`
		if [ "$zz" = "08" ]; then zz=8; fi #bei 08 kommt fehler beim dividieren
		if [ "$zz" = "09" ]; then zz=9; fi #bei 09 kommt fehler beim dividieren
		div=$((100/$blc))
		if [ $div -eq 0 ]; then div=1; fi
		nr=$(($zz/$div))
		nr=$(($nr+1))
		if [ -e "/var/swap/boot/bootlogo$nr.mvi" ]; then
			showiframe -p "/var/swap/boot/bootlogo$nr.mvi"
		elif [ -e /var/etc/boot/bootlogo.mvi ]; then
			showiframe -p /var/etc/boot/bootlogo.mvi
		fi
	elif [ -e /var/etc/boot/bootlogo.mvi ]; then
		echo "[BOOTLOGO] use bootlogo"
		showiframe -p /var/etc/boot/bootlogo.mvi
	fi
	
fi