Skip to content

Commit

Permalink
rc.local: support Network Manager
Browse files Browse the repository at this point in the history
Remove some unnecessary code, and add support for using nmcli
to configure wifi when Network Manager is enabled..
  • Loading branch information
marcone committed Dec 4, 2024
1 parent 562be33 commit e7fe554
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions pi-gen-sources/00-teslausb-tweaks/files/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,26 @@ function get_script () {
}

function enable_wifi () {
setup_progress "Detecting whether to update wpa_supplicant.conf"
setup_progress "Detecting whether to configure wifi"
if [[ -n "$SSID" ]] && [[ -n "$WIFIPASS" ]]
then
if [ ! -e /teslausb/WIFI_ENABLED ]
then
if [ -e /root/bin/remountfs_rw ]
if [ -x /root/bin/remountfs_rw ]
then
/root/bin/remountfs_rw
fi
setup_progress "Wifi variables specified, and no /teslausb/WIFI_ENABLED. Building wpa_supplicant.conf."
cp /teslausb/wpa_supplicant.conf.sample /teslausb/wpa_supplicant.conf
sed -i -e "sTEMPSSID${SSID}g" /teslausb/wpa_supplicant.conf
sed -i -e "sTEMPPASS${WIFIPASS}g" /teslausb/wpa_supplicant.conf
cp /teslausb/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
if systemctl -q is-enabled NetworkManager.service
then
setup_progress "Connecting to wifi using Network Manager"
nmcli device wifi connect "$SSID" password "$WIFIPASS"
else
setup_progress "Configuring wpa_supplicant"
cp /teslausb/wpa_supplicant.conf.sample /teslausb/wpa_supplicant.conf
sed -i -e "sTEMPSSID${SSID}g" /teslausb/wpa_supplicant.conf
sed -i -e "sTEMPPASS${WIFIPASS}g" /teslausb/wpa_supplicant.conf
cp /teslausb/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
fi

# set the host name now if possible, so it's effective immediately after the reboot
local old_host_name
Expand Down Expand Up @@ -178,13 +184,6 @@ then
fi
touch "/teslausb/TESLAUSB_SETUP_STARTED"

# Grab the setup variables. Should still be there since setup isn't finished.
# This is a double check to cover various scenarios of mixed headless/not headless setup attempts
if [ -e "/teslausb/teslausb_setup_variables.conf" ] && [ ! -e "/root/teslausb_setup_variables.conf" ]
then
mv /teslausb/teslausb_setup_variables.conf /root/
dos2unix /root/teslausb_setup_variables.conf
fi
if [ -e "/root/teslausb_setup_variables.conf" ]
then
source "/root/teslausb_setup_variables.conf"
Expand Down

0 comments on commit e7fe554

Please sign in to comment.