devices revision 252987
133965Sjdp#!/bin/sh 278828Sobrien#- 378828Sobrien# Copyright (c) 2006-2013 Devin Teske 433965Sjdp# All rights reserved. 533965Sjdp# 633965Sjdp# Redistribution and use in source and binary forms, with or without 733965Sjdp# modification, are permitted provided that the following conditions 833965Sjdp# are met: 933965Sjdp# 1. Redistributions of source code must retain the above copyright 1033965Sjdp# notice, this list of conditions and the following disclaimer. 1133965Sjdp# 2. Redistributions in binary form must reproduce the above copyright 1233965Sjdp# notice, this list of conditions and the following disclaimer in the 1333965Sjdp# documentation and/or other materials provided with the distribution. 1433965Sjdp# 1533965Sjdp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1633965Sjdp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1733965Sjdp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1833965Sjdp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1933965Sjdp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2033965Sjdp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2133965Sjdp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2233965Sjdp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2333965Sjdp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2433965Sjdp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2533965Sjdp# SUCH DAMAGE. 2633965Sjdp# 2760484Sobrien# $FreeBSD: head/usr.sbin/bsdconfig/networking/devices 252987 2013-07-07 18:51:44Z dteske $ 2860484Sobrien# 2933965Sjdp############################################################ INCLUDES 3033965Sjdp 3133965SjdpBSDCFG_SHARE="/usr/share/bsdconfig" 3233965Sjdp. $BSDCFG_SHARE/common.subr || exit 1 3333965Sjdpf_dprintf "%s: loading includes..." "$0" 3433965Sjdpf_include $BSDCFG_SHARE/dialog.subr 3533965Sjdpf_include $BSDCFG_SHARE/mustberoot.subr 3633965Sjdpf_include $BSDCFG_SHARE/sysrc.subr 37130561Sobrienf_include $BSDCFG_SHARE/media/tcpip.subr 3833965Sjdpf_include $BSDCFG_SHARE/networking/device.subr 3933965Sjdpf_include $BSDCFG_SHARE/networking/ipaddr.subr 4033965Sjdpf_include $BSDCFG_SHARE/networking/media.subr 41130561Sobrienf_include $BSDCFG_SHARE/networking/netmask.subr 4233965Sjdp 4333965SjdpBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" 4433965Sjdpf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 45130561Sobrien 4633965Sjdpipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 4733965Sjdp[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 48130561Sobrien 4933965Sjdp############################################################ MAIN 5033965Sjdp 5133965Sjdp# Incorporate rc-file if it exists 5233965Sjdp[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 5333965Sjdp 5433965Sjdp# 5533965Sjdp# Process command-line options 56130561Sobrien# 5733965Sjdpwhile getopts h$GETOPTS_STDARGS flag; do 5833965Sjdp case "$flag" in 59130561Sobrien h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; 60130561Sobrien esac 61130561Sobriendone 62130561Sobrienshift $(( $OPTIND - 1 )) 63130561Sobrien 64130561Sobrien# 65130561Sobrien# Initialize 66130561Sobrien# 6733965Sjdpf_dialog_title "$msg_networking_devices" 6833965Sjdpf_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 69130561Sobrienf_mustberoot_init 70130561Sobrien 7133965Sjdp# 7233965Sjdp# Launch application main menu 73130561Sobrien# 74130561Sobriendefaultitem= 75130561Sobrienwhile :; do 76130561Sobrien f_dialog_menu_netdev "$defaultitem" || break 77130561Sobrien f_dialog_menutag_fetch interface 78130561Sobrien defaultitem="$interface" 79130561Sobrien 80130561Sobrien # 81130561Sobrien # dialog_menu_netdev adds an asterisk (*) to the right of the 8233965Sjdp # device name if the interface is active. Remove the asterisk 8333965Sjdp # from the device name if present. 84130561Sobrien # 85130561Sobrien case "$interface" in 8633965Sjdp *\*) interface="${interface%?}" ;; 8733965Sjdp esac 88130561Sobrien 8933965Sjdp # 9033965Sjdp # Obtain initial interface settings to be configured. These will be 9133965Sjdp # passed to the f_dialog_menu_netdev_edit function-call below which 9233965Sjdp # will block until the user has either cancelled or finished editing 93130561Sobrien # the values. 9433965Sjdp # 9533965Sjdp # First, attempt to read stored configuration from rc.conf(5) and 9633965Sjdp # fallback to reading the active configuration if not configured in 9733965Sjdp # the rc.conf(5) file(s). 98130561Sobrien # 9933965Sjdp dhcp= 10033965Sjdp _ipaddr= 101130561Sobrien _netmask= 10233965Sjdp _ifconfig=$( f_sysrc_get ifconfig_$interface ) 10360484Sobrien if [ "$_ifconfig" ]; then 104130561Sobrien # If DHCP, get IP address/netmask later from ifconfig(8) 10533965Sjdp glob="[Dd][Hh][Cc][Pp]" 10660484Sobrien case "$_ifconfig" in 10760484Sobrien $glob) dhcp=1 ;; 10860484Sobrien [Ss][Yy][Nn][Cc]$glob) dhcp=1 ;; 109130561Sobrien [Nn][Oo][Ss][Yy][Nn][Cc]$glob) dhcp=1 ;; 11060484Sobrien *) 11133965Sjdp # 112 # Get IP address/netmask from rc.conf(5) configuration 113 # 114 dhcp= 115 eval "$( 116 exec 2> /dev/null 117 set -- $_ifconfig 118 while [ $# -gt 0 ]; do 119 case "$1" in 120 inet) 121 shift 1 122 echo "_ipaddr='$1'" 123 ;; 124 netmask) 125 shift 1 126 echo "_netmask='$1'" 127 ;; 128 esac 129 shift 1 130 done 131 )" 132 ;; 133 esac 134 fi 135 136 # 137 # Fill in IP address/netmask from active settings if no 138 # configuration could be extrapolated from rc.conf(5) 139 # 140 [ "$_ipaddr" ] || _ipaddr=$( f_ifconfig_inet $interface ) 141 [ "$_netmask" ] || _netmask=$( f_ifconfig_netmask $interface ) 142 143 # Get the extra options (this always comes from rc.conf(5)) 144 _options=$( f_ifconfig_options $interface ) 145 146 # Block on user-configuration of the probed settings 147 f_dialog_menu_netdev_edit \ 148 "$interface" "$_ipaddr" "$_netmask" "$_options" $dhcp 149 150 # Return to root menu if above returns success 151 [ $? -eq $SUCCESS ] && break 152done 153 154exit $SUCCESS 155 156################################################################################ 157# END 158################################################################################ 159