From 127e8704f7130537148d8a14f635c085658f0b89 Mon Sep 17 00:00:00 2001 From: Nick Leffler Date: Tue, 6 Apr 2021 11:16:10 -0400 Subject: [PATCH] created a script and updated readme --- README.md | 4 +- install.sh | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 install.sh diff --git a/README.md b/README.md index ad27fb7..bc87e5a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Add firewalld rules firewall-cmd --zone=home --add-service=dhcp firewall-cmd --zone=home --add-service=ssh firewall-cmd --zone=public --add-service=ssh - firewall-cmd --runtime-to-permanen + firewall-cmd --runtime-to-permanent *** @@ -90,7 +90,7 @@ Configure DNS Masq Find ```dhcp-range``` and make if what you'd like. I did the following -```dhcp-range=192.168.5.50,192.168.5.150,4h``` +```sed -i 's/#dhcp-range=192.168.0.50,192.168.0.150,12h/dhcp-range=192.168.5.50,192.168.5.150,4h/g'``` *** diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..de0e8de --- /dev/null +++ b/install.sh @@ -0,0 +1,157 @@ +#!/bin/bash + +printInfo() { + echo "Welcome to the RaspbiAPinstaller, this will turn your rPi into an AIO router and AP" + echo "This is very usefull for if you have a usb hotspot that you want access to without the device limit that they usually come with" + echo "If you choose no hotspot then that means only the ethernet will be used" + echo "Once completed the rPi will reboot" +} + +getVars() { + read -p "Do you want the rPi to be a wifi hotspot? [y/n]: " hotspot + + hotspot="${hotspot,,}" + + if [[ "${hotspot}" == "y" ]]; + then + echo "Hotspot will be installed and configured" + elif [[ "${hotspot}" == "n" ]]; + then + echo "Hotspot will not be configured" + else + echo "Please choose y/n" + fi + + read -p "What is the NIC for the USB hotspot" usbNIC + usbNIC="${usbNIC,,}" +} + +installPreReqs() { +apt update +apt upgrade -y +apt install -y tmux htop curl wget +apt purge -y iptables +apt install -y firewalld dnsmasq bridge-utils + +systemctl stop dnsmasq + +if [[ "${hotspot}" == "y" ]] +then + apt install -y hostapd + systemctl stop hostapd +fi +} + +firewallConfig() { +sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf + +firewall-cmd --zone=home --add-interface=br0 +firewall-cmd --zone=public --add-interface=${usbNIC} +firewall-cmd --zone=public --add-masquerade +firewall-cmd --zone=home --add-service=dns +firewall-cmd --zone=home --add-service=dhcp +firewall-cmd --zone=home --add-service=ssh +firewall-cmd --zone=public --add-service=ssh +firewall-cmd --runtime-to-permanent +} + +apConfig() { +echo 'country=US' | tee -a /etc/wpa_supplicant/wpa_supplicant.conf +echo 'DAEMON_CONF="/etc/hostapd/hostapd.conf"' >> etc/default/hostapd + +echo 'bridge=br0' > /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo'ssid=SSID_HERE' >> /etc/hostapd/hostapd.conf +echo 'wpa_passphrase=PASSPHRASE_HERE' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo 'country_code=US' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo 'interface=wlan0' >> /etc/hostapd/hostapd.conf +echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo 'wpa=2' >> /etc/hostapd/hostapd.conf +echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf +echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo 'logger_syslog=0' >> /etc/hostapd/hostapd.conf +echo 'logger_syslog_level=4' >> /etc/hostapd/hostapd.conf +echo 'logger_stdout=-1' >> /etc/hostapd/hostapd.conf +echo 'logger_stdout_level=0' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo 'hw_mode=a' >> /etc/hostapd/hostapd.conf +echo 'wmm_enabled=1' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo '# N' >> /etc/hostapd/hostapd.conf +echo 'ieee80211n=1' >> /etc/hostapd/hostapd.conf +echo 'require_ht=1' >> /etc/hostapd/hostapd.conf +echo 'ht_capab=[MAX-AMSDU-3839][HT40+][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40]' >> /etc/hostapd/hostapd.conf +echo '' >> /etc/hostapd/hostapd.conf +echo '# AC' >> /etc/hostapd/hostapd.conf +echo 'ieee80211ac=1' >> /etc/hostapd/hostapd.conf +echo 'require_vht=1' >> /etc/hostapd/hostapd.conf +echo 'ieee80211d=0' >> /etc/hostapd/hostapd.conf +echo 'ieee80211h=0' >> /etc/hostapd/hostapd.conf +echo 'vht_capab=[MAX-AMSDU-3839][SHORT-GI-80]' >> /etc/hostapd/hostapd.conf +echo 'vht_oper_chwidth=1' >> /etc/hostapd/hostapd.conf +echo 'channel=36' >> /etc/hostapd/hostapd.conf +echo 'vht_oper_centr_freq_seg0_idx=42' >> /etc/hostapd/hostapd.conf +systemctl enable hostapd +} + +bridgeConfig() { +echo "allow-hotplug ${usbNIC}" >> /etc/network/interfaces +echo "auto ${usbNIC}" >> /etc/network/interfaces +echo "iface ${usbNIC}" inet dhcp' >> /etc/network/interfaces +echo '' >> /etc/network/interfaces +echo 'auto eth0' >> /etc/network/interfaces +echo 'allow-hotplug eth0' >> /etc/network/interfaces +echo 'iface eth0 inet manual' >> /etc/network/interfaces +echo '' >> /etc/network/interfaces + +if [[ "${hotspot}" == "y" ]] +then + echo 'auto wlan0' >> /etc/network/interfaces + echo 'allow-hotplug wlan0' >> /etc/network/interfaces + echo 'iface wlan0 inet manual' >> /etc/network/interfaces + echo '' >> /etc/network/interfaces +fi + +echo 'auto br0' >> /etc/network/interfaces +echo 'iface br0 inet static' >> /etc/network/interfaces +echo ' address 192.168.5.1' >> /etc/network/interfaces +echo ' netmask 255.255.255.0' >> /etc/network/interfaces + +if [[ "${hotspot}" == "y" +then + echo ' bridge_ports eth0 wlan0' >> /etc/network/interfaces +else + echo ' bridge_ports eth0' >> /etc/network/interfaces + +echo ' bridge_fd 0' >> /etc/network/interfaces +echo ' bridge_stp off' >> /etc/network/interfaces + +} + +dnsConfig() { +sed -i 's/#interface=/interface=br0/g' /etc/dnsmasq.conf +sed -i 's/#dhcp-range=192.168.0.50,192.168.0.150,12h/dhcp-range=192.168.5.50,192.168.5.150,4h/g' +systemctl enable dnsmasq +} + +### Start Here ### +getVars +installPreReqs +firewallConfig + +if [[ "${bridge}" == "y" ]] +then + bridgeConfig + apConfig +fi + +echo "The rPi will reboot now" +reboot + +### End Here ###