#!/bin/sh # # netconf 0.1 - Configure network # # Changes: # setglobal LOCALRC = '/usr/etc/rc.local' setglobal INETCONF = '/etc/inet.conf' setglobal RCNET = '/etc/rc.net' setglobal HOSTS = '/etc/hosts' setglobal HOSTNAME = '/etc/hostname.file' setglobal USRKBFILE = '/.usrkb' setglobal step1 = ''"" setglobal step2 = ''"" setglobal step3 = ''"" setglobal v = '1' # verbosity setglobal manual_opts = '0' setglobal prefix = ''"" setglobal cd = '"no'" # running from cd? setglobal eth = ''"" setglobal driver = ''"" setglobal driverargs = ''"" setglobal config = ''"" setglobal manual = ''"" setglobal dhcp = '"no'" setglobal hostname = ''"" setglobal hostname_prev = ''"" setglobal ip = ''"" setglobal ip_prev = ''"" setglobal netmask = ''"" setglobal netmask_prev = ''"" setglobal gateway = ''"" setglobal dns1 = ''"" setglobal dns2 = ''"" # Provide some sane defaults setglobal hostname_default = $[uname -n] test -z $hostname_default && setglobal hostname_default = '"Minix'" setglobal ip_default = '"10.0.0.1'" setglobal netmask_default = '"255.255.255.0'" setglobal gateway_default = ''"" proc usage { cat > !2 << ''' Usage: netconf [-q] [-p ] [-e ] [-a] netconf [-H -i -n -g -d [-s ]] flags: -q Limit generated output -p Path prefix for configuration files (e.g., during install -p mnt is used as files are mounted on /mnt). -e Ethernet card -a Use DHCP (-H, -i, -n, -g, -d, and -s flags are discarded) -H Hostname -i IP address -n Netmask -g Default gateway -d Primary DNS -s Secondary DNS -h Shows this help file -c Shows a list of ethernet cards supported By default netconf starts in Interactive mode. By providing parameters on the command line, some questions can be omitted. ''' exit 1 } proc card { setglobal card_number = $1 setglobal card_name = $2 setglobal card_avail = '0' shift 2 while [ $# -gt 0 ] { lspci | grep > /dev/null "^$1> /dev/null "^$1" && setglobal card_avail = '1' shift } if test $card_avail -gt 0 { setglobal card_mark = '"*'" setglobal eth_default = $card_number } else { setglobal card_mark = '" '" } printf "%2d. %s %s\n" $card_number $card_mark $card_name } proc cards { card 0 "No Ethernet card (no networking)" card 1 "Intel Pro/100" "8086:103D" "8086:1064" "8086:1229" "8086:2449" card 2 "3Com 501 or 3Com 509 based card" card 3 "Realtek 8139 based card (also emulated by KVM)" \ "10EC:8139" "02AC:1012" "1065:8139" "1113:1211" "1186:1300" \ "1186:1340" "11DB:1234" "1259:A117" "1259:A11E" "126C:1211" \ "13D1:AB06" "1432:9130" "14EA:AB06" "14EA:AB07" "1500:1360" \ "1743:8139" "4033:1360" card 4 "Realtek 8169 based card" \ "10EC:8129" "10EC:8167" "10EC:8169" "1186:4300" "1259:C107" \ "1385:8169" "16EC:0116" "1737:1032" card 5 "Realtek 8029 based card (also emulated by Qemu)" "10EC:8029" card 6 "NE2000, 3com 503 or WD based card (also emulated by Bochs)" card 7 "AMD LANCE (also emulated by VMWare and VirtualBox)" "1022:2000" card 8 "Intel PRO/1000 Gigabit" "8086:100E" "8086:107C" "8086:10CD" card 9 "Attansic/Atheros L2 FastEthernet" "1969:2048" card 10 "DEC Tulip 21140A in VirtualPC" "1011:0009" card 11 "Different Ethernet card (no networking)" } proc warn { 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" } proc do_step1 { setglobal eth_default = '0' # Ask user about networking echo "MINIX 3 currently supports the following Ethernet cards. PCI cards detected" echo "by MINIX are marked with *. Please choose: " echo "" cards echo "" while test $step1 != ok { echo -n "Ethernet card? [$eth_default] "; read eth test -z $eth && setglobal eth = $eth_default drv_params $eth test -n $driver && setglobal step1 = '"ok'" } } proc drv_params { match $1 { with 0 setglobal driver = 'psip0'; with 1 setglobal driver = 'fxp'; with 2 setglobal driver = 'dpeth'; setglobal driverargs = '"#dpeth_arg='DPETH0=port:irq:memory''"; test $v = 1 && echo "" test $v = 1 && echo "Note: After installing, edit $LOCALRC to the right configuration." with 4 setglobal driver = 'rtl8169'; with 3 setglobal driver = 'rtl8139'; with 5 setglobal driver = 'dp8390'; setglobal driverargs = '"dp8390_arg='DPETH0=pci''"; with 6 setglobal driver = 'dp8390'; setglobal driverargs = '"dp8390_arg='DPETH0=240:9''"; test $v = 1 && echo "" test $v = 1 && echo "Note: After installing, edit $LOCALRC to the right configuration." test $v = 1 && echo " chose option 4, the defaults for emulation by Bochs have been set." with 7 setglobal driver = '"lance'"; with 8 setglobal driver = '"e1000'"; with 9 setglobal driver = '"atl2'"; with 10 setglobal driver = '"dec21140A'"; with 11 setglobal driver = '"psip0'"; with * warn "choose a number" } } proc do_step2 { echo "" echo "Configure network using DHCP or manually?" echo "" echo "1. Automatically using DHCP" echo "2. Manually" echo "" while [ "$step2" != ok ] { echo -n "Configure method? [1] "; read config test -z $config && setglobal config = '1' match $config { with 1 setglobal step2 = '"ok'"; setglobal dhcp = '"yes'" ; with 2 setglobal step2 = '"ok'"; setglobal manual = '"do'"; with * warn "choose a number" } } # Use manual parameters? if test -n $manual { # Query user for settings # Hostname if test -z $hostname_prev { setglobal hostname_prev = $hostname_default } echo -n "Hostname [$hostname_prev]: " read hostname if test ! -z $hostname { setglobal hostname_prev = $hostname } else { setglobal hostname = $hostname_prev } # IP address if test -z $ip_prev { setglobal ip_prev = $ip_default } echo -n "IP address [$ip_prev]: " read ip if test ! -z $ip { setglobal ip_prev = $ip } else { setglobal ip = $ip_prev } # Netmask if test -z $netmask_prev { setglobal netmask_prev = $netmask_default } echo -n "Netmask [$netmask_prev]: " read netmask if test ! -z $netmask { setglobal netmask_prev = $netmask } else { setglobal netmask = $netmask_prev } # Gateway (no gateway is fine for local networking) echo -n "Gateway: " read gateway # DNS Servers echo -n "Primary DNS Server [$dns1_prev]: " read dns1 test -z $dns1 && test -n $dns1_prev && setglobal dns1 = $dns1_prev if test ! -z $dns1 { setglobal dns1_prev = $dns1 echo -n "Secondary DNS Server [$dns2_prev]: " read dns2 if test ! -z $dns2 { setglobal dns2_prev = $dns2 } } else { # If no primary DNS, then also no secondary DNS setglobal dns2 = ''"" } } } # Parse options while getopts ":qe:p:aH:i:n:g:d:s:hc" arg { match $arg { with q setglobal v = '0'; with e setglobal ethernet = $OPTARG; test $ethernet -ge 0 -a $ethernet -le 7 !2 >/dev/null || usage drv_params $ethernet with p setglobal prefix = $OPTARG; with a setglobal dhcp = '"yes'"; with H setglobal hostname = $OPTARG; setglobal manual_opts = $[expr $manual_opts '+' 1] with i setglobal ip = $OPTARG; setglobal manual_opts = $[expr $manual_opts '+' 1] with n setglobal netmask = $OPTARG; setglobal manual_opts = $[expr $manual_opts '+' 1] with g setglobal gateway = $OPTARG; setglobal manual_opts = $[expr $manual_opts '+' 1] with d setglobal dns1 = $OPTARG; with s setglobal dns2 = $OPTARG; with h usage with c echo -e "The following cards are supported by Minix:\n"; cards; exit 0 with \? echo "Unknown option -$OPTARG"; usage with : echo "Missing required argument for -$OPTARG"; usage with * usage } } # Verify parameter count if test $dhcp != "yes" { if test $manual_opts -gt 0 { test $manual_opts -eq 4 -a -n $dns1 || usage setglobal manual = '"do'" } } if test -n $prefix { setglobal LOCALRC = "$prefix$LOCALRC" setglobal INETCONF = "$prefix$INETCONF" setglobal RCNET = "$prefix$RCNET" setglobal HOSTS = "$prefix$HOSTS" setglobal HOSTNAME = "$prefix$HOSTNAME" if test ! -f $INETCONF { echo -e "It seems the supplied prefix (\`$prefix') is invalid." exit 1 } } if test $USER != root { test $v = 1 && echo "Please run netconf as root." exit 1 } # Are we running from CD? if test -f $USRKBFILE { setglobal cd = '"yes'" # We are running from CD } # Do we know what ethernet card to use? test -z $ethernet && do_step1 # If no parameters are supplied and we're not using DHCP, query for settings test $manual_opts -eq 0 -a $dhcp = "no" && do_step2 # Store settings. # Do not make backups if we're running from CD test $cd != "yes" && test -f $INETCONF && mv $INETCONF "$INETCONF~" && test $v = 1 && echo "Backed up $INETCONF to $INETCONF~" test $cd != "yes" && test -f $LOCALRC && mv $LOCALRC "$LOCALRC~" && test $v = 1 && echo "Backed up $LOCALRC to $LOCALRC~" echo "eth0 $driver 0 { default; } ;" > $INETCONF echo $driverargs > $LOCALRC if test -n $manual { # Backup config file if it exists and we're not running from CD test $cd != "yes" && test -f $RCNET && mv $RCNET "$RCNET~" && test $v = 1 && echo "Backed up $RCNET to $RCNET~" test $cd != "yes" && test -f $HOSTS && mv $HOSTS "$HOSTS~" && test $v = 1 && echo "Backed up $HOSTS to $HOSTS~" # Store manual config echo "ifconfig -I /dev/ip0 -n $netmask -h $ip" > $RCNET test ! -z $gateway && echo "add_route -g $gateway" >> $RCNET echo "daemonize nonamed -L" >> $RCNET test ! -z $dns1 && echo -e "$ip\t%nameserver\t#$hostname" > $HOSTS test ! -z $dns1 && echo -e "$dns1\t%nameserver\t#DNS 1" >> $HOSTS test ! -z $dns2 && echo -e "$dns2\t%nameserver\t#DNS 2" >> $HOSTS echo -e "\n$ip\t$hostname" >> $HOSTS echo $hostname > $HOSTNAME } else { test $cd != "yes" && test -f $RCNET && mv $RCNET "$RCNET~" && test $v = 1 && echo "Moved $RCNET to $RCNET~ to use default settings" test $cd != "yes" && test -f $HOSTS && mv $HOSTS "$HOSTS~" && test $v = 1 && echo "Backed up $HOSTS to $HOSTS~" test -f "$HOSTS~" && grep -v "%nameserver" "$HOSTS~" > $HOSTS } test $cd != "yes" && test $v = 1 && echo " You might have to reboot for the changes to take effect." exit 0