Commit a49ffaf7 authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Switch to single quotes in contexts where we may want to use '\'

Inside double quotes, backslash is an escape character. Hence, it is
cleaner to use single quotes where backslashes may occur. This includes
pattern strings for print, grep, and sed.
parent 1a35b9ff
......@@ -11,7 +11,7 @@ _wireless_interfaces() {
_netctl_profiles() {
find -L /etc/netctl -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf "%f\n"
find -L /etc/netctl -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf '%f\n'
}
......
......@@ -12,7 +12,7 @@ _wireless_interfaces() {
(( $+function[_netctl_command] )) ||
_netctl_command() {
[[ $words[1] = (start|stop|restart|switch-to|is-active|status|enable|disable|reenable|is-enabled|edit|wait-online) ]] &&
compadd "${(f)$(find -L /etc/netctl -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf "%f\n")}"
compadd "${(f)$(find -L /etc/netctl -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf '%f\n')}"
}
......
......@@ -11,7 +11,7 @@ case "$2" in
while IFS= read -r profile; do
if ForceConnect=yes "$SUBR_DIR/network" start "$profile"; then
mkdir -p "$(dirname "$PROFILE_FILE")"
printf "%s" "$profile" > "$PROFILE_FILE"
printf '%s' "$profile" > "$PROFILE_FILE"
exit 0
fi
done < <(list_profiles | while IFS= read -r profile; do
......@@ -26,7 +26,7 @@ case "$2" in
: ${Priority:=1}
fi
is_yes "${ExcludeAuto:-yes}" && exit
printf "%i\t%s\n" "${Priority:-0}" "$profile"
printf '%i\t%s\n' "${Priority:-0}" "$profile"
report_debug "Included profile '$profile'"
)
done | sort -nrs -k 1,1 | cut -f 2-)
......
......@@ -36,7 +36,7 @@ wireless_up() {
report_error "Could not create a WPA config file for interface '$Interface'"
return 1
fi
printf "%s\n" "network={" "$(wpa_make_config_block)" "}" >> "$config_file"
printf '%s\n' "network={" "$(wpa_make_config_block)" "}" >> "$config_file"
fi
# Start the WPA supplicant
......
......@@ -106,7 +106,7 @@ timeout_wait() {
## List all acceptable profiles names separated by newlines
list_profiles() {
# Follow aliases with -L, skip forbidden/reserved names
find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf "%f\n"
find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf '%f\n'
}
## Sources all hooks and a profile (but no interface configuration)
......
......@@ -27,7 +27,7 @@ dhcp_call() {
resolvconf_add() {
local interface="$1"
shift
printf "%s\n" "$@" | do_readable resolvconf -a "$interface"
printf '%s\n' "$@" | do_readable resolvconf -a "$interface"
}
......
......@@ -11,8 +11,8 @@ wpa_call() {
if [[ $WPA_CTRL_DIR ]]; then
args+=("-p" "$WPA_CTRL_DIR")
elif [[ $WPAConfigFile ]] && grep -q "^[[:space:]]*ctrl_interface=" "$WPAConfigFile"; then
WPA_CTRL_DIR=$(sed -n "0,/^[[:space:]]*ctrl_interface=/s///p" "$WPAConfigFile")
elif [[ $WPAConfigFile ]] && grep -q '^[[:space:]]*ctrl_interface=' "$WPAConfigFile"; then
WPA_CTRL_DIR=$(sed -n '0,/^[[:space:]]*ctrl_interface=/s///p' "$WPAConfigFile")
if [[ $WPA_CTRL_DIR == DIR=* ]]; then
WPA_CTRL_DIR=${WPA_CTRL_DIR:4}
WPA_CTRL_DIR=${WPA_CTRL_DIR%% GROUP=*}
......@@ -35,7 +35,7 @@ wpa_is_active() {
# $1: interface name
wpa_get_state() {
local state
state=$(wpa_call "$1" status | grep -m1 "^wpa_state=") || return 1
state=$(wpa_call "$1" status | grep -m1 '^wpa_state=') || return 1
echo "${state#wpa_state=}"
}
......@@ -179,14 +179,14 @@ wpa_quote() {
wpa_unquote() {
local string="$1"
if [[ $string == \"*\" ]]; then
printf "%s" "${string:1:-1}"
printf '%s' "${string:1:-1}"
elif [[ $string == +([[:xdigit:]][[:xdigit:]]) ]]; then
while [[ $string ]]; do
printf "\x${string:0:2}"
printf "\\x${string:0:2}"
string=${string:2}
done
else
printf "%s" "${string}"
printf '%s' "${string}"
fi
}
......@@ -239,7 +239,7 @@ wpa_make_config_block() {
fi
;;
wpa-configsection)
printf "%s\n" "${WPAConfigSection[@]}"
printf '%s\n' "${WPAConfigSection[@]}"
return
;;
*)
......
......@@ -123,7 +123,7 @@ switch_to() {
# List of enabled networks
local enabled_networks=$(wpa_call "$interface" list_networks | tail -n+2 | \
cut -f 1,4 | grep -Fv "[DISABLED]" | cut -f 1 | tr "\n" ' ')
cut -f 1,4 | grep -Fv '[DISABLED]' | cut -f 1 | tr '\n' ' ')
reenable_networks() {
for network in $enabled_networks; do
......@@ -222,7 +222,7 @@ start() {
is_yes "${ExcludeAuto:-no}" && exit
# Set default and exclude wpa-config as it does not fit this scheme
[[ ${Security:=none} != "wpa-config" ]] || exit
printf "%s\n" "network={" "$(wpa_make_config_block)" "id_str=\"$profile\"" "}" >> "$wpa_conf"
printf '%s\n' "network={" "$(wpa_make_config_block)" "id_str=\"$profile\"" "}" >> "$wpa_conf"
report_notice "Included profile '$profile'"
)
done
......
......@@ -45,7 +45,7 @@ store() {
mkdir -p "$(dirname "$STATE_FILE")"
list_profiles | while IFS= read -r Profile; do
if sd_call "is-active --quiet" "$Profile" &> /dev/null; then
printf "%s\n" "$Profile"
printf '%s\n' "$Profile"
fi
done > "$STATE_FILE"
}
......@@ -65,7 +65,7 @@ stop_all() {
# We cannot pipe to mapfile, as the end of a pipe is inside a subshell
mapfile -t Profiles < <(list_profiles)
if (( ${#Profiles[@]} )); then
do_debug sd_call stop "${Profiles[@]}" 2> >(grep -Fv "not loaded" >&2)
do_debug sd_call stop "${Profiles[@]}" 2> >(grep -Fv 'not loaded' >&2)
fi
}
......@@ -77,14 +77,14 @@ switch_to() {
# We assume interface names are not quoted
# Using read removes leading whitespace
read InterfaceLine < \
<(grep -om1 "^[[:space:]]*Interface=[[:alnum:]:._-]\+" "$1")
<(grep -om1 '^[[:space:]]*Interface=[[:alnum:]:._-]\+' "$1")
if [[ -z $InterfaceLine ]]; then
exit_error "Profile '$1' does not specify an interface"
fi
mapfile -t AllProfiles < <(list_profiles)
mapfile -t Profiles < <(grep -Fl "$InterfaceLine" "${AllProfiles[@]}")
if (( ${#Profiles[@]} )); then
do_debug sd_call stop "${Profiles[@]}" 2> >(grep -Fv "not loaded" >&2)
do_debug sd_call stop "${Profiles[@]}" 2> >(grep -Fv 'not loaded' >&2)
fi
do_debug sd_call start "$1"
}
......
......@@ -30,7 +30,7 @@ quote_safe() {
if [[ "$1" = \"* ]]; then
printf '""%s"' "$1"
else
printf "%s" "$1"
printf '%s' "$1"
fi
}
......@@ -46,7 +46,7 @@ init_profiles() {
if [[ "$ESSID" = \"\"*\" ]]; then
ESSID=${ESSID:2:-1}
fi
printf "%s" "$ESSID"
printf '%s' "$ESSID"
if [[ "$Description" =~ "Automatically generated" ]]; then
return 2
else
......@@ -105,7 +105,7 @@ ssid_to_profile() {
local i
for i in $(seq 0 $((${#ESSIDS[@]}-1))); do
if [[ "$1" = "${ESSIDS[i]}" ]]; then
printf "%s" "${PROFILES[i]}"
printf '%s' "${PROFILES[i]}"
return 0
fi
done
......@@ -157,7 +157,7 @@ create_profile() {
fi
elif [[ ${#key} -ge 8 && ${#key} -le 63 ]]; then
if is_yes "${OBSCURE:-no}"; then
key="\"$(wpa_passphrase "$1" "$key" | sed -n "s/^[[:space:]]*psk=//p")"
key="\"$(wpa_passphrase "$1" "$key" | sed -n 's/^[[:space:]]*psk=//p')"
else
key=$(quote_safe "$key")
fi
......@@ -172,11 +172,11 @@ Description='Automatically generated profile by wifi-menu'
Interface=$INTERFACE
Connection=wireless
Security=$security
ESSID=$(printf "%q" "$(quote_safe "$1")")
ESSID=$(printf '%q' "$(quote_safe "$1")")
IP=dhcp
${key+Key=$(printf "%q" "$key")}
${key+Key=$(printf '%q' "$key")}
EOF
printf "%s" "$PROFILE"
printf '%s' "$PROFILE"
return 0
}
......@@ -263,7 +263,7 @@ if [[ "$RFKill" && "$(rf_status "$INTERFACE" "$RFKill")" ]]; then
fi
echo -n "Scanning for networks... "
if CONNECTION=$(wpa_call "$INTERFACE" status 2> /dev/null | grep -m 1 "^ssid="); then
if CONNECTION=$(wpa_call "$INTERFACE" status 2> /dev/null | grep -m 1 '^ssid='); then
CONNECTION=$(printf_decode "${CONNECTION#ssid=}")
CONNECTED=yes
fi
......
Markdown is supported
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