#!/bin/sh

info_file="/usr/lib/enigma.info"

[ -r "$info_file" ] || exit 0
grep -Fqx "displaydistro='OpenATV'" "$info_file" || exit 0

# Enigma2 deliberately protects itself from the OOM killer. eConsole children
# inherit that protection, which previously made the kernel restart Enigma2
# instead of terminating an oversized Chromium renderer. Chromium is
# disposable and must be selected first if the box runs out of memory.
if [ -w /proc/self/oom_score_adj ]; then
	echo 300 > /proc/self/oom_score_adj 2>/dev/null || true
fi

# HiSilicon receivers also reserve a substantial part of RAM for video. Keep
# enough GPU memory for the fixed 1280x720 browser surface while forcing
# Chromium to evict portal artwork before the proprietary allocator invokes
# the OOM killer.
exec /usr/share/netflix/chromium-bin \
	--force-gpu-mem-available-mb=96 \
	"$@"
