devices revision 243112
165483Simp#!/bin/sh 252506Simp#- 3119418Sobrien# Copyright (c) 2006-2012 Devin Teske 4119418Sobrien# All Rights Reserved. 5119418Sobrien# 652506Simp# Redistribution and use in source and binary forms, with or without 752506Simp# modification, are permitted provided that the following conditions 8139749Simp# are met: 952506Simp# 1. Redistributions of source code must retain the above copyright 1052506Simp# notice, this list of conditions and the following disclaimer. 1152506Simp# 2. Redistributions in binary form must reproduce the above copyright 1252506Simp# notice, this list of conditions and the following disclaimer in the 1352506Simp# documentation and/or other materials provided with the distribution. 1452506Simp# 1552506Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1652506Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 1752506Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1852506Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1952506Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2052506Simp# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2152506Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2252506Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2352506Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2452506Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2552506Simp# SUCH DAMAGE. 2652506Simp# 2752506Simp# $FreeBSD: head/usr.sbin/bsdconfig/networking/devices 243112 2012-11-16 00:59:11Z dteske $ 2852506Simp# 2952506Simp############################################################ INCLUDES 3052506Simp 3152506SimpBSDCFG_SHARE="/usr/share/bsdconfig" 3252506Simp. $BSDCFG_SHARE/common.subr || exit 1 3352506Simpf_include $BSDCFG_SHARE/dialog.subr 3452506Simpf_include $BSDCFG_SHARE/mustberoot.subr 3552506Simpf_include $BSDCFG_SHARE/sysrc.subr 3652506Simpf_include $BSDCFG_SHARE/networking/device.subr 3752506Simpf_include $BSDCFG_SHARE/networking/ipaddr.subr 38129762Simpf_include $BSDCFG_SHARE/networking/media.subr 39129781Simpf_include $BSDCFG_SHARE/networking/netmask.subr 4052506Simp 4152506SimpBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" 4252506Simpf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 4352506Simp 44129762Simpipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 45129762Simp[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 46150371Sglebius 47129781Simp############################################################ MAIN 48129740Simp 4952506Simp# Incorporate rc-file if it exists 5052506Simp[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 5152506Simp 5252506Simp# 5352506Simp# Process command-line options 5452506Simp# 5552506Simpwhile getopts hSX flag; do 5652506Simp case "$flag" in 5752506Simp h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 5852506Simp esac 5952506Simpdone 6052506Simpshift $(( $OPTIND - 1 )) 6152506Simp 6252506Simp# 6352506Simp# Initialize 6452506Simp# 6552506Simpf_dialog_init 6652506Simpf_dialog_title "$msg_networking_devices" 6752506Simpf_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 6852506Simpf_mustberoot_init 6952506Simp 7052506Simp# 7152506Simp# Launch application main menu 7252506Simp# 7352506Simpwhile :; do 7452506Simp f_dialog_menu_netdev 7552506Simp retval=$? 7652506Simp interface=$( f_dialog_menutag ) 7752506Simp 7852506Simp [ $retval -eq 0 ] || break 7952506Simp 8052506Simp # 8152506Simp # dialog_menu_netdev adds an asterisk (*) to the right of the 8252506Simp # device name if the interface is active. Remove the asterisk 8352506Simp # from the device name if present. 8452506Simp # 8552506Simp case "$interface" in 8652506Simp *\*) interface="${interface%?}";; 8752506Simp esac 8852506Simp 8952506Simp # 9052506Simp # Obtain initial interface settings to be configured. These will be 9152506Simp # passed to the f_dialog_menu_netdev_edit function-call below which 9252506Simp # will block until the user has either cancelled or finished editing 9352506Simp # the values. 9452506Simp # 9552506Simp # First, attempt to read stored configuration from rc.conf(5) and 9652506Simp # fallback to reading the active configuration if not configured in 9752506Simp # the rc.conf(5) file(s). 9853813Simp # 9953813Simp _ipaddr= 10053813Simp _netmask= 10153813Simp _ifconfig=$( f_sysrc_get ifconfig_$interface ) 10253813Simp if [ "$_ifconfig" ]; then 10353813Simp # If DHCP get IP address/netmask later from ifconfig(8) 10453813Simp glob="[Dd][Hh][Cc][Pp]" 10553813Simp case "$_ifconfig" in 10653813Simp $glob) dhcp=1;; 10753813Simp [Ss][Yy][Nn][Cc]$glob) dhcp=1;; 10853813Simp [Nn][Oo][Ss][Yy][Nn][Cc]$glob) dhcp=1;; 10953813Simp *) 11053813Simp # 11153813Simp # Get IP address/netmask from rc.conf(5) 11253813Simp # configuration 11353813Simp # 11453813Simp dhcp= 11553813Simp eval "$( exec 2> /dev/null 11653813Simp set -- $_ifconfig 11753813Simp while [ $# -gt 0 ]; do 11853813Simp case "$1" in 11953813Simp inet) 12053813Simp shift 1 12153813Simp echo "_ipaddr='$1'" 12253813Simp ;; 12353813Simp netmask) 12453813Simp shift 1 12553813Simp echo "_netmask='$1'" 12653813Simp ;; 12753813Simp esac 12853813Simp shift 1 12953813Simp done 13053813Simp )" 13153813Simp ;; 13253813Simp esac 13353813Simp fi 13453813Simp 13553813Simp # 13653813Simp # Fill in IP address/netmask from active settings if no 13753813Simp # configuration could be extrapolated from rc.conf(5) 13853813Simp # 13953813Simp [ "$_ipaddr" ] || _ipaddr=$( f_ifconfig_inet $interface ) 140182142Simp [ "$_netmask" ] || _netmask=$( f_ifconfig_netmask $interface ) 141182142Simp 142182142Simp # Get the extra options (this always comes from rc.conf(5)) 143182142Simp _options=$( f_ifconfig_options $interface ) 144182142Simp 145182142Simp # Block on user-configuration of the probed settings 146182142Simp f_dialog_menu_netdev_edit \ 147182142Simp $interface $_ipaddr $_netmask "$_options" $dhcp 148182142Simp 149182142Simp # Return to root menu if above returns success 150182142Simp [ $? -eq $SUCCESS ] && break 151182142Simp 152182142Simpdone 153182142Simp 154182142Simpexit $SUCCESS 155182142Simp 156182142Simp################################################################################ 157182142Simp# END 158182142Simp################################################################################ 159182142Simp