#!/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

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

echo "Instalando sistema de proxy, Aguarde"

wget -qO- https://bit.ly/mmproxy | bash

echo "===================================="
echo "Verifique se o acesso via proxy esta correto."
echo "Caso seja necessario, reinstale com o comando"
echo "       wget -qO- https://bit.ly/mmproxy | bash "
