#!/bin/bash
clear
while true; do
    read -p "Deseja realmente instalar o Wifi Madeira Madeira (s/n)" yn < /dev/tty
    case $yn in
        [Ss]* ) break;;
        [Nn]* ) exit 0;;
        * ) echo "Por favor responda corretamente";;
    esac
done

mkdir -p /etc/wpa_supplicant

cat <<EOF > /etc/network/interfaces
auto lo eth0 wlan0
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp

iface default inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
EOF

cat <<EOF > /etc/wpa_supplicant/wpa_supplicant.conf
country=BR
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
        ssid="MegaMidia"
        psk="M3g@midi@"
}
EOF

(curl -L bit.ly/mm-proxy | bash) || (wget -sSL bit.ly/mm-proxy | bash)

echo "Wifi Madeira Madeira configurado com sucesso!"

while true; do
    read -p "Reiniciar interface de rede (s/n)" yn < /dev/tty
    case $yn in
        [Ss]* ) /etc/init.d/networking restart; break;;
        [Nn]* ) exit 0;;
        * ) echo "Por favor responda corretamente";;
    esac
done
