setup for new NetworkManager
This commit is contained in:
106
ap-setup.sh
106
ap-setup.sh
@@ -7,35 +7,36 @@
|
|||||||
# 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
|
||||||
@@ -43,29 +44,7 @@ function get_ap_params() {
|
|||||||
sed -i 's,'wappass=.*','wappass="\"$wappass\""',' /etc/piwifiap.conf
|
sed -i 's,'wappass=.*','wappass="\"$wappass\""',' /etc/piwifiap.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
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 in config file
|
||||||
@@ -110,8 +89,9 @@ 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
|
||||||
@@ -124,31 +104,41 @@ then
|
|||||||
# Save network system in config file
|
# Save network system in config file
|
||||||
sed -i 's,'network_system=.*','network_system="\"NetworkManager\""',' /etc/piwifiap.conf
|
sed -i 's,'network_system=.*','network_system="\"NetworkManager\""',' /etc/piwifiap.conf
|
||||||
|
|
||||||
nmcli con add type bridge \
|
nmcli device wifi hotspot ssid $wapssid password $wappass
|
||||||
con-name piwifi-apbridge \
|
nmcli connection add type bridge con-name 'Bridge' ifname bridge0
|
||||||
ifname bridge0
|
nmcli connection add type ethernet slave-type bridge con-name 'Ethernet' ifname eth0 master bridge0
|
||||||
|
nmcli connection modify 'Hotspot' master bridge0
|
||||||
|
nmcli connection up Bridge
|
||||||
|
nmcli connection up Hotspot
|
||||||
|
}
|
||||||
|
|
||||||
nmcli con add type ethernet \
|
current_user=$(whoami)
|
||||||
slave-type bridge \
|
if [[ "$current_user" != "root" ]]
|
||||||
con-name piwifi-ethernet \
|
then
|
||||||
ifname eth0 \
|
echo "You must have root privileges to run this setup."
|
||||||
master bridge0
|
echo "Try 'sudo $0'"
|
||||||
|
exit 1
|
||||||
nmcli con add type wifi \
|
fi
|
||||||
ifname wlan0 \
|
echo ""
|
||||||
con-name piwifi-ap \
|
echo ""
|
||||||
autoconnect yes \
|
echo "If this terminal connects to a network using ethernet, it can be configured"
|
||||||
ssid "$wapssid" \
|
echo "as a wireless access point for other terminals. Would you like to configure"
|
||||||
slave-type bridge \
|
echo -n "this terminal as an access point? [y/N]: "
|
||||||
master bridge0 \
|
read wapconf
|
||||||
wifi-sec.key-mgmt wpa-psk \
|
if [[ "$wapconf" == "Y" || "$wapconf" == "y" ]]
|
||||||
wifi-sec.psk "$wappass" \
|
then
|
||||||
802-11-wireless.mode ap \
|
# Determine if we are using NetworkManager or systemd-networkd
|
||||||
802-11-wireless.band bg
|
echo ""
|
||||||
|
echo "Copying files..."
|
||||||
nmcli con up piwifi-apbridge
|
chmod +x apsetup/usr/local/bin/*
|
||||||
nmcli con up piwifi-ethernet
|
cp -Rv apsetup/usr/local/bin/* /usr/local/bin
|
||||||
nmcli con up piwifi-ap
|
cp -Rv apsetup/etc/* /etc
|
||||||
|
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."
|
||||||
|
|||||||
Reference in New Issue
Block a user