freebsd-skq/usr.sbin/bsdinstall/scripts/wlanconfig
Devin Teske bc4a673f89 A series of changes tested together as a whole:
+ Add a `-D FILE" command-line option for overriding the path to the
  bsdinstall log file (BSDINSTALL_LOG env var).
+ Document new `-D FILE' in the man page for bsdinstall.
+ If FILE in `-D FILE' begins with a +, debug output goes to stdout
  (interleaved between dialog(1) invocations/output) as well as to FILE
  (minus the leading + of course).
+ If BSDINSTALL_LOG cannot be written, then debugging is disabled (except in
  the case of a leading + in the pathname, wherein debug will still be
  printed to stdout).
+ Update source code formatting style.
+ Fix a dangling participle ("Begun ..." -> "Began ...")
+ Rewrite the docsinstall script (was necessary to abate direct dependency
  on BSDINSTALL_LOG (instead, use fault-tolerant bsdconfig framework which
  displays appropriate errors for package management).
NB: docsinstall is still using pkg(8) after this change.
+ Add additional debug output for dhclient/rtsol/wpa_cliscan
+ Display script errors in a textbox rather than just on stdout
+ Update many coments.
+ Add new f_show_err() API call (like f_show_msg but changes the dialog
  title to "Error")(see bsdconfig's `common.subr').
+ Add new f_eval_catch() API call for executing a command via eval but not
  before logging the command to debug. Several example cases documented in
  API header for function in bsdconfig's `common.subr'.
+ Fix dialog auto-sizing when launched as an rvalue to a pipe for indirected
  scripts (previously would default to 24x80 sizing in this case, now it can
  autosize to full size even when in a pipe chain).
+ Fix bug in f_snprintf if $format argument began with "-"; printf would
  misinterpret as a flag. (this is in bsdcofig's `strings.subr').
+ Add accompanying f_sprintf() and f_vsprintf() to go along with already
  existing f_snprintf() and f_vsnprintf() (see bsdconfig's `strings.subr').
+ Remove some unnecessary default ZFS datasets from the automatic "zfsboot"
  script. Such as: /usr/ports/distfiles /usr/ports/packages /usr/obj /var/db
  /var/empty /var/mail and /var/run (these can all be created as-needed once
  the system is installed).
+ Remove setuid=off for /usr/home (as discussed from last round of CFT).
+ Fix some i18n string violations in "zfsboot".
+ Bolster debugging output in "zfsboot".
+ Fix some string quoting issues in "zfsboot".
+ Fix some variable scope issues in "zfsboot".
+ Change "Create" to "Install" in "zfsboot" main menu.
+ Increase error checking in "zfsboot" (type-check arguments and such).
+ Add call to "graid destroy" killing automatic metadata (part of the series
  of pedantic destructions we do when bootstrapping a new/naked disk).
+ Make judicious use of new f_eval_catch() in "zfsboot".
+ Fixup some variable names for consistency (zfsboot).
+ Fix an underride syntax parameter expansion folly (zfsboot).
+ Confirm layout if not explicitly chosen when blindly proceeding (no
  longer have to touch anything on the ZFS menu if it scares you, just
  choose the omnibus "Install" option at the top and you'll be prompted to
  select vdev type and disks in the layout confirmation dialog).
+ Change numbered menu items to alphabetic for more efficient navigation.
+ Consolidate vdev selection and disk selection into a single stateful
  menu which performs validation and allows backing out to each previous
  menu as you go deeper.
+ Redesign the ``Last Chance'' dialog (still using the same colors, but
  make it conform to a tolerable width and make disks appear in a block-
  quote style indented region).
+ Fix a bug wherein we used the a lowercase variable name by accident
  (actual variable name declared as all-uppercase) at the time of
  initializing fstab(5) (not believed to cause any issues though).
+ Update the geli setup infobox for each provider being initialized
  (not just at the onset -- since each ``geli init'' causes kernel messages
  to push our infobox off-screen).

Reviewed by:	Allan Jude <freebsd@allanjude.com>
Discussed on:	-current
MFC after:	3 days
2013-11-08 09:57:03 +00:00

154 lines
5.0 KiB
Bash
Executable File

#!/bin/sh
#-
# Copyright (c) 2011 Nathan Whitehorn
# Copyright (c) 2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
############################################################ INCLUDES
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
############################################################ MAIN
echo -n > $BSDINSTALL_TMPETC/wpa_supplicant.conf
chmod 0600 $BSDINSTALL_TMPETC/wpa_supplicant.conf
echo "ctrl_interface=/var/run/wpa_supplicant" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
echo "eapol_version=2" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
echo "ap_scan=1" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
echo "fast_reauth=1" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
echo >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
# Try to reach wpa_supplicant. If it isn't running and we can modify the
# existing system, start it. Otherwise, fail.
(wpa_cli ping >/dev/null 2>/dev/null || ([ ! -z $BSDINSTALL_CONFIGCURRENT ] && \
wpa_supplicant -B -i $1 -c $BSDINSTALL_TMPETC/wpa_supplicant.conf)) || \
(dialog --backtitle "FreeBSD Installer" --title "Error" --msgbox \
"Could not start wpa_supplicant!" 0 0; exit 1) || exit 1
# See if we succeeded
wpa_cli ping >/dev/null 2>/dev/null
if [ $? -ne 0 -a -z $BSDINSTALL_CONFIGCURRENT ]; then
dialog --backtitle "FreeBSD Installer" --title "Error" --msgbox \
"Wireless cannot be configured without making changes to the local system!" \ 0 0
exit 1
fi
output=$( wpa_cli scan 2>&1 )
f_dprintf "%s" "$output"
dialog --backtitle "FreeBSD Installer" --title "Scanning" --ok-label "Skip" \
--pause "Waiting 5 seconds to scan for wireless networks..." \
9 40 5 || exit 1
SCAN_RESULTS=`wpa_cli scan_results`
NETWORKS=`echo "$SCAN_RESULTS" | awk -F '\t' \
'/..:..:..:..:..:../ {if (length($5) > 0) printf("\"%s\"\t%s\n", $5, $4);}' |
sort | uniq`
if [ -z "$NETWORKS" ]; then
dialog --backtitle "FreeBSD Installer" --title "Error" \
--yesno "No wireless networks were found. Rescan?" 0 0 && \
exec $0 $@
exit 1
fi
exec 3>&1
NETWORK=`sh -c "dialog --extra-button --extra-label \"Rescan\" \
--backtitle \"FreeBSD Installer\" --title \"Network Selection\" --menu \
\"Select a wireless network to connect to.\" 0 0 0 \
$(echo $NETWORKS | tr '\n' ' ')" 2>&1 1>&3`
case $? in
0) # OK
;;
1) # Cancel
exit 1
;;
3) # Rescan
exec $0 $@
;;
esac
exec 3>&-
ENCRYPTION=`echo "$NETWORKS" | awk -F '\t' \
"/^\"$NETWORK\"\t/ {printf(\"%s\n\", \\\$2 );}"`
if echo $ENCRYPTION | grep -q 'PSK'; then
exec 3>&1
PASS=`dialog --insecure --backtitle "FreeBSD Installer" \
--title "WPA Setup" --mixedform "" 0 0 0 \
"SSID" 1 0 "$NETWORK" 1 12 0 0 2 \
"Password" 2 0 "" 2 12 15 63 1 \
2>&1 1>&3` \
|| exec $0 $@
exec 3>&-
echo "network={
ssid=\"$NETWORK\"
psk=\"$PASS\"
priority=5
}" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
elif echo $ENCRYPTION | grep -q WEP; then
echo FOO
exec 3>&1
WEPKEY=`dialog --insecure --backtitle "FreeBSD Installer" \
--title "WEP Setup" --mixedform "" 0 0 0 \
"SSID" 1 0 "$NETWORK" 1 12 0 0 2 \
"WEP Key 0" 2 0 "" 2 12 15 0 1 \
2>&1 1>&3` \
|| exec $0 $@
echo "network={
ssid=\"$NETWORK\"
key_mgmt=NONE
wep_key0=\"$WEPKEY\"
wep_tx_keyidx=0
priority=5
}" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
else # Open
echo "network={
ssid=\"$NETWORK\"
key_mgmt=NONE
priority=5
}" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
fi
# Connect to any open networks policy
echo "network={
priority=5
key_mgmt=NONE
}" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
# Bring up new network
if [ "$BSDINSTALL_CONFIGCURRENT" ]; then
output=$( wpa_cli reconfigure 2>&1 )
f_dprintf "%s" "$output"
fi
exit 0
################################################################################
# END
################################################################################