Deleted Added
full compact
device.subr (256281) device.subr (260675)
1if [ ! "$_NETWORKING_DEVICE_SUBR" ]; then _NETWORKING_DEVICE_SUBR=1
2#
3# Copyright (c) 2006-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
1if [ ! "$_NETWORKING_DEVICE_SUBR" ]; then _NETWORKING_DEVICE_SUBR=1
2#
3# Copyright (c) 2006-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: stable/10/usr.sbin/bsdconfig/networking/share/device.subr 256181 2013-10-09 08:12:26Z dteske $
27# $FreeBSD: stable/10/usr.sbin/bsdconfig/networking/share/device.subr 260675 2014-01-15 07:36:34Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." networking/device.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr

--- 21 unchanged lines hidden (view full) ---

57
58# f_dialog_menu_netdev [$default]
59#
60# Display a list of network devices with descriptions. Optionally, if present
61# and non-NULL, initially highlight $default interface.
62#
63f_dialog_menu_netdev()
64{
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." networking/device.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr

--- 21 unchanged lines hidden (view full) ---

57
58# f_dialog_menu_netdev [$default]
59#
60# Display a list of network devices with descriptions. Optionally, if present
61# and non-NULL, initially highlight $default interface.
62#
63f_dialog_menu_netdev()
64{
65 local defaultitem="${1%\*}" # Tim trailing asterisk if present
65 local menu_list # Calculated below
66 local defaultitem="${1%\*}" # Trim trailing asterisk if present
66
67 #
68 # Display a message to let the user know we're working...
69 # (message will remain until we throw up the next dialog)
70 #
71 f_dialog_info "$msg_probing_network_interfaces"
72
73 #
74 # Get list of usable network interfaces
75 #
67
68 #
69 # Display a message to let the user know we're working...
70 # (message will remain until we throw up the next dialog)
71 #
72 f_dialog_info "$msg_probing_network_interfaces"
73
74 #
75 # Get list of usable network interfaces
76 #
76 local d='[[:digit:]]+:'
77 local iflist="`echo "$(ifconfig -l):" | sed -E -e "
78 # Convert all spaces to colons
79 y/ /:/
77 local if iflist= # Calculated below
78 for if in $( ifconfig -l ); do
79 # Skip unsavory interfaces
80 case "$if" in
81 lo[0-9]*|ppp[0-9]*|sl[0-9]*|faith[0-9]*) continue ;;
82 esac
83 iflist="$iflist $if"
84 done
85 iflist="${iflist# }"
80
86
81 # Prune unsavory interfaces
82 s/lo$d//g
83 s/ppp$d//g
84 s/sl$d//g
85 s/faith$d//g
86
87 # Convert all colons back into spaces
88 y/:/ /
89 "`"
90
91 #
92 # Optionally kick interfaces in the head to get them to accurately
93 # track the carrier status in realtime (required on FreeBSD).
94 #
95 if [ "$DIALOG_MENU_NETDEV_KICK_INTERFACES" ]; then
96 DIALOG_MENU_NETDEV_KICK_INTERFACES=
97
98 local ifn

--- 6 unchanged lines hidden (view full) ---

105 sleep $DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK
106 fi
107 fi
108
109 #
110 # Mark any "active" interfaces with an asterisk (*)
111 # to the right of the device name.
112 #
87 #
88 # Optionally kick interfaces in the head to get them to accurately
89 # track the carrier status in realtime (required on FreeBSD).
90 #
91 if [ "$DIALOG_MENU_NETDEV_KICK_INTERFACES" ]; then
92 DIALOG_MENU_NETDEV_KICK_INTERFACES=
93
94 local ifn

--- 6 unchanged lines hidden (view full) ---

101 sleep $DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK
102 fi
103 fi
104
105 #
106 # Mark any "active" interfaces with an asterisk (*)
107 # to the right of the device name.
108 #
113 interfaces=$(
109 menu_list=$(
114 for ifn in $iflist; do
110 for ifn in $iflist; do
115 active=$( ifconfig $ifn | awk \
116 '
117 ( $1 == "status:" ) \
118 {
119 if ( $2 == "active" ) { print 1; exit }
120 }
121 ' )
111 active=$( ifconfig $ifn 2> /dev/null | awk '
112 ($1 == "status:") {
113 if ($2 == "active") { print 1; exit }
114 }' )
122 printf "'%s%s' '%s'\n" \
123 $ifn "${active:+*}" "$( f_device_desc $ifn )"
124 done
125 )
115 printf "'%s%s' '%s'\n" \
116 $ifn "${active:+*}" "$( f_device_desc $ifn )"
117 done
118 )
126 if [ ! "$interfaces" ]; then
119 if [ ! "$menu_list" ]; then
127 f_show_msg "$msg_no_network_interfaces"
128 return $DIALOG_CANCEL
129 fi
130
131 #
132 # Maybe the default item was marked as active
133 #
134 if [ "$defaultitem" ]; then
120 f_show_msg "$msg_no_network_interfaces"
121 return $DIALOG_CANCEL
122 fi
123
124 #
125 # Maybe the default item was marked as active
126 #
127 if [ "$defaultitem" ]; then
135 ifconfig "$defaultitem" 2> /dev/null | awk \
136 '( $1 == "status:" && $2 != "active" ) { exit 0 }' ||
128 ifconfig "$defaultitem" 2> /dev/null |
129 awk '($1 == "status:" && $2 == "active"){exit 1}' ||
137 defaultitem="$defaultitem*"
138 fi
139
140 local hline="$hline_arrows_tab_enter"
141
142 #
143 # Ask user to select an interface
144 #
145 local prompt="$msg_select_network_interface"
146 local height width rows
147 eval f_dialog_menu_size height width rows \
148 \"\$DIALOG_TITLE\" \
149 \"\$DIALOG_BACKTITLE\" \
150 \"\$prompt\" \
151 \"\$hline\" \
130 defaultitem="$defaultitem*"
131 fi
132
133 local hline="$hline_arrows_tab_enter"
134
135 #
136 # Ask user to select an interface
137 #
138 local prompt="$msg_select_network_interface"
139 local height width rows
140 eval f_dialog_menu_size height width rows \
141 \"\$DIALOG_TITLE\" \
142 \"\$DIALOG_BACKTITLE\" \
143 \"\$prompt\" \
144 \"\$hline\" \
152 $interfaces
145 $menu_list
153 local menu_choice
154 menu_choice=$( eval $DIALOG \
155 --title \"\$DIALOG_TITLE\" \
156 --backtitle \"\$DIALOG_BACKTITLE\" \
157 --hline \"\$hline\" \
158 --ok-label \"\$msg_ok\" \
159 --cancel-label \"\$msg_cancel\" \
160 --default-item \"\$defaultitem\" \
161 --menu \"\$prompt\" \
162 $height $width $rows \
146 local menu_choice
147 menu_choice=$( eval $DIALOG \
148 --title \"\$DIALOG_TITLE\" \
149 --backtitle \"\$DIALOG_BACKTITLE\" \
150 --hline \"\$hline\" \
151 --ok-label \"\$msg_ok\" \
152 --cancel-label \"\$msg_cancel\" \
153 --default-item \"\$defaultitem\" \
154 --menu \"\$prompt\" \
155 $height $width $rows \
163 $interfaces \
156 $menu_list \
164 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
165 )
166 local retval=$?
167 f_dialog_menutag_store -s "$menu_choice"
168 return $retval
169}
170
171# f_dialog_menu_netdev_edit $interface $ipaddr $netmask $options $dhcp

--- 107 unchanged lines hidden (view full) ---

279 dhcp=
280 else
281 trap - SIGINT
282 ( # Execute within sub-shell to allow/catch Ctrl-C
283 trap 'exit $FAILURE' SIGINT
284 msg=$( printf "$msg_scanning_for_dhcp" "$interface" )
285 if [ "$USE_XDIALOG" ]; then
286 (
157 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
158 )
159 local retval=$?
160 f_dialog_menutag_store -s "$menu_choice"
161 return $retval
162}
163
164# f_dialog_menu_netdev_edit $interface $ipaddr $netmask $options $dhcp

--- 107 unchanged lines hidden (view full) ---

272 dhcp=
273 else
274 trap - SIGINT
275 ( # Execute within sub-shell to allow/catch Ctrl-C
276 trap 'exit $FAILURE' SIGINT
277 msg=$( printf "$msg_scanning_for_dhcp" "$interface" )
278 if [ "$USE_XDIALOG" ]; then
279 (
287 f_quietly ifconfig $interface delete
288 f_quietly dhclient $interface
280 f_quietly ifconfig "$interface" delete
281 f_quietly dhclient "$interface"
289 ) |
290 f_xdialog_info "$msg"
291 else
292 f_dialog_info "$msg"
282 ) |
283 f_xdialog_info "$msg"
284 else
285 f_dialog_info "$msg"
293 f_quietly ifconfig $interface delete
294 f_quietly dhclient $interface
286 f_quietly ifconfig "$interface" delete
287 f_quietly dhclient "$interface"
295 fi
296 )
297 retval=$?
298 trap 'interrupt' SIGINT
299 if [ $retval -eq $DIALOG_OK ]; then
300 dhcp=1
288 fi
289 )
290 retval=$?
291 trap 'interrupt' SIGINT
292 if [ $retval -eq $DIALOG_OK ]; then
293 dhcp=1
301 ipaddr=$( f_ifconfig_inet $interface )
302 netmask=$( f_ifconfig_netmask $interface )
294 f_ifconfig_inet "$interface" ipaddr
295 f_ifconfig_inet6 "$interface" ipaddr6
296 f_ifconfig_netmask "$interface" netmask
303 options=
304
305 # Fixup search/domain in resolv.conf(5)
306 hostname=$( f_sysrc_get \
307 'hostname:-$(hostname)' )
308 f_dialog_resolv_conf_update "$hostname"
309 fi
310 fi

--- 81 unchanged lines hidden ---
297 options=
298
299 # Fixup search/domain in resolv.conf(5)
300 hostname=$( f_sysrc_get \
301 'hostname:-$(hostname)' )
302 f_dialog_resolv_conf_update "$hostname"
303 fi
304 fi

--- 81 unchanged lines hidden ---