#!/bin/bash

IDENTIFICADOR=$( id -u )
COMPROBAR="$( dpkg -l | grep winehq | head -n 1 | awk '{ print $1 }' )"
C=1



if [ $IDENTIFICADOR == 0 ]; then
    while [ $C -eq 1 ]; do

        COMPROBAR="$( dpkg -l | grep winehq | head -n 1 | awk '{ print $1 }' )"
        WINELISTFILE="/etc/apt/sources.list.d/wine.list"
        
        if ! [ "$COMPROBAR" == "ii" ]; then
            (( C=0 ))

            sudo dpkg --add-architecture i386
            wget -nc https://dl.winehq.org/wine-builds/winehq.key
            sudo apt-key add winehq.key
	        wget -nc https://download.opensuse.org/repositories/Emulators:/Wine:/Debian/xUbuntu_18.04/Release.key
	        sudo apt-key add Release.key
	        if ! [ WINELISTFILE -f  ] ; then 
                touch /etc/apt/sources.list.d/wine.list
	        fi
            echo "deb https://download.opensuse.org/repositories/Emulators:/Wine:/Debian/xUbuntu_18.04/ ./" > /etc/apt/sources.list.d/wine.list
            sudo apt-key adv --keyserver keyserver.ubuntu.com 9 --recv-keys DFA175A75104960E
            sudo apt update
            sudo apt install --install-recommends winehq-stable
            winecfg

        else
            apt remove --purge winehq-stable -y
            echo "WineHQ desinstalado"
            
            
                
        fi

    done



else
echo "Necesita permisos de administrador"
fi

