3 # netconf 0.1 - Configure network
11 LOCALRC
=/usr
/etc
/rc.
local
12 INETCONF
=/etc
/inet.conf
15 HOSTNAME
=/etc
/hostname.
file
18 DEVICES
=/tmp
/devices.$$
26 cd="no" # running from cd?
46 # Provide some sane defaults
47 hostname_default
=`uname -n`
48 test -z "$hostname_default" && hostname_default
="Minix"
50 netmask_default
="255.255.255.0"
58 netconf [-q] [-p <prefix>] [-e <num>] [-a]
59 netconf [-H <name> -i <ip> -n <mask> -g <gw> -d <prim dns> [-s <sec dns>]]
62 -q Limit generated output
63 -p Path prefix for configuration files (e.g., during install -p mnt is used as files are mounted on /mnt).
65 -a Use DHCP (-H, -i, -n, -g, -d, and -s flags are discarded)
72 -h Shows this help file
73 -c Shows a list of ethernet cards supported
75 By default netconf starts in Interactive mode. By providing parameters on the
76 command line, some questions can be omitted.
89 cat $LSPCI |
grep > /dev
/null
"^$1" && card_avail
=1
92 if [ $card_avail -gt 0 ]
95 eth_default
=$card_number
99 printf "%2d. %s %s\n" "$card_number" "$card_mark" "$card_name"
106 # Run lspci once to a temp file for use in 'card' function
107 lspci
>$LSPCI 2>/dev
/null || true
109 card
0 "No Ethernet card (no networking)"
110 card
1 "3Com 501 or 3Com 509 based card"
111 card
2 "Realtek 8029 based card (also emulated by Qemu)" "10EC:8029"
112 card
3 "NE2000, 3com 503 or WD based card (also emulated by Bochs)"
113 card
4 "lan8710a (on BeagleBone, BeagleBone Black)"
115 for pcicard
in $pci_list
116 do var
=\
$pci_descr$pcicard; descr
="`eval echo $var`"
117 var
=\
$pci_pcilist$pcicard; pcilist
="`eval echo $var`"
118 card
$n "$descr" $pcilist
122 card
$first_after_pci "Different Ethernet card (no networking)"
124 # Remove temporary lspci output
130 echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! $1"
138 # Collect configs from network devices
139 for dir
in $SYSTEM_CONF_DIRS
140 do for f
in $dir/$SYSTEM_CONF_SUBDIR/*
142 then printconfig
$f |
grep 'type net.*pci device'
147 do pcilist
="`echo $devline | sed 's/.*pci device //' | sed 's/,.*//'`"
148 descr
="`echo $devline | sed 's/.*,descr //' | sed 's/,.*//'`"
149 label
="`echo $devline | sed 's/.*service //' | sed 's/,.*//'`"
150 pci_list
="$pci_list $n"
151 eval "pci_pcilist$n=\"$pcilist\""
152 eval "pci_descr$n=\"$descr\""
153 eval "pci_label$n=\"$label\""
157 first_after_pci
=`expr $first_pcicard + $n`
166 # Ask user about networking
167 echo "MINIX 3 currently supports the following Ethernet cards. PCI cards detected"
168 echo "by MINIX are marked with *. Please choose: "
173 while [ "$step1" != ok
]; do
174 echo -n "Ethernet card? [$eth_default] "; read eth
175 test -z $eth && eth
=$eth_default
178 test -n "$driver" && step1
="ok"
184 # If this is a known pci device, we only have to set
186 if [ $1 -ge $first_pcicard -a $1 -lt $first_after_pci ]
187 then pcicard
="`expr $1 - $first_pcicard`"
188 var
=\
$pci_label$pcicard; driver
="`eval echo $var`"
192 # Other possibilities.
195 1) driver
=dpeth
; driverargs
="#dpeth_arg='DPETH0=port:irq:memory'";
196 test "$v" = 1 && echo ""
197 test "$v" = 1 && echo "Note: After installing, edit $LOCALRC to the right configuration."
199 2) driver
=dp8390
; driverargs
="dp8390_arg='DPETH0=pci'"; ;;
200 3) driver
=dp8390
; driverargs
="dp8390_arg='DPETH0=240:9'";
201 test "$v" = 1 && echo ""
202 test "$v" = 1 && echo "Note: After installing, edit $LOCALRC to the right configuration."
203 test "$v" = 1 && echo " chose option 4, the defaults for emulation by Bochs have been set."
205 4) driver
=lan8710a
; ;;
206 $first_after_pci) driver
="psip0"; ;;
207 *) warn
"choose a number"
214 echo "Configure network using DHCP or manually?"
216 echo "1. Automatically using DHCP"
220 while [ "$step2" != ok
]
222 echo -n "Configure method? [1] "; read config
223 test -z $config && config
=1
226 1) step2
="ok"; dhcp
="yes" ; ;;
227 2) step2
="ok"; manual
="do"; ;;
228 *) warn
"choose a number"
232 # Use manual parameters?
233 if [ -n "$manual" ]; then
234 # Query user for settings
236 if [ -z $hostname_prev ]; then
237 hostname_prev
=$hostname_default
239 echo -n "Hostname [$hostname_prev]: "
241 if [ ! -z $hostname ]; then
242 hostname_prev
=$hostname
244 hostname
=$hostname_prev
248 if [ -z $ip_prev ]; then
251 echo -n "IP address [$ip_prev]: "
253 if [ ! -z $ip ]; then
260 if [ -z $netmask_prev ]; then
261 netmask_prev
=$netmask_default
263 echo -n "Netmask [$netmask_prev]: "
265 if [ ! -z $netmask ]; then
266 netmask_prev
=$netmask
268 netmask
=$netmask_prev
271 # Gateway (no gateway is fine for local networking)
276 echo -n "Primary DNS Server [$dns1_prev]: "
278 test -z "$dns1" && test -n "$dns1_prev" && dns1
=$dns1_prev
279 if [ ! -z "$dns1" ]; then
282 echo -n "Secondary DNS Server [$dns2_prev]: "
284 if [ ! -z $dns2 ]; then
288 # If no primary DNS, then also no secondary DNS
294 # Find pci cards we know about
298 while getopts ":qe:p:aH:i:n:g:d:s:hc" arg
; do
302 test "$ethernet" -ge 0 -a "$ethernet" -le 7 2>/dev
/null || usage
305 p
) prefix
=$OPTARG; ;;
307 H
) hostname
=$OPTARG; manual_opts
=`expr $manual_opts '+' 1`;;
308 i
) ip
=$OPTARG; manual_opts
=`expr $manual_opts '+' 1`;;
309 n
) netmask
=$OPTARG; manual_opts
=`expr $manual_opts '+' 1`;;
310 g
) gateway
=$OPTARG; manual_opts
=`expr $manual_opts '+' 1`;;
314 c
) echo -e "The following cards are supported by Minix:\n";
317 \?) echo "Unknown option -$OPTARG"; usage
;;
318 :) echo "Missing required argument for -$OPTARG"; usage
;;
323 # Verify parameter count
324 if [ "$dhcp" != "yes" ] ; then
325 if [ $manual_opts -gt 0 ] ; then
326 test $manual_opts -eq 4 -a -n "$dns1" || usage
331 if [ -n "$prefix" ] ; then
332 LOCALRC
=$prefix$LOCALRC
333 INETCONF
=$prefix$INETCONF
336 HOSTNAME
=$prefix$HOSTNAME
337 if [ ! -f $INETCONF ]; then
338 echo -e "It seems the supplied prefix (\`$prefix') is invalid."
343 if [ `whoami` != root
] ; then
344 test "$v" = 1 && echo "Please run netconf as root."
348 # Are we running from CD?
349 if [ -f "$USRKBFILE" ] ; then
350 cd="yes" # We are running from CD
353 # Do we know what ethernet card to use?
354 test -z "$ethernet" && do_step1
356 # If no parameters are supplied and we're not using DHCP, query for settings
357 test $manual_opts -eq 0 -a "$dhcp" = "no" && do_step2
360 # Do not make backups if we're running from CD
361 test "$cd" != "yes" && test -f $INETCONF && mv $INETCONF "$INETCONF~" &&
362 test "$v" = 1 && echo "Backed up $INETCONF to $INETCONF~"
363 test "$cd" != "yes" && test -f $LOCALRC && mv $LOCALRC "$LOCALRC~" &&
364 test "$v" = 1 && echo "Backed up $LOCALRC to $LOCALRC~"
366 if [ "$driver" = "psip0" ]; then
367 echo "psip0 { default; } ;" > $INETCONF
369 echo "eth0 $driver 0 { default; } ;" > $INETCONF
371 echo "$driverargs" > $LOCALRC
375 # Backup config file if it exists and we're not running from CD
376 test "$cd" != "yes" && test -f $RCNET && mv $RCNET "$RCNET~" &&
377 test "$v" = 1 && echo "Backed up $RCNET to $RCNET~"
378 test "$cd" != "yes" && test -f $HOSTS && mv $HOSTS "$HOSTS~" &&
379 test "$v" = 1 && echo "Backed up $HOSTS to $HOSTS~"
381 # Store manual config
382 echo "ifconfig -I /dev/ip0 -n $netmask -h $ip" > $RCNET
383 test ! -z $gateway && echo "add_route -g $gateway" >> $RCNET
384 echo "daemonize nonamed -L" >> $RCNET
385 test ! -z $dns1 && echo -e "$ip\t%nameserver\t#$hostname" > $HOSTS
386 test ! -z $dns1 && echo -e "$dns1\t%nameserver\t#DNS 1" >> $HOSTS
387 test ! -z $dns2 && echo -e "$dns2\t%nameserver\t#DNS 2" >> $HOSTS
388 echo -e "\n$ip\t$hostname" >> $HOSTS
389 echo $hostname > $HOSTNAME
391 test "$cd" != "yes" && test -f "$RCNET" && mv "$RCNET" "$RCNET~" &&
392 test "$v" = 1 && echo "Moved $RCNET to $RCNET~ to use default settings"
393 test "$cd" != "yes" && test -f $HOSTS && mv $HOSTS "$HOSTS~" &&
394 test "$v" = 1 && echo "Backed up $HOSTS to $HOSTS~"
395 test -f "$HOSTS~" && grep -v "%nameserver" "$HOSTS~" > $HOSTS
398 test "$cd" != "yes" && test "$v" = 1 && echo "
399 You might have to reboot for the changes to take effect."