#!/bin/sh
#
# License: Copyright 2020 SpinetiX S.A. This file is licensed
#          under the terms of the GNU General Public License version 2.
#          This program is licensed "as is" without any warranty of any
#          kind, whether express or implied.
#
# Copyright 2002, 2003, 2004 Sony Corporation
# Copyright 2002, 2003, 2004 Matsushita Electric Industrial Co., Ltd.
#
### BEGIN INIT INFO
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Handles splash screen
# Description: Handles splash screen
### END INIT INFO

# Init script information
NAME=splash
DESC="splash screen"

# Defaults
BOOTIMG=
SHUTDOWNIMG=
FIRMUPDIMG=

# Load init script configuration
[ -f /etc/default/$NAME ] && . /etc/default/$NAME

# Source the init script functions
. /etc/init.d/functions

# Constants
PIDFILE=/run/spxdispmanager/spxdispmanager.pid
IMAGELINK=/run/spxdispmanager/image

load_splash() {
    local RET

    echo -n "$NAME: $2 splash image "

    ln -sf "$1" $IMAGELINK || return
    RET=$?
    if [ $RET -eq 0 ]; then
        success; echo
    else
        failure; echo
    fi

    return $RET
}

case "$1" in
    start)
	[ -n "$BOOTIMG" ] && load_splash "$BOOTIMG" "Bootup splash image"
	exit 0
	;;
    restart)
	# do nothing, compatibility with update-rc.d
	exit 0
	;;
    stop)
	[ -n "$SHUTDOWNIMG" ] && load_splash "$SHUTDOWNIMG" "Shutdown"
	exit $?
	;;
    updating)
	[ -n "$FIRMUPDIMG" ] && load_splash "$FIRMUPDIMG" "Firmware update"
	exit $?
	;;
    *)
	echo "Usage: $NAME {start|stop|updating|restart}" >&2
	exit 1
	;;
esac
