Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions lib/rdk/NM_Bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
# limitations under the License.
##############################################################################

WIFI_WPA_SUPPLICANT_CONF="/opt/secure/wifi/wpa_supplicant.conf"
RDK_PROFILE=$(grep "RDK_PROFILE" /etc/device.properties | cut -d '=' -f 2)
RDKV_SUPP_CONF="/opt/secure/wifi/wpa_supplicant.conf"

if [ -f $WIFI_WPA_SUPPLICANT_CONF ]; then
SSID=$(cat $WIFI_WPA_SUPPLICANT_CONF | grep -w ssid= | cut -d '"' -f 2)
PSK_LINE=$(grep psk= "$WIFI_WPA_SUPPLICANT_CONF")

if [ -f $RDKV_SUPP_CONF ]; then

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable $RDKV_SUPP_CONF should be quoted to prevent word splitting and glob expansion. Use "$RDKV_SUPP_CONF" instead.

Suggested change
if [ -f $RDKV_SUPP_CONF ]; then
if [ -f "$RDKV_SUPP_CONF" ]; then

Copilot uses AI. Check for mistakes.
SSID=$(cat $RDKV_SUPP_CONF | grep -w ssid= | cut -d '"' -f 2)
PSK_LINE=$(grep psk= "$RDKV_SUPP_CONF")

# Case 1: Quoted passphrase
if [[ "$PSK_LINE" =~ psk=\"(.+)\" ]]; then
Expand All @@ -37,6 +39,35 @@ if [ -f $WIFI_WPA_SUPPLICANT_CONF ]; then
else
PSK=""
fi
echo "`/bin/timestamp` :$0: Removed nmcli SSID connect" >> /opt/logs/NMMonitor.log
sed -i '/network={/,/}/d' /opt/secure/wifi/wpa_supplicant.conf
fi

if [ -z $SSID ]; then

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable $SSID should be quoted to prevent word splitting and handle empty/unset values correctly. Use "$SSID" instead.

Suggested change
if [ -z $SSID ]; then
if [ -z "$SSID" ]; then

Copilot uses AI. Check for mistakes.
echo "`/bin/timestamp` :$0: No SSID found in supplicant conf" >> /opt/logs/NMMonitor.log
echo "`/bin/timestamp` :$0: Trying with previously configured settings" >> /opt/logs/NMMonitor.log

if [ ! -d /opt/secure/NetworkManager/system-connections ]; then
mkdir -p /opt/secure/NetworkManager/system-connections
fi
if [ -d /opt/NetworkManager/system-connections ]; then
cp /opt/NetworkManager/system-connections/* /opt/secure/NetworkManager/system-connections/

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command will fail if the source directory is empty because the wildcard won't expand. Add a check for files or use a safer pattern like 'cp -r /opt/NetworkManager/system-connections/. /opt/secure/NetworkManager/system-connections/' with proper error handling.

Suggested change
cp /opt/NetworkManager/system-connections/* /opt/secure/NetworkManager/system-connections/
cp -r /opt/NetworkManager/system-connections/. /opt/secure/NetworkManager/system-connections/ || echo "`/bin/timestamp` :$0: Failed to copy system-connections" >> /opt/logs/NMMonitor.log

Copilot uses AI. Check for mistakes.
rm -rf /opt/NetworkManager/system-connections/*
fi
nmcli conn reload
else
if [ -d /opt/NetworkManager/system-connections ]; then
rm -rf /opt/NetworkManager/system-connections/*
fi
if [ "$RDK_PROFILE" == "TV" ]; then
echo "`/bin/timestamp` :$0: Migrating Wifi credentials for TVs from NM_Bootsrtap" >> /opt/logs/NMMonitor.log

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'NM_Bootsrtap' to 'NM_Bootstrap'.

Suggested change
echo "`/bin/timestamp` :$0: Migrating Wifi credentials for TVs from NM_Bootsrtap" >> /opt/logs/NMMonitor.log
echo "`/bin/timestamp` :$0: Migrating Wifi credentials for TVs from NM_Bootstrap" >> /opt/logs/NMMonitor.log

Copilot uses AI. Check for mistakes.
fi
if [ -z $PSK ]; then

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable $PSK should be quoted to prevent word splitting and handle empty/unset values correctly. Use "$PSK" instead.

Suggested change
if [ -z $PSK ]; then
if [ -z "$PSK" ]; then

Copilot uses AI. Check for mistakes.
#connect to wifi
nmcli conn add type wifi con-name "$SSID" autoconnect yes ifname wlan0 ssid "$SSID"
nmcli conn reload
else
#connect to wifi
nmcli conn add type wifi con-name "$SSID" autoconnect yes ifname wlan0 ssid "$SSID" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "$PSK"
nmcli conn reload
fi
fi