Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bsdinstall/scripts/wlanconfig
#!/bin/sh | #!/bin/sh | ||||
#- | #- | ||||
# Copyright (c) 2011 Nathan Whitehorn | # Copyright (c) 2011 Nathan Whitehorn | ||||
# Copyright (c) 2013-2016 Devin Teske | # Copyright (c) 2013-2020 Devin Teske | ||||
# All rights reserved. | # All rights reserved. | ||||
# | # | ||||
# Redistribution and use in source and binary forms, with or without | # Redistribution and use in source and binary forms, with or without | ||||
# modification, are permitted provided that the following conditions | # modification, are permitted provided that the following conditions | ||||
# are met: | # are met: | ||||
# 1. Redistributions of source code must retain the above copyright | # 1. Redistributions of source code must retain the above copyright | ||||
# notice, this list of conditions and the following disclaimer. | # notice, this list of conditions and the following disclaimer. | ||||
# 2. Redistributions in binary form must reproduce the above copyright | # 2. Redistributions in binary form must reproduce the above copyright | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | country_set() | ||||
f_eval_catch -dk error_str wlanconfig ifconfig "ifconfig %s %s" \ | f_eval_catch -dk error_str wlanconfig ifconfig "ifconfig %s %s" \ | ||||
"$WLAN_IFACE" "$ifconfig_args" | "$WLAN_IFACE" "$ifconfig_args" | ||||
error_str="${error_str#ifconfig: }" | error_str="${error_str#ifconfig: }" | ||||
# Restart wpa_supplicant(8) (should not fail). | # Restart wpa_supplicant(8) (should not fail). | ||||
[ "$iface_up" ] && f_eval_catch -d wlanconfig wpa_supplicant \ | [ "$iface_up" ] && f_eval_catch -d wlanconfig wpa_supplicant \ | ||||
'wpa_supplicant -B -i "%s" -c "%s/wpa_supplicant.conf"' \ | 'wpa_supplicant -B -i "%s" -c "%s/wpa_supplicant.conf"' \ | ||||
"$WLAN_IFACE" "$BSDINSTALL_TMPETC" | "$WLAN_IFACE" "$BSDINSTALL_TMPETC" | ||||
if [ "$error_str" ]; then | if [ "$error_str" ]; then | ||||
$DIALOG \ | $DIALOG --title "$msg_error" \ | ||||
--title "$msg_error" \ | |||||
--backtitle "$DIALOG_BACKTITLE" \ | --backtitle "$DIALOG_BACKTITLE" \ | ||||
--yes-label Change \ | --yes-label Change \ | ||||
--no-label Ignore \ | --no-label Ignore \ | ||||
--yesno \ | --yesno \ | ||||
"Error while applying chosen settings ($error_str)" \ | "Error while applying chosen settings ($error_str)" \ | ||||
0 0 || return $SUCCESS # Skip | 0 0 || return $SUCCESS # Skip | ||||
return $FAILURE # Restart | return $FAILURE # Restart | ||||
else | else | ||||
awk 'sub(/^\t\t/,"")||1' \ | cat > "$BSDINSTALL_TMPETC/rc.conf.net.wlan" <<-EOF | ||||
> "$BSDINSTALL_TMPETC/rc.conf.net.wlan" <<-EOF | |||||
create_args_$WLAN_IFACE="$ifconfig_args" | create_args_$WLAN_IFACE="$ifconfig_args" | ||||
EOF | EOF | ||||
fi | fi | ||||
return $SUCCESS | return $SUCCESS | ||||
} | } | ||||
dialog_country_select() | dialog_country_select() | ||||
Show All 13 Lines | sub(/.*domains:/, ""), /[^[:alnum:][[:space:]]/ { | ||||
for (i = 1; i <= n; i++) | for (i = 1; i <= n; i++) | ||||
printf "'\''%s'\'' '\'\''", domains[i] | printf "'\''%s'\'' '\'\''", domains[i] | ||||
} | } | ||||
' | sort ) | ' | sort ) | ||||
countries=$( echo "$input" | awk ' | countries=$( echo "$input" | awk ' | ||||
sub(/Country codes:/, ""), sub(/Regulatory.*/, "") { | sub(/Country codes:/, ""), sub(/Regulatory.*/, "") { | ||||
while (match($0, /[[:upper:]][[:upper:][:digit:]] /)) { | while (match($0, /[[:upper:]][[:upper:][:digit:]] /)) { | ||||
country = substr($0, RSTART) | country = substr($0, RSTART) | ||||
sub(/ [[:upper:]][[:upper:][:digit:]].*/, "", country) | sub(/ [[:upper:]][[:upper:][:digit:]].*/, "", | ||||
country) | |||||
code = substr(country, 1, 2) | code = substr(country, 1, 2) | ||||
desc = substr(country, 4) | desc = substr(country, 4) | ||||
sub(/[[:space:]]*$/, "", desc) | sub(/[[:space:]]*$/, "", desc) | ||||
printf "'\''%s'\'' '\''%s'\''\n", code, desc | printf "'\''%s'\'' '\''%s'\''\n", code, desc | ||||
$0 = substr($0, RSTART + RLENGTH) | $0 = substr($0, RSTART + RLENGTH) | ||||
} | } | ||||
} | } | ||||
' | sort ) | ' | sort ) | ||||
Show All 35 Lines | dialog_country_select() | ||||
country_set "$regdomain" "$country" | country_set "$regdomain" "$country" | ||||
} | } | ||||
############################################################ MAIN | ############################################################ MAIN | ||||
: > "$BSDINSTALL_TMPETC/wpa_supplicant.conf" | : > "$BSDINSTALL_TMPETC/wpa_supplicant.conf" | ||||
chmod 0600 "$BSDINSTALL_TMPETC/wpa_supplicant.conf" | chmod 0600 "$BSDINSTALL_TMPETC/wpa_supplicant.conf" | ||||
cat >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" << EOF | cat >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF | ||||
ctrl_interface=/var/run/wpa_supplicant | ctrl_interface=/var/run/wpa_supplicant | ||||
eapol_version=2 | eapol_version=2 | ||||
ap_scan=1 | ap_scan=1 | ||||
fast_reauth=1 | fast_reauth=1 | ||||
EOF | EOF | ||||
# | # | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | PASS=$( $DIALOG \ | ||||
--backtitle "$DIALOG_BACKTITLE" \ | --backtitle "$DIALOG_BACKTITLE" \ | ||||
--insecure \ | --insecure \ | ||||
--mixedform "" \ | --mixedform "" \ | ||||
0 0 0 \ | 0 0 0 \ | ||||
"SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ | "SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ | ||||
"Password" 2 0 "" 2 12 15 63 1 \ | "Password" 2 0 "" 2 12 15 63 1 \ | ||||
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD | 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD | ||||
) || exec "$0" "$@" | ) || exec "$0" "$@" | ||||
awk 'sub(/^\t/,"")||1' \ | awk 'sub(/^\\/,"")||1' \ | ||||
>> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF | >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF | ||||
network={ | network={ | ||||
ssid="$NETWORK" | \ ssid="$NETWORK" | ||||
scan_ssid=$SCANSSID | \ scan_ssid=$SCANSSID | ||||
psk="$PASS" | \ psk="$PASS" | ||||
priority=5 | \ priority=5 | ||||
} | } | ||||
EOF | EOF | ||||
elif echo "$ENCRYPTION" | grep -q EAP; then | elif echo "$ENCRYPTION" | grep -q EAP; then | ||||
USERPASS=$( $DIALOG \ | USERPASS=$( $DIALOG \ | ||||
--title "WPA-Enterprise Setup" \ | --title "WPA-Enterprise Setup" \ | ||||
--backtitle "$DIALOG_BACKTITLE" \ | --backtitle "$DIALOG_BACKTITLE" \ | ||||
--insecure \ | --insecure \ | ||||
--mixedform "" \ | --mixedform "" \ | ||||
0 0 0 \ | 0 0 0 \ | ||||
"SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ | "SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ | ||||
"Username" 2 0 "" 2 12 25 63 0 \ | "Username" 2 0 "" 2 12 25 63 0 \ | ||||
"Password" 3 0 "" 3 12 25 63 1 \ | "Password" 3 0 "" 3 12 25 63 1 \ | ||||
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD | 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD | ||||
) || exec "$0" "$@" | ) || exec "$0" "$@" | ||||
awk 'sub(/^\t/,"")||1' \ | awk 'sub(/^\\/,"")||1' \ | ||||
>> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF | >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF | ||||
network={ | network={ | ||||
ssid="$NETWORK" | \ ssid="$NETWORK" | ||||
scan_ssid=$SCANSSID | \ scan_ssid=$SCANSSID | ||||
key_mgmt=WPA-EAP$( | \ key_mgmt=WPA-EAP$( | ||||
echo "$USERPASS" | awk ' | echo "$USERPASS" | awk ' | ||||
NR == 1 { printf "\n\t\tidentity=\"%s\"", $1 } | NR == 1 { printf "\n\tidentity=\"%s\"", $1 } | ||||
NR == 2 { printf "\n\t\tpassword=\"%s\"", $1 } | NR == 2 { printf "\n\tpassword=\"%s\"", $1 } | ||||
' ) | ' ) | ||||
priority=5 | \ priority=5 | ||||
} | } | ||||
EOF | EOF | ||||
elif echo "$ENCRYPTION" | grep -q WEP; then | elif echo "$ENCRYPTION" | grep -q WEP; then | ||||
WEPKEY=$( $DIALOG \ | WEPKEY=$( $DIALOG \ | ||||
--title "WEP Setup" \ | --title "WEP Setup" \ | ||||
--backtitle "$DIALOG_BACKTITLE" \ | --backtitle "$DIALOG_BACKTITLE" \ | ||||
--insecure \ | --insecure \ | ||||
--mixedform "" \ | --mixedform "" \ | ||||
0 0 0 \ | 0 0 0 \ | ||||
"SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ | "SSID" 1 0 "$NETWORK" 1 12 0 0 2 \ | ||||
"WEP Key 0" 2 0 "" 2 12 15 0 1 \ | "WEP Key 0" 2 0 "" 2 12 15 0 1 \ | ||||
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD | 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD | ||||
) || exec "$0" "$@" | ) || exec "$0" "$@" | ||||
awk 'sub(/^\t/,"")||1' \ | awk 'sub(/^\\/,"")||1' \ | ||||
>> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF | >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF | ||||
network={ | network={ | ||||
ssid="$NETWORK" | \ ssid="$NETWORK" | ||||
scan_ssid=$SCANSSID | \ scan_ssid=$SCANSSID | ||||
key_mgmt=NONE | \ key_mgmt=NONE | ||||
wep_key0="$WEPKEY" | \ wep_key0="$WEPKEY" | ||||
wep_tx_keyidx=0 | \ wep_tx_keyidx=0 | ||||
priority=5 | \ priority=5 | ||||
} | } | ||||
EOF | EOF | ||||
else # Open | else # Open | ||||
awk 'sub(/^\t/,"")||1' \ | awk 'sub(/^\\/,"")||1' \ | ||||
>> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF | >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<-EOF | ||||
network={ | network={ | ||||
ssid="$NETWORK" | \ ssid="$NETWORK" | ||||
scan_ssid=$SCANSSID | \ scan_ssid=$SCANSSID | ||||
key_mgmt=NONE | \ key_mgmt=NONE | ||||
priority=5 | \ priority=5 | ||||
} | } | ||||
EOF | EOF | ||||
fi | fi | ||||
# Connect to any open networks policy | # Connect to any open networks policy | ||||
cat >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" << EOF | cat >> "$BSDINSTALL_TMPETC/wpa_supplicant.conf" <<EOF | ||||
network={ | network={ | ||||
priority=0 | priority=0 | ||||
key_mgmt=NONE | key_mgmt=NONE | ||||
} | } | ||||
EOF | EOF | ||||
# Bring up new network | # Bring up new network | ||||
[ "$BSDINSTALL_CONFIGCURRENT" ] && | [ "$BSDINSTALL_CONFIGCURRENT" ] && | ||||
f_eval_catch -d wlanconfig wpa_cli "wpa_cli reconfigure" | f_eval_catch -d wlanconfig wpa_cli "wpa_cli reconfigure" | ||||
exit $SUCCESS | exit $SUCCESS | ||||
################################################################################ | ################################################################################ | ||||
# END | # END | ||||
################################################################################ | ################################################################################ |