Commit 7e2ff917 authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Better grep usage

When possible, fgrep is preferred.
This prevents interpreting variable search patterns as expressions.
In setting the control paths, the search expression was updated to match what wpa_supplicant uses.
parent b0373830
......@@ -105,7 +105,7 @@ create_profile()
local box flags key msg security
PROFILE="$INTERFACE-${1//\//_}"
[[ -e "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu"
flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2)
flags=$(fgrep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2)
if [[ "$flags" =~ WPA|WEP ]]; then
security=${BASH_REMATCH[0],,}
else
......
......@@ -105,7 +105,7 @@ wpa_supplicant_scan_and_find() {
for ((try=0; try < $RETRIES; try++)); do
local found
sleep 2
found=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan_results | tail -n+2 | cut -f ${FIELD} | grep -F -x -m 1 "${ITEM}")
found=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan_results | tail -n+2 | cut -f ${FIELD} | fgrep -x -m 1 "${ITEM}")
(( $? == 0 )) && scan_ok=1
# ITEM has been found, echo it
......@@ -144,7 +144,7 @@ wpa_supplicant_scan_info() {
# Wait at least 3 seconds for scan results
sleep 3
# Sometimes, that is not enough (FS#29946)
timeout_wait 7 '! wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | grep -q "wpa_state=SCANNING"'
timeout_wait 7 '! wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | fgrep -q "wpa_state=SCANNING"'
wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan_results |
grep -v "^Selected" |
grep -v "^bssid" |
......
......@@ -45,8 +45,8 @@ ethernet_up() {
[[ -z "$WPA_DRIVER" ]] && WPA_DRIVER="wired"
# Set wpa_supplicant control path (FS#25473)
WPA_CTRL_PATH=/run/wpa_supplicant
if grep "^ *ctrl_interface=" "$WPA_CONF" &>/dev/null; then
WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | tail -n 1 | cut -d= -f 2- | sed -r 's/DIR=(.*) +GROUP=.*/\1/')
if grep -q "^ *ctrl_interface=" "$WPA_CONF"; then
WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | cut -d= -f 2- | sed -r 's/^DIR=(.*) GROUP=.*/\1/')
fi
report_debug ethernet_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"
......
......@@ -25,8 +25,8 @@ wireless_up() {
if [[ "$SECURITY" = "wpa-config" ]]; then
WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}"
# Use defined control path (FS#24949)
if grep "^ *ctrl_interface=" "$WPA_CONF" &>/dev/null; then
WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | tail -n 1 | cut -d= -f 2- | sed -r 's/DIR=(.*) +GROUP=.*/\1/')
if grep -q "^ *ctrl_interface=" "$WPA_CONF"; then
WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | cut -d= -f 2- | sed -r 's/^DIR=(.*) GROUP=.*/\1/')
fi
else
WPA_CONF=$(make_wpa_config_file $INTERFACE)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment