summaryrefslogtreecommitdiffstats
path: root/scripts/wifi-menu
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/wifi-menu')
-rwxr-xr-xscripts/wifi-menu73
1 files changed, 38 insertions, 35 deletions
diff --git a/scripts/wifi-menu b/scripts/wifi-menu
index fc21a9b..25ac87e 100755
--- a/scripts/wifi-menu
+++ b/scripts/wifi-menu
@@ -46,12 +46,12 @@ init_profiles()
)
case $? in
2)
- GENERATED[${#GENERATED[@]}]="$profile"
+ GENERATED+=("$profile")
;&
1)
- PROFILES[$i]="$profile"
- ESSIDS[$i]="$essid"
- let i++
+ PROFILES[i]=$profile
+ ESSIDS[i]=$essid
+ (( ++i ))
;;
esac
done
@@ -60,29 +60,29 @@ init_profiles()
# Builds ENTRIES as an argument list for dialog based on scan results in $1.
init_entries()
{
- local i=0 flags security signal ssid
+ local i=0 flags signal ssid
while IFS=$'\t' read signal flags ssid; do
- ENTRIES[$i]="--" # $ssid might look like an option to dialog.
- let i++
- ENTRIES[$i]="$ssid"
- let i++
+ ENTRIES[i++]="--" # $ssid might look like an option to dialog.
+ ENTRIES[i++]=$ssid
if inarray "$ssid" "${ESSIDS[@]}"; then
if inarray "$(ssid_to_profile "$ssid")" "${GENERATED[@]}"; then
- ENTRIES[$i]="+" # Automatically generated
+ ENTRIES[i]="+" # Automatically generated
else
- ENTRIES[$i]="*" # Handmade
+ ENTRIES[i]="*" # Handmade
fi
else
- ENTRIES[$i]="-" # Not present
+ ENTRIES[i]="-" # Not present
fi
if [[ "$ssid" = "$CONNECTION" ]]; then
- ENTRIES[$i]="!" # Currently connected
+ ENTRIES[i]="!" # Currently connected
fi
- security="$(expr match "$flags" ".*\(WPA2\|WPA\|WEP\)")"
- : ${security:="NONE"}
- ENTRIES[$i]+=":${security,,}"
- ENTRIES[$i]+=" :$signal"
- let i++
+ if [[ "$flags" =~ WPA2|WPA|WEP ]]; then
+ ENTRIES[i]+=":${BASH_REMATCH[0],,}"
+ else
+ ENTRIES[i]+=":none"
+ fi
+ ENTRIES[i]+=" :$signal"
+ (( ++i ))
done < "$1"
}
@@ -91,8 +91,8 @@ ssid_to_profile()
{
local i
for i in $(seq 0 $((${#ESSIDS[@]}-1))); do
- if [[ "$1" = "${ESSIDS[$i]}" ]]; then
- printf "%s" "${PROFILES[$i]}"
+ if [[ "$1" = "${ESSIDS[i]}" ]]; then
+ printf "%s" "${PROFILES[i]}"
return 0
fi
done
@@ -105,10 +105,13 @@ create_profile()
local flags key msg security
PROFILE="$INTERFACE-$1"
[[ -f "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu"
- flags="$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2)"
- security="$(expr match "$flags" ".*\(WPA\|WEP\)")"
- : ${security:="NONE"}
- if [[ "$flags" =~ "PSK"|"WEP" ]]; then
+ flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2)
+ if [[ "$flags" =~ WPA|WEP ]]; then
+ security=${BASH_REMATCH[0],,}
+ else
+ security=none
+ fi
+ if [[ "$flags" =~ PSK|WEP ]]; then
msg="Enter $security security key for\n'$1'"
if [[ "$OBSCURE" ]]; then
key=$(wpa_passphrase "$1" "$(dialog --insecure --passwordbox \
@@ -120,13 +123,13 @@ create_profile()
key="KEY='$(dialog --inputbox "$msg" 10 40 --stdout)'"
RETURN=$?
fi
- [[ $RETURN -eq 0 ]] || return $RETURN
+ (( RETURN == 0 )) || return $RETURN
fi
cat << EOF > "$PROFILE_DIR/$PROFILE" || return 4
CONNECTION='wireless'
DESCRIPTION='Automatically generated profile by wifi-menu'
INTERFACE='$INTERFACE'
-SECURITY='${security,,}'
+SECURITY='$security'
ESSID='$1'
IP='dhcp'
$key
@@ -147,12 +150,12 @@ connect_to_ssid()
else
PROFILE=$(create_profile "$1")
RETURN=$?
- [[ $RETURN -eq 0 ]] || return $RETURN
+ (( RETURN == 0 )) || return $RETURN
SPAWNED_PROFILE=1
clear
fi
if ! profile_up "$PROFILE"; then
- if [[ "$SPAWNED_PROFILE" ]]; then
+ if (( SPAWNED_PROFILE )); then
msg=" CONNECTING FAILED
Do you want to keep the generated profile ('$PROFILE')?"
@@ -191,7 +194,7 @@ if [[ $(id -u) -ne 0 ]]; then
exit_stderr "This script needs to be run with root privileges"
fi
-INTERFACE="${1-$WIRELESS_INTERFACE}"
+INTERFACE=${1-$WIRELESS_INTERFACE}
if [[ -z "$INTERFACE" ]]; then
report_err "Missing interface specification"
usage
@@ -200,16 +203,16 @@ fi
cd / # We do not want to spawn anything that can block unmounting
is_interface "$INTERFACE" || exit_fail "No such interface: $INTERFACE"
-if [[ -z "$(ip link show up dev $INTERFACE)" ]]; then
+if [[ -z "$(ip link show up dev "$INTERFACE" 2> /dev/null)" ]]; then
[[ -f "$IFACE_DIR/$INTERFACE" ]] && . "$IFACE_DIR/$INTERFACE"
bring_interface up "$INTERFACE" || exit_fail "Interface unavailable"
SPAWNED_INTERFACE=1
fi
report_try "Scanning for networks"
-CONNECTION=$(expr substr \
- "$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status \
- 2> /dev/null | grep "^ssid=")" 6 32)
+CONNECTION=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status 2> /dev/null \
+ | grep "^ssid=")
+CONNECTION=${CONNECTION#ssid=}
init_profiles "$INTERFACE"
NETWORKS=$(wpa_supplicant_scan_info "$INTERFACE" 3,4,5)
[[ $? -eq 0 ]] && init_entries "$NETWORKS"
@@ -227,7 +230,7 @@ Flags description:
CHOICE=$(dialog --column-separator : --menu "$MSG" 24 50 12 \
"${ENTRIES[@]}" --stdout)
RETURN=$?
- if [[ $RETURN -eq 0 ]]; then
+ if (( RETURN == 0 )); then
connect_to_ssid "$CHOICE"
RETURN=$?
fi
@@ -256,5 +259,5 @@ case $RETURN in
;;
esac
[[ -f "$NETWORKS" ]] && rm -f "$NETWORKS"
-[[ $RETURN -ne 0 && "$SPAWNED_INTERFACE" ]] && bring_interface down "$INTERFACE"
+(( RETURN && SPAWNED_INTERFACE )) && bring_interface down "$INTERFACE"
exit $RETURN