10 Commits
1.0.0 ... main

15 changed files with 230 additions and 228 deletions

1
VERSION.txt Normal file
View File

@@ -0,0 +1 @@
2.0.0

View File

@@ -7,69 +7,49 @@
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
# Wireless Access Point Raspberry Pi Setup # Wireless Access Point Raspberry Pi Setup
function get_ap_params() { function get_ap_params() {
echo "" echo ""
wapssidok=0 wapssidok="no"
while [ "$wapssidok" -ne 1 ] while [[ "$wapssidok" == "no" ]]
do do
echo "This access point will need an SSID. This is what will appear" 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 "as the name of this terminal when other devices connect."
echo -n "Please enter the desired SSID for this access point: " echo -n "Please enter the desired SSID for this access point: "
read wapssid read wapssid
if [ "$wapssid" = "" ] if [[ "$wapssid" = "" ]]
then then
echo "SSID cannot be blank. Try again." echo "SSID cannot be blank. Try again."
else else
wapssidok=1 wapssidok="yes"
fi fi
done done
wappassok=0 wappassok="no"
while [ "$wappassok" -ne 1 ] while [[ "$wappassok" == "no" ]]
do do
echo "You will need to set a passphrase for this access point. It should" 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 "be at least 8 characters in length and cannot be blank."
echo -n "Please enter the desired passphrase for this access point: " echo -n "Please enter the desired passphrase for this access point: "
read wappass read wappass
wappasslen=`echo -n $wappass | wc -m` wappasslen=$(echo -n $wappass | wc -m)
if [ "$wappass" = "" -o "$wappasslen" -lt 8 ] if [[ "$wappass" == "" || $wappasslen -lt 8 ]]
then then
echo "Passphrase doesn't satisfy requirements above. Try again." echo "Passphrase doesn't satisfy requirements above. Try again."
else else
wappassok=1 wappassok="yes"
fi fi
done done
# Save parameters in config file # Save parameters in config file
sed -i 's,'wapssid=.*','wapssid="\"$wapssid\""',' /etc/piwifiap.conf sed -i 's|'wapssid=.*'|'wapssid="\'$wapssid\'"'|' /etc/piwifiap/piwifiap.conf
sed -i 's,'wappass=.*','wappass="\"$wappass\""',' /etc/piwifiap.conf sed -i 's|'wappass=.*'|'wappass="\'$wappass\'"'|' /etc/piwifiap/piwifiap.conf
sed -i 's|'802-11-wireless-security.psk:.*'|'802-11-wireless-security.psk:$wappass'|' /etc/piwifiap/piwifiap.secret
} }
current_user=`whoami` function config_systemd-networkd() {
if [ "$current_user" != "root" ]
then
echo "You must have root privileges to run this setup."
echo "Try 'sudo $0'"
exit 1
fi
echo ""
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
# Determine if we are using NetworkManager or systemd-networkd
echo ""
echo "Copying files..."
chmod +x apsetup/usr/local/bin/*
cp -Rv apsetup/usr/local/bin/* /usr/local/bin
cp -Rv apsetup/etc/* /etc
if systemctl status dhcpcd.service|grep -q "Active: active (running)"
then
echo "Configuring as wireless access point using systemd-networkd." echo "Configuring as wireless access point using systemd-networkd."
get_ap_params get_ap_params
# Save network system in config file # Save network system type in config file
sed -i 's,'network_system=.*','network_system="\"systemd-networkd\""',' /etc/piwifiap.conf sed -i 's,'network_system=.*','network_system="\"systemd-networkd\""',' /etc/piwifiap/piwifiap.conf
apt install hostapd apt install hostapd
systemctl unmask hostapd systemctl unmask hostapd
@@ -110,45 +90,75 @@ then
fi fi
echo "" echo ""
echo "" echo ""
elif systemctl status NetworkManager.service|grep -q "Active: active (running)" }
then
function config_NetworkManager() {
echo "Configuring as wireless access point using NetworkManager." echo "Configuring as wireless access point using NetworkManager."
rfkill unblock wlan rfkill unblock wlan
get_ap_params get_ap_params
# Clean up a possible failed previous attempt # Clean up a possible failed previous attempt
nmcli con del piwifi-ap >/dev/null 2>&1 nmcli con del piwifi-hotspot >/dev/null 2>&1
nmcli con del piwifi-ethernet >/dev/null 2>&1 nmcli con del piwifi-ethernet >/dev/null 2>&1
nmcli con del piwifi-apbridge >/dev/null 2>&1 nmcli con del piwifi-bridge >/dev/null 2>&1
# Save network system in config file
sed -i 's,'network_system=.*','network_system="\"NetworkManager\""',' /etc/piwifiap.conf
nmcli con add type bridge \ # Save network system type in config file
con-name piwifi-apbridge \ sed -i 's|'network_system=.*'|'network_system="\"NetworkManager\""'|' /etc/piwifiap/piwifiap.conf
ifname bridge0
nmcli con add type ethernet \ # create bridge interface
slave-type bridge \ nmcli con add type bridge con-name piwifi-bridge ifname bridge0
con-name piwifi-ethernet \
ifname eth0 \
master bridge0
nmcli con add type wifi \ # add ethernet to bridge
ifname wlan0 \ nmcli con add type ethernet slave-type bridge con-name piwifi-ethernet ifname eth0 master bridge0
con-name piwifi-ap \
autoconnect yes \
ssid "$wapssid" \
slave-type bridge \
master bridge0 \
wifi-sec.key-mgmt wpa-psk \
wifi-sec.psk "$wappass" \
802-11-wireless.mode ap \
802-11-wireless.band bg
nmcli con up piwifi-apbridge # create access point
nmcli con up piwifi-ethernet nmcli con add type wifi ifname wlan0 mode ap con-name piwifi-hotspot ssid $wapssid
nmcli con up piwifi-ap nmcli con modify piwifi-hotspot wifi-sec.key-mgmt wpa-psk
nmcli con modify piwifi-hotspot 802-11-wireless.band bg
# disable protected management frames for wpa_supplicant bug in trixie
nmcli con modify piwifi-hotspot 802-11-wireless-security.pmf 1
# add wifi to bridge
nmcli con modify piwifi-hotspot master bridge0 slave-type bridge
# activate bridge
nmcli con up piwifi-bridge
# activite wifi
nmcli con up piwifi-hotspot passwd-file /etc/piwifiap/piwifiap.secret
}
current_user=$(whoami)
if [[ "$current_user" != "root" ]]
then
echo "You must have root privileges to run this setup."
echo "Try 'sudo $0'"
exit 1
fi
echo ""
echo ""
echo "If this system connects to a network using ethernet, it can be configured"
echo "as a wireless access point for other systems. Would you like to configure"
echo -n "this system as an access point? [y/N]: "
read wapconf
if [[ "$wapconf" == "Y" || "$wapconf" == "y" ]]
then
# Determine if we are using NetworkManager or systemd-networkd
echo ""
echo "Copying files..."
chmod +x apsetup/usr/local/bin/wap-*
cp -R apsetup/usr/local/bin/* /usr/local/bin/
cp -R apsetup/etc/* /etc/
chown -R root:root /etc/piwifiap
chmod 600 /etc/piwifiap/*
if systemctl status dhcpcd.service|grep -q "Active: active (running)"
then
config_systemd-networkd
elif systemctl status NetworkManager.service|grep -q "Active: active (running)"
then
config_NetworkManager
else else
echo "Unable to determine what type of network configuration (systemd-networkd" echo "Unable to determine what type of network configuration (systemd-networkd"
echo "or NetworkManager) your system uses. Automatic setup cannot continue." echo "or NetworkManager) your system uses. Automatic setup cannot continue."
@@ -165,12 +175,23 @@ then
echo "" echo ""
echo "To disable the access point altogether in the future, run:" echo "To disable the access point altogether in the future, run:"
echo " sudo wap-disable" echo " sudo wap-disable"
echo "at a command prompt and reboot the terminal. To re-enable it, run:" echo "at a command prompt and reboot. To re-enable it, run:"
echo " sudo wap-enable" echo " sudo wap-enable"
echo "at a command prompt and reboot the terminal." echo "at a command prompt and reboot."
echo "" echo ""
echo -n "Press enter key to continue..." echo "The system must be rebooted for the configuration to take effect."
read cont echo ""
read -p "Would you like to reboot now? [Y/n]: " -r rebootok
case "$rebootok" in
"y" | "Y" | "")
reboot
;;
*)
echo "You may continue to use the system, but the access point will not be"
echo "functional until you reboot."
exit 0
;;
esac
else else
exit 2 exit 2
fi fi

View File

@@ -0,0 +1 @@
802-11-wireless-security.psk:none

View File

@@ -1,3 +0,0 @@
sudo wap-enable
Enable Wireless Access Point
* 0 1 0 0 0 0 0 -

View File

@@ -1 +0,0 @@

View File

@@ -1,3 +0,0 @@
sudo wap-disable
Disable Wireless Access Point
* 0 1 0 0 0 0 0 -

View File

@@ -1 +0,0 @@

View File

@@ -1,11 +0,0 @@
/etc/hostapd/hostapd.conf
Edit Wireless Access Point Parameters
systemctl restart hostapd
0
0

View File

@@ -1 +0,0 @@

View File

@@ -1,8 +0,0 @@
display_mode=1
params_file=0
params_cmd=0
columns=1
height=
wrap=
width=
sort=

20
apsetup/usr/local/bin/wap-disable Normal file → Executable file
View File

@@ -9,19 +9,21 @@ then
exit 1 exit 1
fi fi
source /etc/piwifiap.conf source /etc/piwifiap/piwifiap.conf
if [ "$network_system" = "systemd-networkd" ] case "$network_system" in
then "systemd-networkd")
systemctl stop hostapd systemctl stop hostapd
systemctl disable hostapd systemctl disable hostapd
elif [ "$network_system" = "NetworkManager" ] ;;
then "NetworkManager")
nmcli con down piwifi-ap nmcli con down piwifi-hotspot
nmcli con mod piwifi-ap autoconnect no nmcli con mod piwifi-hotspot autoconnect no
else ;;
*)
echo "Unable to determine what type of network configuration (systemd-networkd" echo "Unable to determine what type of network configuration (systemd-networkd"
echo "or NetworkManager) your system uses." echo "or NetworkManager) your system uses."
echo "Cannot disable wireless access point." echo "Cannot disable wireless access point."
exit 2 exit 2
fi ;;
esac

21
apsetup/usr/local/bin/wap-enable Normal file → Executable file
View File

@@ -9,20 +9,21 @@ then
exit 1 exit 1
fi fi
source /etc/piwifiap.conf source /etc/piwifiap/piwifiap.conf
if [ "$network_system" = "systemd-networkd" ] case "$network_system" in
then "systemd-networkd")
systemctl enable hostapd systemctl enable hostapd
systemctl start hostapd systemctl start hostapd
elif [ "$network_system" = "NetworkManager" ] ;;
then "NetworkManager")
nmcli con mod piwifi-ap autoconnect yes nmcli con mod piwifi-hotspot autoconnect yes
nmcli con up piwifi-ap nmcli con up piwifi-hotspot passwd-file /etc/piwifiap/piwifiap.secret
else ;;
*)
echo "Unable to determine what type of network configuration (systemd-networkd" echo "Unable to determine what type of network configuration (systemd-networkd"
echo "or NetworkManager) your system uses." echo "or NetworkManager) your system uses."
echo "Cannot enable wireless access point." echo "Cannot enable wireless access point."
exit 2 exit 2
fi ;;
esac

50
apsetup/usr/local/bin/wap-setpassphrase Normal file → Executable file
View File

@@ -9,39 +9,41 @@ then
exit 1 exit 1
fi fi
source /etc/piwifiap.conf source /etc/piwifiap/piwifiap.conf
newppok=0 wappassok="no"
while [ "$newppok" -ne 1 ] while [[ "$wappassok" == "no" ]]
do do
echo -n "New passphrase: " echo "You will need to set a passphrase for this access point. It should"
read newpp echo "be at least 8 characters in length and cannot be blank."
newpplen=`echo -n $newpp | wc -m` echo -n "Please enter the desired passphrase for this access point: "
if [ "$newpp" = "" -o "$newpplen" -lt 8 ] read wappass
wappasslen=$(echo -n $wappass | wc -m)
if [[ "$wappass" == "" || $wappasslen -lt 8 ]]
then then
echo "Passphrase didn't satisfy requirements. Try again or hit <ctrl>-c to abort." echo "Passphrase doesn't satisfy requirements above. Try again."
else else
newppok=1 wappassok="yes"
fi fi
done done
if [ "$network_system" = "systemd-networkd" ] case "$network_system" in
then "systemd-networkd")
sed -i "/wpa_passphrase=.*/c wpa_passphrase=$newpp" /etc/hostapd/hostapd.conf sed -i "/wpa_passphrase=.*/c wpa_passphrase=$wappass" /etc/hostapd/hostapd.conf
systemctl restart hostapd systemctl restart hostapd
elif [ "$network_system" = "NetworkManager" ] sed -i 's|'wappass=.*'|'wappass="\'$wappass\'"'|' /etc/piwifiap/piwifiap.conf
then sed -i 's|'802-11-wireless-security.psk:.*'|'802-11-wireless-security.psk:$wappass'|' /etc/piwifiap/piwifiap.secret
nmcli con down piwifi-ap ;;
nmcli con mod piwifi-ap wifi-sec.psk "$newpp" "NetworkManager")
nmcli con up piwifi-ap nmcli con down piwifi-hotspot
else sed -i 's|'wappass=.*'|'wappass="\'$wappass\'"'|' /etc/piwifiap/piwifiap.conf
sed -i 's|'802-11-wireless-security.psk:.*'|'802-11-wireless-security.psk:$wappass'|' /etc/piwifiap/piwifiap.secret
nmcli con up piwifi-hotspot passwd-file /etc/piwifiap/piwifiap.secret
;;
*)
echo "Unable to determine what type of network configuration (systemd-networkd" echo "Unable to determine what type of network configuration (systemd-networkd"
echo "or NetworkManager) your system uses." echo "or NetworkManager) your system uses."
echo "Cannot modify wireless access point parameters." echo "Cannot modify wireless access point parameters."
exit 2 exit 2
fi ;;
esac
sed -i 's,'wappass=.*','wappass="\"$newpp\""',' /etc/piwifiap.conf

50
apsetup/usr/local/bin/wap-setssid Normal file → Executable file
View File

@@ -9,37 +9,39 @@ then
exit 1 exit 1
fi fi
source /etc/piwifiap.conf source /etc/piwifiap/piwifiap.conf
newssidok=0 wapssidok="no"
while [ "$newssidok" -ne 1 ] while [[ "$wapssidok" == "no" ]]
do do
echo -n "New SSID: " echo "This access point will need an SSID. This is what will appear"
read newssid echo "as the name of this terminal when other devices connect."
if [ "$newssid" = "" ] echo -n "Please enter the desired SSID for this access point: "
read wapssid
if [[ "$wapssid" = "" ]]
then then
echo "SSID cannot be blank. Try again or hit <ctrl>-c to abort." echo "SSID cannot be blank. Try again."
else else
newssidok=1 wapssidok="yes"
fi fi
done done
if [ "$network_system" = "systemd-networkd" ] case "$network_system" in
then "systemd-networkd")
sed -i "/ssid=.*/c ssid=$newssid" /etc/hostapd/hostapd.conf sed -i "/ssid=.*/c ssid=$wapssid" /etc/hostapd/hostapd.conf
systemctl restart hostapd systemctl restart hostapd
elif [ "$network_system" = "NetworkManager" ] sed -i 's|'wapssid=.*'|'wapssid="\'$wapssid\'"'|' /etc/piwifiap/piwifiap.conf
then ;;
nmcli con down piwifi-ap "NetworkManager")
nmcli con mod piwifi-ap ssid "$newssid" nmcli con down piwifi-hotspot
nmcli con up piwifi-ap nmcli con mod piwifi-hotspot ssid "$wapssid"
else nmcli con up piwifi-hotspot passwd-file /etc/piwifiap/piwifiap.secret
sed -i 's|'wapssid=.*'|'wapssid="\'$wapssid\'"'|' /etc/piwifiap/piwifiap.conf
;;
*)
echo "Unable to determine what type of network configuration (systemd-networkd" echo "Unable to determine what type of network configuration (systemd-networkd"
echo "or NetworkManager) your system uses." echo "or NetworkManager) your system uses."
echo "Cannot modify wireless access point parameters." echo "Cannot modify wireless access point parameters."
exit 2 exit 2
fi ;;
esac
sed -i 's,'wapssid=.*','wapssid="\"$newssid\""',' /etc/piwifiap.conf