#!/bin/sh

export PREFIX=${PKG_PREFIX:-/usr/local}
export WINE=$1

if [ -d ${PREFIX}/lib32/.libGL-new ]
then
    LIBGLDIR=.libGL-new
else
    LIBGLDIR=.libGL
fi

case "$2" in
  DEINSTALL)
    sh ${PREFIX}/share/wine/patch-nvidia.sh -d
    rm -r ${PREFIX}/lib32/libGL.so.1 ${PREFIX}/lib32/dri
    ;;
  POST-INSTALL)
    ln -s ${LIBGLDIR}/libGL.so.1 ${PREFIX}/lib32/libGL.so.1
    mkdir -p ${PREFIX}/lib32/dri
    for dri in $(cd ${PREFIX}/lib32/${LIBGLDIR}/dri/; echo *.so)
    do
        ln -s ../${LIBGLDIR}/dri/${dri} ${PREFIX}/lib32/dri/${dri}
    done
    sh ${PREFIX}/share/wine/patch-nvidia.sh -n > /dev/null 2>&1
    case $? in
      0)
        cat << _EOF
$1 has been patched for use with nvidia graphics driver.  If
the version of the installed nvidia graphics driver changes execute (as root):
_EOF
        ;;
      1)
        cat << _EOF
This system does not appear to use a nvidia graphics driver.  If this changes
and then every time the driver's version changes execute (as root)
_EOF
        ;;
      *)
        cat << _EOF
A NVIDIA GRAPHICS DRIVER HAS BEEN DETECTED ON THIS SYSTEM AND THE AUTOMATED
PATCHING HAS FAILED, execute (as root)
_EOF
        ;;
    esac
    cat << _EOF
	sh ${PREFIX}/share/wine/patch-nvidia.sh
to get 2D/3D acceleration to work with the nvidia driver.  Without this wine
will crash when a program requires 2D/3D graphics acceleration.

_EOF
    ;;
esac
