#!/bin/bash # ap-setup.sh # OpenDRS Online Discrepancy Reporting System # Copyright (C) 2022 Rod Wright # SPDX-License-Identifier: GPL-2.0 # Wireless Access Point Raspberry Pi Setup current_user=`whoami` if [ "$current_user" != "root" ] then echo "You must have root privileges to run this setup." echo "Try 'sudo ./ap-setup.sh'" exit 1 fi echo "" echo -n "Raspberry Pi model is: " rpimodeltxt=$(tr -d '\0' < /proc/device-tree/model) echo $rpimodeltxt echo $rpimodeltxt|grep -q "Raspberry Pi 3" if [ $? -eq 0 ] then ismodel3="true" fi echo "" echo -n "OS Release version is: " os_rel_ver=`grep VERSION_CODENAME /etc/os-release | cut -d "=" -f2` echo $os_rel_ver echo "" echo -n "Architecture is: " arch_32_64=`getconf LONG_BIT` echo "$arch_32_64 bit" echo "" if [ $arch_32_64 -eq 64 -a "$ismodel3" = "true" ] then echo "Raspberry Pi 3 hardware is known to have problems with acting as a" echo "wireless access point when 64 bit kernels are used. If you intend for" echo "this terminal to act as a wireless access point, you should stop here," echo "power off, remove the microsd card and re-image using a 32 bit version" echo "of Raspberry Pi OS." echo -n "Ignore and [c]ontinue or [A]bort? [c/A]: " read archabort if [ "$archabort" = "C" -o "$archabort" = "c" ] then echo "" echo "Continuing with installation." else echo "" echo "Aborting installation." exit 0 fi fi echo "" echo "If this terminal connects to a network using ethernet, it can be configured" echo "as a wireless access point for other terminals. Would you like to configure" echo -n "this terminal as an access point? [y/N]: " read wapconf if [ "$wapconf" = "Y" -o "$wapconf" = "y" ] then echo "Configuring as wireless access point." echo "" echo "Copying files..." chmod +x $os_rel_ver/apsetup/usr/local/bin/* cp -v$os_rel_ver/apsetup/usr/local/bin/* /usr/local/bin cp -Rv $os_rel_ver/apsetup/etc/* /etc echo "" wapssidok=0 while [ "$wapssidok" -ne 1 ] do echo "This access point will need an SSID. This is what will appear" echo "as the name of this terminal when other devices connect." echo -n "Please enter the desired SSID for this access point: " read wapssid if [ "$wapssid" = "" ] then echo "SSID cannot be blank. Try again." else wapssidok=1 fi done wappassok=0 while [ "$wappassok" -ne 1 ] do echo "You will need to set a passphrase for this access point. It should" echo "be at least 8 characters in length and cannot be blank." echo -n "Please enter the desired passphrase for this access point: " read wappass wappasslen=`echo -n $wappass | wc -m` if [ "$wappass" = "" -o "$wappasslen" -lt 8 ] then echo "Passphrase doesn't satisfy requirements above. Try again." else wappassok=1 fi done apt install hostapd systemctl unmask hostapd systemctl enable hostapd echo "[NetDev]" >/etc/systemd/network/bridge-br0.netdev echo "Name=br0" >>/etc/systemd/network/bridge-br0.netdev echo "Kind=bridge" >>/etc/systemd/network/bridge-br0.netdev echo "[Match]" >/etc/systemd/network/br0-member-eth0.network echo "Name=eth0" >>/etc/systemd/network/br0-member-eth0.network echo "" >>/etc/systemd/network/br0-member-eth0.network echo "[Network]" >>/etc/systemd/network/br0-member-eth0.network echo "Bridge=br0" >>/etc/systemd/network/br0-member-eth0.network systemctl enable systemd-networkd mv /etc/dhcpcd.conf /etc/dhcpcd.conf.old echo "denyinterfaces wlan0 eth0" >/etc/dhcpcd.conf cat /etc/dhcpcd.conf.old >>/etc/dhcpcd.conf echo "interface br0" >>/etc/dhcpcd.conf rfkill unblock wlan echo "country_code=US" >/etc/hostapd/hostapd.conf echo "interface=wlan0" >>/etc/hostapd/hostapd.conf echo "bridge=br0" >>/etc/hostapd/hostapd.conf echo "ssid=$wapssid" >>/etc/hostapd/hostapd.conf echo "hw_mode=g" >>/etc/hostapd/hostapd.conf echo "channel=7" >>/etc/hostapd/hostapd.conf echo "macaddr_acl=0" >>/etc/hostapd/hostapd.conf echo "auth_algs=1" >>/etc/hostapd/hostapd.conf echo "ignore_broadcast_ssid=0" >>/etc/hostapd/hostapd.conf echo "wpa=2" >>/etc/hostapd/hostapd.conf echo "wpa_passphrase=$wappass" >>/etc/hostapd/hostapd.conf echo "wpa_key_mgmt=WPA-PSK" >>/etc/hostapd/hostapd.conf echo "wpa_pairwise=TKIP" >>/etc/hostapd/hostapd.conf echo "rsn_pairwise=CCMP" >>/etc/hostapd/hostapd.conf wget -c http://github.com/pjz/webmin-modules/releases/download/v1.0/hostap.wbm.gz gzip -d hostap.wbm.gz /usr/share/webmin/install-module.pl hostap.wbm echo "" echo "" echo "Wireless access point setup is complete. It will be" echo "automatically enabled after reboot. To change the SSID or" echo "passphrase in the future, edit the file /etc/hostapd/hostapd.conf" echo "or use the Host AP module in the Servers section of Webmin." echo "" echo "To disable the access point altogether in the future, run:" echo " sudo wap-disable" echo "at a command prompt and reboot the terminal. To re-enable it, run:" echo " sudo wap-enable" echo "at a command prompt and reboot the terminal." echo "It can also be enabled or disabled via Custom Commands in the Tools" echo "section of Webmin." echo "" echo -n "Press enter key to continue..." read cont else exit 2 fi