#!/bin/sh

BRANCH=""
LINUXFAMILY=""

[ -f "/etc/orangepi-release" ] && . /etc/orangepi-release

case "$1" in
	install)
		if [ -z "$BRANCH" ] || [ "$BRANCH" != "legacy" ]; then
			echo "Mali binary driver can be used only with legacy kernel" 1>&2
			exit 1
		fi
		if [ -z "$LINUXFAMILY" ] || ! ( [ "$LINUXFAMILY" = "sun4i" ] || [ "$LINUXFAMILY" = "sun5i" ] || [ "$LINUXFAMILY" = "sun7i" ] || [ "$LINUXFAMILY" = "sun8i" ] ); then
			echo "Mali binary driver can be used only on sunxi hardware" 1>&2
			exit 1
		fi
	;;
esac

DISTRIBUTION="${distribution}"

DIVERT_TARGETS="libEGL.so libEGL.so.1 libEGL.so.1.0.0 libGLESv1_CM.so libGLESv1_CM.so.1 libGLESv1_CM.so.1.1.0 \
	libGLESv2.so libGLESv2.so.2 libGLESv2.so.2.0.0"

if [ "Debian" = "$DISTRIBUTION" ]; then
	mkdir -p /usr/lib/${DEB_HOST_MULTIARCH}/mali-divert
	for f in $DIVERT_TARGETS; do
		dpkg-divert --package libmali-sunxi-r3p0 --add --rename \
			--divert /usr/lib/${DEB_HOST_MULTIARCH}/mali-divert/${f} /usr/lib/${DEB_HOST_MULTIARCH}/${f}
	done
	LDCONFIG_NOTRIGGER=y ldconfig
fi

#DEBHELPER#

exit 0
