From owner-svn-src-user@FreeBSD.ORG Sat Feb 5 16:03:08 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CC0731065670; Sat, 5 Feb 2011 16:03:08 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BA9BB8FC13; Sat, 5 Feb 2011 16:03:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p15G38aw032962; Sat, 5 Feb 2011 16:03:08 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p15G38WN032958; Sat, 5 Feb 2011 16:03:08 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201102051603.p15G38WN032958@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 5 Feb 2011 16:03:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218330 - user/nwhitehorn/bsdinstall/scripts X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Feb 2011 16:03:08 -0000 Author: nwhitehorn Date: Sat Feb 5 16:03:08 2011 New Revision: 218330 URL: http://svn.freebsd.org/changeset/base/218330 Log: Add an interface for wireless configuration. This provides a menu of available wireless networks and lets the user set up WEP or WPA. Added: user/nwhitehorn/bsdinstall/scripts/wlanconfig (contents, props changed) Modified: user/nwhitehorn/bsdinstall/scripts/Makefile user/nwhitehorn/bsdinstall/scripts/netconfig Modified: user/nwhitehorn/bsdinstall/scripts/Makefile ============================================================================== --- user/nwhitehorn/bsdinstall/scripts/Makefile Sat Feb 5 15:37:10 2011 (r218329) +++ user/nwhitehorn/bsdinstall/scripts/Makefile Sat Feb 5 16:03:08 2011 (r218330) @@ -1,7 +1,7 @@ # $FreeBSD $ SCRIPTS= auto adduser config hostname jail keymap mount netconfig rootpass \ - services time umount + services time umount wlanconfig BINDIR= /usr/libexec/bsdinstall NO_MAN= true Modified: user/nwhitehorn/bsdinstall/scripts/netconfig ============================================================================== --- user/nwhitehorn/bsdinstall/scripts/netconfig Sat Feb 5 15:37:10 2011 (r218329) +++ user/nwhitehorn/bsdinstall/scripts/netconfig Sat Feb 5 16:03:08 2011 (r218330) @@ -25,9 +25,24 @@ INTERFACE=`echo $DIALOG_TAGS | xargs dia if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi exec 3>&- +# Do a dirty check to see if this a wireless interface -- there should be a +# better way +IFCONFIG_PREFIX="" +if ifconfig $INTERFACE | grep -q 'media: IEEE 802.11 Wireless'; then + NEXT_WLAN_IFACE=wlan0 # XXX + echo wlans_$INTERFACE=\"$NEXT_WLAN_IFACE\" >> $BSDINSTALL_TMPETC/rc.conf.net + IFCONFIG_PREFIX="WPA " + if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE + ifconfig $NEXT_WLAN_IFACE up + fi + bsdinstall wlanconfig $NEXT_WLAN_IFACE || exec $0 + INTERFACE="$NEXT_WLAN_IFACE" +fi + dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 if [ $? -eq $DIALOG_OK ]; then - echo ifconfig_$INTERFACE=\"DHCP\" >> $BSDINSTALL_TMPETC/rc.conf.net + echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/rc.conf.net if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0 @@ -57,8 +72,8 @@ if [ $? -eq $DIALOG_CANCEL ]; then exec exec 3>&- echo $INTERFACE $IF_CONFIG | - awk '{ - printf("ifconfig_%s=\"%s netmask %s\"\n", $1, $2, $3); + awk -v prefix="$IFCONFIG_PREFIX" '{ + printf("ifconfig_%s=\"%s%s netmask %s\"\n", $1, prefix, $2, $3); printf("defaultrouter=\"%s\"\n", $4); }' >> $BSDINSTALL_TMPETC/rc.conf.net Added: user/nwhitehorn/bsdinstall/scripts/wlanconfig ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/nwhitehorn/bsdinstall/scripts/wlanconfig Sat Feb 5 16:03:08 2011 (r218330) @@ -0,0 +1,104 @@ +#!/bin/sh + +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` + +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 0 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