1238438Sdteske#!/bin/sh 2238438Sdteske#- 3247280Sdteske# Copyright (c) 2006-2013 Devin Teske 4252980Sdteske# All rights reserved. 5238438Sdteske# 6238438Sdteske# Redistribution and use in source and binary forms, with or without 7238438Sdteske# modification, are permitted provided that the following conditions 8238438Sdteske# are met: 9238438Sdteske# 1. Redistributions of source code must retain the above copyright 10238438Sdteske# notice, this list of conditions and the following disclaimer. 11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12238438Sdteske# notice, this list of conditions and the following disclaimer in the 13238438Sdteske# documentation and/or other materials provided with the distribution. 14238438Sdteske# 15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16252987Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18238438Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20252987Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25238438Sdteske# SUCH DAMAGE. 26238438Sdteske# 27238438Sdteske# $FreeBSD$ 28238438Sdteske# 29238438Sdteske############################################################ INCLUDES 30238438Sdteske 31258458Sdteske# Prevent device.subr (included indirectly) from auto scanning; this will be 32258458Sdteske# performed indirectly later via f_dialog_menu_netdev() -- but only after we've 33258458Sdteske# successfully completed f_mustberoot_init(). 34258458Sdteske# 35258458SdteskeDEVICE_SELF_SCAN_ALL=NO 36258458Sdteske 37240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 38240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1 39244675Sdteskef_dprintf "%s: loading includes..." "$0" 40240684Sdteskef_include $BSDCFG_SHARE/dialog.subr 41240684Sdteskef_include $BSDCFG_SHARE/mustberoot.subr 42240684Sdteskef_include $BSDCFG_SHARE/sysrc.subr 43247280Sdteskef_include $BSDCFG_SHARE/media/tcpip.subr 44240684Sdteskef_include $BSDCFG_SHARE/networking/device.subr 45240684Sdteskef_include $BSDCFG_SHARE/networking/ipaddr.subr 46240684Sdteskef_include $BSDCFG_SHARE/networking/media.subr 47240684Sdteskef_include $BSDCFG_SHARE/networking/netmask.subr 48238438Sdteske 49240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" 50238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 51238438Sdteske 52259054Sdteskef_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && 53259054Sdteske pgm="${ipgm:-$pgm}" 54238438Sdteske 55238438Sdteske############################################################ MAIN 56238438Sdteske 57238438Sdteske# Incorporate rc-file if it exists 58238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 59238438Sdteske 60238438Sdteske# 61238438Sdteske# Process command-line options 62238438Sdteske# 63250633Sdteskewhile getopts h$GETOPTS_STDARGS flag; do 64238438Sdteske case "$flag" in 65252178Sdteske h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; 66238438Sdteske esac 67238438Sdteskedone 68238438Sdteskeshift $(( $OPTIND - 1 )) 69238438Sdteske 70238438Sdteske# 71238438Sdteske# Initialize 72238438Sdteske# 73238438Sdteskef_dialog_title "$msg_networking_devices" 74238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 75238438Sdteskef_mustberoot_init 76238438Sdteske 77238438Sdteske# 78238438Sdteske# Launch application main menu 79238438Sdteske# 80251269Sdteskedefaultitem= 81238438Sdteskewhile :; do 82251236Sdteske f_dialog_menu_netdev "$defaultitem" || break 83251236Sdteske f_dialog_menutag_fetch interface 84249751Sdteske defaultitem="$interface" 85238438Sdteske 86238438Sdteske # 87238438Sdteske # dialog_menu_netdev adds an asterisk (*) to the right of the 88238438Sdteske # device name if the interface is active. Remove the asterisk 89238438Sdteske # from the device name if present. 90238438Sdteske # 91238438Sdteske case "$interface" in 92252001Sdteske *\*) interface="${interface%?}" ;; 93238438Sdteske esac 94238438Sdteske 95238438Sdteske # 96238438Sdteske # Obtain initial interface settings to be configured. These will be 97238438Sdteske # passed to the f_dialog_menu_netdev_edit function-call below which 98238438Sdteske # will block until the user has either cancelled or finished editing 99238438Sdteske # the values. 100238438Sdteske # 101238438Sdteske # First, attempt to read stored configuration from rc.conf(5) and 102238438Sdteske # fallback to reading the active configuration if not configured in 103238438Sdteske # the rc.conf(5) file(s). 104238438Sdteske # 105249753Sdteske dhcp= 106238438Sdteske _ipaddr= 107238438Sdteske _netmask= 108238438Sdteske _ifconfig=$( f_sysrc_get ifconfig_$interface ) 109238438Sdteske if [ "$_ifconfig" ]; then 110251926Sdteske # If DHCP, get IP address/netmask later from ifconfig(8) 111238438Sdteske glob="[Dd][Hh][Cc][Pp]" 112238438Sdteske case "$_ifconfig" in 113252001Sdteske $glob) dhcp=1 ;; 114252001Sdteske [Ss][Yy][Nn][Cc]$glob) dhcp=1 ;; 115252001Sdteske [Nn][Oo][Ss][Yy][Nn][Cc]$glob) dhcp=1 ;; 116238438Sdteske *) 117238438Sdteske # 118251926Sdteske # Get IP address/netmask from rc.conf(5) configuration 119238438Sdteske # 120238438Sdteske dhcp= 121252001Sdteske eval "$( 122252001Sdteske exec 2> /dev/null 123252001Sdteske set -- $_ifconfig 124252001Sdteske while [ $# -gt 0 ]; do 125252001Sdteske case "$1" in 126252001Sdteske inet) 127252001Sdteske shift 1 128252001Sdteske echo "_ipaddr='$1'" 129252001Sdteske ;; 130252001Sdteske netmask) 131252001Sdteske shift 1 132252001Sdteske echo "_netmask='$1'" 133252001Sdteske ;; 134252001Sdteske esac 135252001Sdteske shift 1 136252001Sdteske done 137252001Sdteske )" 138238438Sdteske ;; 139238438Sdteske esac 140238438Sdteske fi 141238438Sdteske 142238438Sdteske # 143238438Sdteske # Fill in IP address/netmask from active settings if no 144238438Sdteske # configuration could be extrapolated from rc.conf(5) 145238438Sdteske # 146259054Sdteske [ "$_ipaddr" ] || f_ifconfig_inet $interface _ipaddr 147259054Sdteske [ "$_netmask" ] || f_ifconfig_netmask $interface _netmask 148238438Sdteske 149238438Sdteske # Get the extra options (this always comes from rc.conf(5)) 150238438Sdteske _options=$( f_ifconfig_options $interface ) 151238438Sdteske 152238438Sdteske # Block on user-configuration of the probed settings 153238438Sdteske f_dialog_menu_netdev_edit \ 154249753Sdteske "$interface" "$_ipaddr" "$_netmask" "$_options" $dhcp 155238438Sdteske 156238438Sdteske # Return to root menu if above returns success 157256181Sdteske [ $? -eq $DIALOG_OK ] && break 158238438Sdteskedone 159238438Sdteske 160238438Sdteskeexit $SUCCESS 161238438Sdteske 162238438Sdteske################################################################################ 163238438Sdteske# END 164238438Sdteske################################################################################ 165