|
| 1 | +#!/bin/bash |
| 2 | +#The script is from km4ack's github. |
| 3 | +#https://github.com/km4ack |
| 4 | + |
| 5 | +#Functions |
| 6 | +checkInstaller() { |
| 7 | + if hash hostapd 2>/dev/null; then |
| 8 | + hostapd "-v"; |
| 9 | + else |
| 10 | + echo "hostapd is not installed!"; |
| 11 | + echo "Installing hostapd..."; |
| 12 | + apt-get update; |
| 13 | + apt-get install hostapd -y; |
| 14 | + fi |
| 15 | + if hash dnsmasq 2>/dev/null; then |
| 16 | + dnsmasq "-v"; |
| 17 | + else |
| 18 | + echo "dnsmasq is not installed!"; |
| 19 | + echo "Installing dnsmasq..."; |
| 20 | + apt-get update; |
| 21 | + apt-get install dnsmasq -y; |
| 22 | + fi |
| 23 | +} |
| 24 | +stopServices(){ |
| 25 | + #stop both services |
| 26 | + systemctl disable hostapd |
| 27 | + systemctl disable dnsmasq |
| 28 | +} |
| 29 | +checkIw(){ |
| 30 | + #check if iw installed. install if not |
| 31 | + iwcheck=$(dpkg --get-selections | grep -w "iw") |
| 32 | + if [ -z "iw" ]; then |
| 33 | + apt-get install iw |
| 34 | + fi |
| 35 | +} |
| 36 | +wifipass () { |
| 37 | + echo;echo; |
| 38 | + echo "This password will be used to connect to the pi" |
| 39 | + echo "when the pi is in hotspot mode" |
| 40 | + read -p "Enter password to use with new hotspot " wifipasswd |
| 41 | + echo |
| 42 | + echo "You entered $wifipasswd" |
| 43 | + read -p "Is this correct? y/n " wifians |
| 44 | + if [ $wifians == "y" ]; then |
| 45 | + echo |
| 46 | + else |
| 47 | + wifipass |
| 48 | + fi |
| 49 | +} |
| 50 | +shackwifi1 () { |
| 51 | + #get ham's wifi credentials |
| 52 | + echo "¿What wifi SSID name would you like to connect to?" |
| 53 | + read -p "SSID Name: " shackwifi |
| 54 | + echo "¿What is the password for this wifi?" |
| 55 | + read -p "Password:" shackpass |
| 56 | + echo |
| 57 | + echo "Your shack's current wifi is: $shackwifi" |
| 58 | + echo "Password: $shackpass" |
| 59 | + echo "¿Is this correct? y/n" |
| 60 | + read shackans |
| 61 | + if [ $shackans == "y" ]; then |
| 62 | + echo |
| 63 | + else |
| 64 | + shackwifi1 |
| 65 | + fi |
| 66 | +} |
| 67 | + |
| 68 | +checkInstaller |
| 69 | +stopServices |
| 70 | + |
| 71 | +mkdir -p $HOME/temp |
| 72 | + |
| 73 | +wifipass |
| 74 | + |
| 75 | +cd $HOME/temp |
| 76 | + |
| 77 | +wget https://raw.githubusercontent.com/sckull/raspberry-pi-4/master/hotspot/hostapd.txt |
| 78 | + |
| 79 | +#set new hotspot passwd |
| 80 | +sed -i "s/wpa_passphrase=1234567890/wpa_passphrase=$wifipasswd/" $HOME/temp/hostapd.txt |
| 81 | +#set country to US |
| 82 | +sed -i 's/country_code=GB/country_code=US/' $HOME/temp/hostapd.txt |
| 83 | + |
| 84 | +#move hostapd to correct location |
| 85 | +mv $HOME/temp/hostapd.txt /etc/hostapd/hostapd.conf |
| 86 | + |
| 87 | +sed -i s'/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/' /etc/default/hostapd |
| 88 | +sed -i s'/DAEMON_OPTS=""/#DAEMON_OPTS=""/' /etc/default/hostapd |
| 89 | + |
| 90 | +#add needed info to dnsmasq.conf |
| 91 | +echo "#AutoHotspot config" >> /etc/dnsmasq.conf |
| 92 | +echo "interface=wlan0" >> /etc/dnsmasq.conf |
| 93 | +echo "bind-dynamic" >> /etc/dnsmasq.conf |
| 94 | +echo "server=8.8.8.8" >> /etc/dnsmasq.conf |
| 95 | +echo "domain-needed" >> /etc/dnsmasq.conf |
| 96 | +echo "bogus-priv" >> /etc/dnsmasq.conf |
| 97 | +echo "dhcp-range=10.10.10.150,10.10.10.200,255.255.255.0,12h" >> /etc/dnsmasq.conf |
| 98 | +echo "#Set up redirect for router.com" >> /etc/dnsmasq.conf |
| 99 | +echo "dhcp-option=3,10.10.10.10" >> /etc/dnsmasq.conf |
| 100 | +echo "address=/router.com/10.10.10.10" >> /etc/dnsmasq.conf |
| 101 | + |
| 102 | +mv /etc/network/interfaces /etc/network/interfaces.org |
| 103 | + |
| 104 | +echo "source-directory /etc/network/interfaces.d" >> /etc/network/interfaces |
| 105 | + |
| 106 | + |
| 107 | +echo "nohook wpa_supplicant" >> /etc/dhcpcd.conf |
| 108 | + |
| 109 | +#setup ip forward |
| 110 | +sed 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf |
| 111 | + |
| 112 | +cd $HOME/temp |
| 113 | + |
| 114 | +wget https://raw.githubusercontent.com/sckull/raspberry-pi-4/master/hotspot/autohotspot-service.txt |
| 115 | + |
| 116 | +#create autohotspot service file |
| 117 | +mv autohotspot-service.txt /etc/systemd/system/autohotspot.service |
| 118 | + |
| 119 | +#start autohotspot service |
| 120 | +systemctl enable autohotspot.service |
| 121 | +#CheckIW |
| 122 | +checkIw |
| 123 | + |
| 124 | +#install autohotspot script |
| 125 | +cd $HOME/temp |
| 126 | +wget https://raw.githubusercontent.com/sckull/raspberry-pi-4/master/hotspot/autohotspotN.txt |
| 127 | +#mod ip address for our custom setup |
| 128 | +sed -i 's/192.168.50.5/10.10.10.10/' autohotspotN.txt |
| 129 | +mv autohotspotN.txt /usr/bin/autohotspotN |
| 130 | +chmod +x /usr/bin/autohotspotN |
| 131 | + |
| 132 | +#run shackwifi function |
| 133 | +shackwifi1 |
| 134 | + |
| 135 | +#add shack wifi to wpa_supplicant.conf |
| 136 | +echo "network={" >> /etc/wpa_supplicant/wpa_supplicant.conf |
| 137 | +echo "ssid=\"$shackwifi\"" >> /etc/wpa_supplicant/wpa_supplicant.conf |
| 138 | +echo "psk=\"$shackpass\"" >> /etc/wpa_supplicant/wpa_supplicant.conf |
| 139 | +echo "key_mgmt=WPA-PSK" >> /etc/wpa_supplicant/wpa_supplicant.conf |
| 140 | +echo "}" >> /etc/wpa_supplicant/wpa_supplicant.conf |
| 141 | + |
| 142 | +#remove hostapd masked error on first run of hotspot |
| 143 | +systemctl unmask hostapd |
| 144 | + |
| 145 | +echo;echo; |
| 146 | +echo "A reboot is required to complete the setup" |
| 147 | +echo "Wifi/AutoHotSpot will not work until reboot" |
0 commit comments