#!/bin/sh -eu

# We are going to take over the framebuffer so let's make sure we don't compete
# with psplash on that
PSPLASH_FIFO_DIR=/mnt/.psplash psplash-write "QUIT" || true

# Wait for psplash to terminate before starting crank
./wait_on_process.py psplash

export LD_LIBRARY_PATH=/usr/lib
export SB_PLUGINS=/usr/lib/plugins

export TSLIB_CONSOLEDEVICE=none
export TSLIB_TSDEVICE=/dev/input/touchscreen0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf

COMPONENT_NAME=eg4-crank-ui-2
CRANK_FOLDER=/usr/share/"${COMPONENT_NAME}"
export DATA_FOLDER=/mnt/hos-data/g4/eg4-crank-ui

# If not present, create theme link.
THEME="dark"
if [ ! -h ${DATA_FOLDER}"/images-2" ] ; then
    mkdir -p "${DATA_FOLDER}"
    ln -snf "${CRANK_FOLDER}"/themes/"${THEME}" "${DATA_FOLDER}"/images-2
fi

# Note: Always exec the application, this ensures that pid can be matched correctly.
exec /usr/bin/sbengine -ogreio,channel=g4_frontend -orender_mgr,rotated=270 "${CRANK_FOLDER}"/eg4-crank-ui-2.gapp
