#!/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-hostapd.sh'" exit 1 fi source ../common.sh echo "" getmodel echo "" getosrelease echo "" getarch 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 apsetup/usr/local/bin/* cp -v apsetup/usr/local/bin/* /usr/local/bin cp -Rv 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 # Create network bridge interface nmcli connection add type bridge con-name 'Bridge' ifname bridge0 # Add ethernet connection to the bridge nmcli connection add type ethernet slave-type bridge con-name 'Ethernet' ifname eth0 master bridge0 # Create wireless interface and add it to the bridge nmcli connection add con-name 'Hotspot' ifname wlan0 type wifi slave-type bridge master bridge0 \ wifi.mode ap wifi.ssid $wapssid wifi-sec.key-mgmt wpa-psk \ wifi-sec.proto rsn wifi-sec.pairwise ccmp \ wifi-sec.psk $wappass # Activate bridge nmcli connection up Bridge # Activate access point nmcli connection up Hotspot echo "" echo "Wireless access point setup is complete." echo "" echo -n "Press enter key to continue..." read cont else exit 2 fi