head	1.5;
access;
symbols
	RELENG_9_1_0_RELEASE:1.3.2.1.4.2
	RELENG_9_1:1.3.2.1.0.4
	RELENG_9_1_BP:1.3.2.1
	RELENG_9_0_0_RELEASE:1.3.2.1.2.1
	RELENG_9_0:1.3.2.1.0.2
	RELENG_9_0_BP:1.3.2.1
	RELENG_9:1.3.0.2
	RELENG_9_BP:1.3;
locks; strict;
comment	@# @;


1.5
date	2013.01.28.00.33.16;	author svnexp;	state Exp;
branches;
next	1.4;

1.4
date	2012.11.17.01.54.40;	author svnexp;	state Exp;
branches;
next	1.3;

1.3
date	2011.09.13.21.39.26;	author brueffer;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2011.04.05.03.11.21;	author nwhitehorn;	state Exp;
branches;
next	1.1;

1.1
date	2011.02.18.14.54.34;	author nwhitehorn;	state Exp;
branches;
next	;

1.3.2.1
date	2011.09.23.00.51.37;	author kensmith;	state Exp;
branches
	1.3.2.1.2.1
	1.3.2.1.4.1;
next	1.3.2.2;

1.3.2.2
date	2012.11.17.11.37.43;	author svnexp;	state Exp;
branches;
next	1.3.2.3;

1.3.2.3
date	2013.03.13.14.06.57;	author svnexp;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	2014.03.31.02.01.46;	author svnexp;	state Exp;
branches;
next	;

1.3.2.1.2.1
date	2011.11.11.04.20.22;	author kensmith;	state Exp;
branches;
next	1.3.2.1.2.2;

1.3.2.1.2.2
date	2012.11.17.08.37.39;	author svnexp;	state Exp;
branches;
next	;

1.3.2.1.4.1
date	2012.08.05.23.54.33;	author kensmith;	state Exp;
branches;
next	1.3.2.1.4.2;

1.3.2.1.4.2
date	2012.11.17.08.48.31;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.5
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/245980
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@#!/bin/sh
#-
# Copyright (c) 2011 Nathan Whitehorn
# 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: head/usr.sbin/bsdinstall/scripts/wlanconfig 245980 2013-01-27 14:49:54Z nwhitehorn $

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

wpa_cli scan >>$BSDINSTALL_LOG
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
test ! -z $BSDINSTALL_CONFIGCURRENT && wpa_cli reconfigure >>$BSDINSTALL_LOG

exit 0
@


1.4
log
@Switching exporter and resync
@
text
@d27 1
a27 1
# $FreeBSD: head/usr.sbin/bsdinstall/scripts/wlanconfig 225539 2011-09-13 21:39:26Z brueffer $
d63 1
a63 1
if [ -z $NETWORKS ]; then
@


1.3
log
@SVN rev 225539 on 2011-09-13 21:39:26Z by brueffer

Allow WPA PSKs up to 63 characters, the max length according to
wpa_supplicant.conf(5).  Up to now, the PSK was truncated
to 15 characters (the length of the input field).

PR:		159559
Submitted by:	Gavin Chappell <gavin.chappell@@gmail.com>
Approved by:	re (kib)
@
text
@d27 1
a27 1
# $FreeBSD$
@


1.3.2.1
log
@SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.3.2.2
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242902
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242902 | dteske | 2012-11-11 23:29:45 +0000 (Sun, 11 Nov 2012) | 10 lines
## SVN ##
## SVN ## Fix a regression introduced by SVN r211417 that saw the breakage of a feature
## SVN ## documented in usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## Reviewed by:	adrian (co-mentor)
## SVN ## Approved by:	adrian (co-mentor)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d27 1
a27 1
# $FreeBSD: stable/9/usr.sbin/bsdinstall/scripts/wlanconfig 225539 2011-09-13 21:39:26Z brueffer $
@


1.3.2.3
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/248240
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d27 1
a27 1
# $FreeBSD: stable/9/usr.sbin/bsdinstall/scripts/wlanconfig 248240 2013-03-13 13:50:50Z nwhitehorn $
d63 1
a63 1
if [ -z "$NETWORKS" ]; then
@


1.3.2.4
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/263956
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a3 1
# Copyright (c) 2013 Devin Teske
d27 1
a27 8
# $FreeBSD: stable/9/usr.sbin/bsdinstall/scripts/wlanconfig 263956 2014-03-31 01:04:40Z dteske $
#
############################################################ INCLUDES

BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1

############################################################ MAIN
d53 1
a53 2
output=$( wpa_cli scan 2>&1 )
f_dprintf "%s" "$output"
a103 23
elif echo $ENCRYPTION | grep -q EAP; then
	exec 3>&1
	USERPASS=`dialog --insecure --backtitle "FreeBSD Installer" \
	    --title "WPA-Enterprise Setup" --mixedform "" 0 0 0 \
		"SSID" 1 0 "$NETWORK" 1 12 0 0 2 \
		"Username" 2 0 "" 2 12 25 63 0 \
		"Password" 3 0 "" 3 12 25 63 1 \
		2>&1 1>&3` \
	|| exec $0 $@@
	exec 3>&-
echo "network={
	ssid=\"$NETWORK\"
	key_mgmt=WPA-EAP" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
echo "$USERPASS" | awk '
{
	if (NR == 1) {
		printf "	identity=\"%s\"\n", $1;
	} else if (NR == 2) {
		printf "	password=\"%s\"\n", $1;
	}
}' >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
echo "	priority=5
}" >> $BSDINSTALL_TMPETC/wpa_supplicant.conf
d105 1
d130 1
a130 1
	priority=0
d135 1
a135 4
if [ "$BSDINSTALL_CONFIGCURRENT" ]; then
	output=$( wpa_cli reconfigure 2>&1 )
	f_dprintf "%s" "$output"
fi
a137 4

################################################################################
# END
################################################################################
@


1.3.2.1.4.1
log
@SVN rev 239080 on 2012-08-05 23:54:33Z by kensmith

Copy stable/9 to releng/9.1 as part of the 9.1-RELEASE release process.

Approved by:	re (implicit)
@
text
@@


1.3.2.1.4.2
log
@Switch importer
@
text
@d27 1
a27 1
# $FreeBSD: releng/9.1/usr.sbin/bsdinstall/scripts/wlanconfig 225539 2011-09-13 21:39:26Z brueffer $
@


1.3.2.1.2.1
log
@SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)
@
text
@@


1.3.2.1.2.2
log
@Switch importer
@
text
@d27 1
a27 1
# $FreeBSD: releng/9.0/usr.sbin/bsdinstall/scripts/wlanconfig 225539 2011-09-13 21:39:26Z brueffer $
@


1.2
log
@SVN rev 220351 on 2011-04-05 03:11:21Z by nwhitehorn

Check correctly for whether there are any available wireless networks. This
was tested on a train in the middle of an upstate New York swamp.
@
text
@d95 1
a95 1
		"Password" 2 0 "" 2 12 15 0 1 \
@


1.1
log
@SVN rev 218799 on 2011-02-18 14:54:34Z by nwhitehorn

Import bsdinstall. This is meant to be (eventually in conjunction with
pc-sysinstall) a replacement for sysinstall in the 9.0 release and beyond.
Currently supported platforms are sparc64, pc98, i386, amd64, powerpc, and
powerpc64. Integration into the build system will occur in the coming
weeks.

Merging with pc-sysinstall will use this code as a frontend, while
temporarily retaining the interactive partition editor here. This work
will be done in parallel with improvements on this code and release
integration.

Thanks to all who have provided testing and comments!
@
text
@d63 1
a63 1
if [ -z $SCAN_RESULTS ]; then
@

