3 # netconf 0.2 - Configure network
6 # v0.2: rewrite for NetBSD network infrastructure
7 # - the primary choice is now for an interface, not a network card;
8 # - manual driver configuration is now an exception;
9 # - the menu transition system is slightly more solid;
10 # - all non-interactive functionality has been removed.
16 LOCALRC
=/usr
/etc
/rc.
local
18 RESOLVCONF
=/etc
/resolv.conf
19 HOSTNAME
=/etc
/hostname.
file
23 cd="no" # running from cd?
24 changed
="no" # have any ifconfig.if(5) files been changed?
31 netconf [-lh] [-p <prefix>]
34 -l Print a list of configurable interfaces
35 -h Print this help file
36 -p Set a path prefix for all configuration files (e.g., /mnt)
43 # Do not make backups if we're running from CD.
44 if [ "$cd" != "yes" -a -f "$1" ]; then
45 mv "$1" "$1~" ||
exit 1
47 echo "Backed up $1 to $1~"
63 [ $input -ge $1 -a $input -le $2 ] && return $input
71 # Get a list of interfaces that are not virtual (i.e., cloners). There
72 # is always one virtual interface type ("lo", loopback).
73 cloners_regex
='^('`ifconfig -C | sed 's/ /[0-9]|/g'`'[0-9])'
74 iflist
=`ifconfig -l | tr ' ' '\n' | grep -vE "$cloners_regex"`
77 ifunconf
=0 # the first interface with no configuration file, or 0
78 if [ -z "$iflist" ]; then
79 echo " No network hardware interfaces detected!"
82 ifcount
=$
(($ifcount + 1))
83 if [ -r $IFCONF$if ]; then
86 [ $ifunconf -eq 0 ] && ifunconf
=$ifcount
89 printf "%2d. %-8s %s\n" $ifcount "$if" "$info"
97 The following network interfaces are available for configuration. These are
98 interfaces corresponding to network drivers that are currently running. If no
99 interface is listed for your network card here, then either MINIX 3 does not
100 support your card, or, if it is not a plug-and-play device, it may require
101 manual configuration first.
103 Please choose the interface you would like to configure, or another option.
105 interfaces
"already configured"
107 manual_choice
=$
(($ifcount + 1))
108 quit_choice
=$
(($ifcount + 2))
109 printf "%2d. Manually configure an ethernet driver\n" $manual_choice
110 printf "%2d. Quit\n\n" $quit_choice
112 default_choice
=$ifunconf
113 [ $default_choice -eq 0 ] && default_choice
=$quit_choice
115 select_number
1 $quit_choice $default_choice "Interface choice?"
125 ifchoice
="$(echo $iflist | cut -d' ' -f$choice)"
132 # TODO: it would be nice if this list changed on a per-platform basis..
134 MINIX 3 has drivers for a limited number of older cards that require manual
135 configuration. They are shown below. Please choose one of the listed options.
137 1. 3Com 501 or 3Com 509 based ISA card (i386)
138 2. NE2000, 3Com 503, or WD based ISA card (i386) (emulated by Bochs, Qemu)
140 3. Go back to interface selection
144 select_number
1 4 4 "Card choice?"
149 driverargs
="#dpeth_args='DPETH0=port:irq:memory'"
151 Note: After installing, edit $LOCALRC to the right configuration."
155 driverargs
="dp8390_args='DPETH0=300:9'"
157 Note: After installing, edit $LOCALRC to the right configuration.
158 You may then also have to edit /etc/system.conf.d/dp8390 to match.
159 For now, the defaults for emulation by Bochs/Qemu have been set."
170 backup_file
"$LOCALRC"
171 echo "# Generated by netconf(8). Edit as necessary." > $LOCALRC
172 echo "netdriver='"$driver"'" >> $LOCALRC
173 echo "$driverargs" >> $LOCALRC
175 # $LOCALRC typically expands to /mnt/usr/etc/rc.local, so leave room..
177 A template to start the driver has been written to $LOCALRC . As
178 noted above, you may have to edit it. Once you are done editing, reboot the
179 system, after which the driver will be started. Once the driver is running,
180 you can run 'netconf' to configure the corresponding network interface."
185 iffile
="$IFCONF$ifchoice"
188 Configure interface $ifchoice using DHCP or manually?
190 For now, the choice here is primarily about IPv4. With DHCP it is possible to
191 enable IPv6 as well. Even if the local network has no IPv6 facilities, enabling
192 IPv6 should do no harm. For IPv6-only mode or any other configuration that is
193 not supported here, you will have to edit $iffile yourself.
195 1. Automatically using DHCP (IPv4 + IPv6)
196 2. Automatically using DHCP (IPv4 only)
197 3. Manually (IPv4 only)"
199 if [ -r "$iffile" ]; then
200 echo " 4. Remove current configuration"
211 printf "%2d. Go back to interface selection\n" $goback_choice
212 printf "%2d. Quit\n\n" $quit_choice
214 select_number
1 $quit_choice 1 "Configuration choice?"
218 backup_file
"$iffile"
220 echo '!dhcpcd -qM $int' >> $iffile
223 echo "Interface $ifchoice configured for DHCP (IPv4 + IPv6)."
227 backup_file
"$iffile"
229 echo '!dhcpcd -qM -4 $int' >> $iffile
232 echo "Interface $ifchoice configured for DHCP (IPv4 only)."
236 # Query user for settings
238 # Some of these settings (hostname, nameservers) do not apply
239 # to just the selected interface. Still, they are what one has
240 # to specify for a complete manual configuration. In order to
241 # make manual configuration of multiple interfaces less
242 # frustrating in this regard, offer defaults that match what
243 # may just have been set already.
248 if [ -r $HOSTNAME ]; then
249 hostname_default
=$
(cat $HOSTNAME)
251 hostname_default
="minix"
253 echo -n "Hostname [$hostname_default]: "
255 if [ -z "$hostname" ]; then
256 hostname
="$hostname_default"
261 while [ -z "$ip" ]; do
262 echo -n "IP address []: "
267 echo -n "Netmask (optional) []: "
269 [ -n "$netmask" ] && netmask
=" netmask $netmask"
271 # Gateway (no gateway is fine for local networking)
272 echo -n "Gateway (optional) []: "
276 dns1_default
="$(grep '^nameserver' $RESOLVCONF 2>/dev/null | \
277 sed '1q' | awk '{print $2}')"
278 dns2_default
="$(grep '^nameserver' $RESOLVCONF 2>/dev/null | \
279 sed '2q;d' | awk '{print $2}')"
281 echo -n "Primary DNS Server [$dns1_default]: "
283 [ -z "$dns1" ] && dns1
="$dns1_default"
285 if [ -n "$dns1" ]; then
286 echo -n "Secondary DNS Server (optional) [$dns2_default]: "
288 [ -z "$dns2" ] && dns2
="$dns2_default"
293 backup_file
"$HOSTNAME"
294 echo "$hostname" > $HOSTNAME
297 backup_file
"$iffile"
299 echo "inet $ip$netmask" >> $iffile
300 if [ -n "$gateway" ]; then
301 echo "!route -q add default $gateway" >> $iffile
304 if [ -n "$dns1" ]; then
305 backup_file
"$RESOLVCONF"
306 echo "nameserver $dns1" > $RESOLVCONF
307 if [ -n "$dns2" ]; then
308 echo "nameserver $dns2" >> $RESOLVCONF
313 echo "Interface $ifchoice configured manually."
317 backup_file
"$iffile"
320 echo "Removed configuration for interface $ifchoice."
332 # We get here only if one of the ifconfig.if(5) files have changed.
336 Do you want to configure additional interfaces?
338 You can also invoke the 'netconf' command as root at any later time.
340 1. Go back to interface selection
344 # Note that "quit" is deliberately the default choice: most people will
345 # want to configure at most one interface, and keep pressing Enter in
346 # order to make it through the setup procedure as easily as possible.
347 select_number
1 2 2 "Menu choice?"
349 [ $?
-eq 1 ] && step
=do_step1
353 while getopts "p:hl" arg
; do
355 p
) prefix
=$OPTARG; ;;
357 l
) echo "The following network hardware interfaces are detected:"
359 interfaces
"configured"
362 \?) echo "Unknown option -$OPTARG"; usage
;;
363 :) echo "Missing required argument for -$OPTARG"; usage
;;
368 if [ -n "$prefix" ] ; then
369 if [ ! -d $prefix ]; then
370 echo -e "It seems the supplied prefix (\`$prefix') is invalid."
373 LOCALRC
=$prefix$LOCALRC
374 IFCONF
=$prefix$IFCONF
375 RESOLVCONF
=$prefix$RESOLVCONF
376 HOSTNAME
=$prefix$HOSTNAME
379 if [ `whoami` != root
] ; then
380 echo "Please run netconf as root."
384 if ! ifconfig
-l >/dev
/null
2>&1; then
385 echo "Unable to obtain a list of interfaces. Is the LWIP service running?"
389 # Are we running from CD?
390 if [ -f "$USRKBFILE" ] ; then
391 cd="yes" # We are running from CD
394 # The interactive program.
396 while [ $step != exit ]; do
402 # Skip printing this last bit of information if it will not actually work. The
403 # fact that it will not work on the CD (i.e. from the setup program) at least
404 # yet, is also the reason why we do not simply issue the command ourselves
405 # right now. We might reconsider this later.
406 if [ "$changed" = "yes" -a -z "$prefix" ]; then
408 echo "One or more of the interface configuration files have been changed."
409 echo "You can use the command 'service network restart' to reload them now."