#!/bin/bash
# preinst script for kylin-wine-test
#
# see: dh_installdeb(1)

if [[ $(id -u) != 0 ]]; then
    folder=$USER
else
    for folder in $(ls /home/); do
        if test -d /home/$folder/.config/; then
            user_name=$(who | grep $folder)
            if [[ "$user_name" != "" ]]; then
                folder=${user_name%%$" "*}
                break
            fi
        fi
    done
fi

BOTTLE="%BOTTLE%"
WINEPREFIX="/home/$folder/.kylinwine/${BOTTLE}"

if [ -d "${WINEPREFIX}" ]; then
    kill $(lsof -t +D "$WINEPREFIX" 2>/dev/null) 2>/dev/null
fi

if [ -f "${WINEPREFIX}/.auth" ]; then
    rm "${WINEPREFIX}/.auth"
fi

exit 0
