From 78b09cc4b4863a1bdc4c1d2d17bdad48cbf1a43c Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 13 Dec 2019 16:54:01 +0000 Subject: [PATCH] Initialize wpa_supplicant, create if absent. Resolves #452 --- installers/common.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 9cfedc31..fc12560f 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -209,6 +209,11 @@ function check_for_old_configs() { sudo cp /etc/rc.local "$raspap_dir/backups/rc.local.`date +%F-%R`" sudo ln -sf "$raspap_dir/backups/rc.local.`date +%F-%R`" "$raspap_dir/backups/rc.local" fi + + if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then + sudo cp /etc/wpa_supplicant/wpa_supplicant.conf "$raspap_dir/backups/wpa_supplicant.conf.`date +%F-%R`" + sudo ln -sf "$raspap_dir/backups/wpa_supplicant.conf.`date +%F-%R`" "$raspap_dir/backups/wpa_supplicant.conf" + fi } # Move configuration file to the correct location @@ -343,9 +348,26 @@ function patch_system_files() { install_log "Sudoers file already patched" fi - # add symlink to prevent wpa_cli cmds from breaking with multiple wlan interfaces + # Add symlink to prevent wpa_cli cmds from breaking with multiple wlan interfaces install_log "Symlinked wpa_supplicant hooks for multiple wlan interfaces" - sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /etc/dhcp/dhclient-enter-hooks.d/ + if [ ! -f /usr/share/dhcpcd/hooks/10-wpa_supplicant ]; then + sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /etc/dhcp/dhclient-enter-hooks.d/ + fi + + # Add ctrl_interface and group to wpa_supplicant, create if absent + install_log "Patching wpa_supplicant.conf" + line="ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" + if [ ! -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then + echo "Creating wpa_supplicant.conf" + sudo touch /etc/wpa_supplicant/wpa_supplicant.conf || install_error "Unable to create wpa_supplicant.conf" + echo $line | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf || install_error "Unable to write to wpa_supplicant.conf" + fi + if grep "$line" /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null; then + echo "ctrl_interface is OK" + else + sudo sed -i "1 i\$line" /etc/wpa_supplicant/wpa_supplicant.conf || install_error "Unable to write to wpa_supplicant.conf" + echo "Adding line $line" + fi # Unmask and enable hostapd.service install_log "Unmasking and enabling hostapd service"