Instalador de Hotspot Linux Debian (SysV)

Publicado por MARX FABYAN CARVALHO DO MONTE (última atualização em 29/05/2025)

[ Hits: 91 ]

Homepage: marxfcmonte

Download InstallHotspot.sh




O script cria três programas, um para restaurar quando, por algum motivo,
o hotspot deixar de responder, o outro parar o serviço hotspot e por fim um para mudar o nome da rede Wi-Fi e senha. Cria atalhos para a Área de trabalho e no menu Linux.

Além disso, deixa a inicialização automática do hotspot quando o sistema inicializa. (SysV)

Realiza toda a instalação de forma automática, solicitando apenas o SSID e a Senha para SSID.

  



Esconder código-fonte

#!/bin/bash

echo "
Desenvolvido por Marx F. C. Monte
Instalador de Hotspot v 1.8.1 (2025)
Para a Distribuição Debian 12 e derivados (antiX 23)\
"

if [ "$USER" != "root" ]; then
   echo -e "Use comando 'sudo'  ou comando 'su' 
antes de inicializar o programa.\n"

   exit 1   
fi
conexoes=$(ifconfig -a | grep broadcast -c)
if [ "$conexoes" -lt 2 ]; then
   echo -e "\nDeve haver pelo menos 2 interfaces ativas (Ethernet e Wi-Fi)...\n
Instalação finalizada...\n"
   exit 1        
fi

echo -e "\nInstalação sendo iniciada...\n"   
interfaces=( $(ifconfig -a | grep broadcast -B 1 | cut -d ":" -f1 -s | sed 's/ //g') )
ethe=${interfaces[0]}
wifi=${interfaces[1]}
sleep 5
clear
rede=$(dialog --inputbox "Nome da rede Wi-Fi (SSID)" 10 45 --stdout)
senha=$(dialog --inputbox "Senha da rede Wi-Fi" 10 45 --stdout)
clear

service dnsmasq stop

sed -i 's#^DAEMON_CONF=.*#DAEMON_CONF=/etc/hostapd/hostapd.conf#' /etc/init.d/hostapd

cat <<EOF > /etc/dnsmasq.conf
log-facility=/var/log/dnsmasq.log
interface=$wifi
dhcp-range=192.168.137.10,192.168.137.250,12h
dhcp-option=3,192.168.137.1
dhcp-option=6,192.168.137.1
log-queries
EOF

service dnsmasq start
service hostapd stop

ifconfig $wifi up
ifconfig $wifi 192.168.137.1/24

iptables -t nat -F
iptables -F 
iptables -t nat -A POSTROUTING -o $ethe -j MASQUERADE
iptables -A FORWARD -i $wifi -o $ethe -j ACCEPT
echo '1' > /proc/sys/net/ipv4/ip_forward
chown $SUDO_USER:$SUDO_USER /etc/hostapd/hostapd.conf

cat <<EOF > /etc/hostapd/hostapd.conf
interface=$wifi
driver=nl80211
channel=1

ssid=$rede
wpa=2
wpa_passphrase=$senha
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
# Altera as chaves transmitidas/multidifundidas após esse número de segundos.
wpa_group_rekey=600
# Troca a chave mestra após esse número de segundos. A chave mestra é usada como base.
wpa_gmk_rekey=86400

EOF

cat <<EOF > /usr/share/Hotspot/StartHotspot.sh
#!/bin/bash

service hostapd stop
service dnsmasq stop
sed -i 's#^DAEMON_CONF=.*#DAEMON_CONF=/etc/hostapd/hostapd.conf#' /etc/init.d/hostapd
ifconfig $wifi up
ifconfig $wifi 192.168.137.1/24
iptables -t nat -F
iptables -F 
iptables -t nat -A POSTROUTING -o $ethe -j MASQUERADE
iptables -A FORWARD -i $wifi -o $ethe -j ACCEPT
echo '1' > /proc/sys/net/ipv4/ip_forward
service hostapd start
service dnsmasq start

exit 0

EOF

fim=EOF
cat <<EOF > /usr/share/Hotspot/HotspotLogin.sh
#!/bin/bash
senha=\$(dialog --title "AUTORIZAÇÃO" --passwordbox "Digite a senha (SUDO):" 8 40 --stdout)
if [[ -z "\$senha" ]]; then
   dialog --title "ERRO" --infobox "A senha (SUDO) não foi digitada." 3 40
   exit 1
fi
clear
echo \$senha|sudo -S -p "" service hostapd stop
sudo service dnsmasq stop
sudo sed -i 's#^DAEMON_CONF=.*#DAEMON_CONF=/etc/hostapd/hostapd.conf#' /etc/init.d/hostapd
sudo ifconfig $wifi up
sudo ifconfig $wifi 192.168.137.1/24
sudo iptables -t nat -F
sudo iptables -F 
sudo iptables -t nat -A POSTROUTING -o $ethe -j MASQUERADE
sudo iptables -A FORWARD -i $wifi -o $ethe -j ACCEPT
sudo echo '1' > /proc/sys/net/ipv4/ip_forward
clear
rede=\$(dialog --inputbox "Nome da rede Wi-Fi (SSID)" 10 45 --stdout)
clear
senha=\$(dialog --inputbox "Senha da rede Wi-Fi" 10 45 --stdout)
clear
sudo cat <<$fim > /etc/hostapd/hostapd.conf
interface=$wifi
driver=nl80211
channel=1

ssid=\$rede
wpa=2
wpa_passphrase=\$senha
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
# Altera as chaves transmitidas/multidifundidas após esse número de segundos.
wpa_group_rekey=600
# Troca a chave mestra após esse número de segundos. A chave mestra é usada como base.
wpa_gmk_rekey=86400

$fim

sudo service hostapd start
sudo service dnsmasq start

exit 0

EOF

cat <<EOF > /usr/share/Hotspot/RStarHotspot.sh
#!/bin/bash

service hostapd stop
service dnsmasq stop
sed -i 's#^DAEMON_CONF=.*#DAEMON_CONF=/etc/hostapd/hostapd.conf#' /etc/init.d/hostapd
ifconfig $wifi up
ifconfig $wifi 192.168.137.1/24
iptables -t nat -F
iptables -F 
iptables -t nat -A POSTROUTING -o $ethe -j MASQUERADE
iptables -A FORWARD -i $wifi -o $ethe -j ACCEPT
echo '1' > /proc/sys/net/ipv4/ip_forward
service hostapd start
service dnsmasq start
service hostapd stop
service dnsmasq stop
sed -i 's#^DAEMON_CONF=.*#DAEMON_CONF=/etc/hostapd/hostapd.conf#' /etc/init.d/hostapd
ifconfig $wifi up
ifconfig $wifi 192.168.137.1/24
iptables -t nat -F
iptables -F 
iptables -t nat -A POSTROUTING -o $ethe -j MASQUERADE
iptables -A FORWARD -i $wifi -o $ethe -j ACCEPT
echo '1' > /proc/sys/net/ipv4/ip_forward
service hostapd start
service dnsmasq start
echo "Hotspot reiniciando..." > /usr/share/Hotspot/hotspot.conf
cat /usr/share/Hotspot/hotspot.conf
sleep 5
echo "Hotspot reiniciado..." > /usr/share/Hotspot/hotspot.conf
cat /usr/share/Hotspot/hotspot.conf
sleep 5

service hostapd start
service dnsmasq start

exit 0

EOF

cat <<EOF > /usr/share/Hotspot/StopHotspot.sh
#!/bin/bash

service hostapd stop
service dnsmasq stop

exit 0

EOF

cp /usr/share/applications/RStarHotspot.desktop /home/$SUDO_USER/Desktop
cp /usr/share/applications/StopHotspot.desktop /home/$SUDO_USER/Desktop
cp /usr/share/applications/HotspotLogin.desktop /home/$SUDO_USER/Desktop
chmod +x /usr/share/Hotspot/*.sh /usr/share/applications/RStarHotspot.desktop /usr/share/applications/StopHotspot.desktop 
chmod 775 /home/$SUDO_USER/Desktop/RStarHotspot.desktop /home/$SUDO_USER/Desktop/StopHotspot.desktop /home/$SUDO_USER/Desktop/HotspotLogin.desktop
chown $SUDO_USER:$SUDO_USER /home/$SUDO_USER/Desktop/*.desktop

cat <<EOF >  /etc/init.d/hotstop
#!/bin/sh

### BEGIN INIT INFO
# Provides:      hotspot
# Required-Start:   $remote_fs
# Required-Stop:   $remote_fs
# Should-Start:      $network
# Should-Stop:
# Default-Start:   2 3 4 5
# Default-Stop:      0 1 6
# Short-Description:   Access point and authentication server for Wi-Fi and Ethernet
# Description:      Access point and authentication server for Wi-Fi and Ethernet
#         Userspace IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator
### END INIT INFO

. /lib/lsb/init-functions

case "\$1" in
  start)
   sleep 3 
   /usr/share/Hotspot/StartHotspot.sh
   echo "Hotspot\e[32;1m iniciado\e[0m..." > /usr/share/Hotspot/hotspot.conf
   ;;
  stop)
   /usr/share/Hotspot/StopHotspot.sh
   echo "Hotspot\e[31;1m parado\e[0m..." > /usr/share/Hotspot/hotspot.conf
   ;;
  restart)
   /usr/share/Hotspot/RStarHotspot.sh
   echo "Hotspot\e[32;1m reiniciado\e[0m..." > /usr/share/Hotspot/hotspot.conf
   ;;
  status)
   cat /usr/share/Hotspot/hotspot.conf
   ;;
esac

exit 0

EOF
chmod +x /etc/init.d/hotstop
update-rc.d hotstop defaults
update-rc.d hostapd defaults
update-rc.d dnsmasq defaults
update-rc.d tlp defaults
cat /etc/sudoers | grep -q "$SUDO_USER ALL=NOPASSWD: /etc/init.d/hotstop"
if [ "$?" = "1" ]; then
   echo "As configurações serão atualizadas..." 
   sed '/^$/d' /etc/sudoers > /tmp/temp.txt && mv /tmp/temp.txt /etc/sudoers
   echo "$SUDO_USER ALL=NOPASSWD: /etc/init.d/hotstop" >> /etc/sudoers
else
   echo "As configurações estão atualizadas..."
fi
service hostapd start
echo "Testanto o serviço Hotspot..."
service hotstop start
service hotstop status
    
exit 0

Scripts recomendados

Unificando arquivos de bloqueio e liberação no squid

Recriando /dev/null facilmente

Script para desligar o servidor

Extrair o áudio de arquivos de vídeo

Scritp de Firewall com Iptables


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts