#!/bin/sh

set -e

name=$(basename $0)
bindir=/usr/lib/$name

wine32=$bindir/wine
wine64=$bindir/wine64

if test -x $wine32; then
    wine=$wine32
elif test -x $wine64; then
    wine=$wine64
    if [ "$(dpkg --print-architecture)" = "amd64" -a "$(dpkg --print-foreign-architectures)" != "i386" ]; then
        echo "it looks like multiarch needs to be enabled.  as root, please"
        echo "execute \"dpkg --add-architecture i386 && apt-get update &&"
        echo "apt-get install $(echo $name | sed s/wine/wine32/)\""
    fi
else
    echo "error: unable to find wine executable.  this shouldn't happen."
    exit 1
fi

if test -z $WINELOADER; then
    wineloader=$wine
else
    wineloader=$WINELOADER
fi

if test -z $WINEDEBUG; then
    winedebug=-all
else
    winedebug=$WINEDEBUG
fi

WINELOADER=$wineloader WINEDEBUG=$winedebug $wine "$@"
