From: Thomas Veerman Date: Thu, 3 Sep 2009 09:38:27 +0000 (+0000) Subject: - Added netconf script which makes it a lot easier to change network settings. X-Git-Tag: v3.1.5~163 X-Git-Url: http://zhaoyanbai.com/repos/pkcs11-tokens.html?a=commitdiff_plain;h=360dc9104ccd3ac9a772608681b48b2327dcca8c;p=minix.git - Added netconf script which makes it a lot easier to change network settings. - Modified the setup script to use the netconf script for the network configuration: - Moved step 2 to step 8 and renamed the steps in between. - Autopart adapted to print step 3 instead of step 4. --- diff --git a/commands/ibm/autopart.c b/commands/ibm/autopart.c index 9d974c2f7..a168b43c2 100755 --- a/commands/ibm/autopart.c +++ b/commands/ibm/autopart.c @@ -2066,7 +2066,7 @@ select_region(void) void printstep(int step, char *str) { int n; - n = printf("\n --- Substep 4.%d: %s ---", step, str); + n = printf("\n --- Substep 3.%d: %s ---", step, str); while(n++ < 73) printf("-"); printf("\n"); } diff --git a/commands/scripts/Makefile b/commands/scripts/Makefile index f99954fab..b2b55a2e4 100755 --- a/commands/scripts/Makefile +++ b/commands/scripts/Makefile @@ -40,6 +40,7 @@ usr: \ /usr/bin/mkdist \ /bin/readclock \ /bin/setup \ + /bin/netconf \ /usr/bin/binsizes \ /usr/bin/rotate \ /usr/bin/floppysetup \ @@ -142,6 +143,9 @@ clean: /bin/setup: setup.sh install -m 755 -c -o bin $? $@ +/bin/netconf: netconf.sh + install -m 755 -c -o bin $? $@ + /usr/bin/binsizes: binsizes.sh install -m 755 -c -o bin $? $@ diff --git a/commands/scripts/netconf.sh b/commands/scripts/netconf.sh new file mode 100755 index 000000000..4e4671abb --- /dev/null +++ b/commands/scripts/netconf.sh @@ -0,0 +1,315 @@ +#!/bin/sh +# +# netconf 0.1 - Configure network +# +# Changes: +# + +LOCALRC=/usr/etc/rc.local +INETCONF=/etc/inet.conf +RCNET=/etc/rc.net +HOSTS=/etc/hosts +HOSTNAME=/etc/hostname.file +USRKBFILE=/.usrkb + +step1="" +step2="" +step3="" +v=1 # verbosity +manual_opts=0 +prefix="" +cd="no" # running from cd? + +eth="" +driver="" +driverargs="" + +config="" +manual="" +dhcp="no" + +hostname="" +hostname_prev="" +ip="" +ip_prev="" +netmask="" +netmask_prev="" +gateway="" +dns1="" +dns2="" + +# Provide some sane defaults +hostname_default=`uname -n` +test -z "$hostname_default" && hostname_default="Minix" +ip_default="10.0.0.1" +netmask_default="255.255.255.0" +gateway_default="" + +usage() +{ + cat >&2 <<'EOF' +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. +EOF + exit 1 +} + +cards() +{ + echo "0. No Ethernet card (no networking)" + echo "1. Intel Pro/100" + echo "2. 3Com 501 or 3Com 509 based card" + echo "3. Realtek 8139 based card (also emulated by KVM)" + echo "4. Realtek 8029 based card (also emulated by Qemu)" + echo "5. NE2000, 3com 503 or WD based card (also emulated by Bochs)" + echo "6. AMD LANCE (also emulated by VMWare and VirtualBox)" + echo "7. Different Ethernet card (no networking)" +} + +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" +} + +do_step1() +{ + # Ask user about networking + echo "MINIX 3 currently supports the following Ethernet cards. Please choose: " + echo "" + cards + echo "" + + while [ "$step1" != ok ]; do + echo -n "Ethernet card? [0] "; read eth + test -z $eth && eth=0 + + drv_params $eth + test -n "$driver" && step1="ok" + done +} + +drv_params() +{ + case "$1" in + 0) driver=psip0; ;; + 1) driver=fxp; ;; + 2) driver=dpeth; driverargs="#dpeth_arg='DPETH0=port:irq:memory'"; + test "$v" = 1 && echo "" + test "$v" = 1 && echo "Note: After installing, edit $LOCALRC to the right configuration." + ;; + 3) driver=rtl8139; ;; + 4) driver=dp8390; driverargs="dp8390_arg='DPETH0=pci'"; ;; + 5) driver=dp8390; 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." + ;; + 6) driver="lance"; ;; + 7) driver="psip0"; ;; + *) warn "choose a number" + esac +} + +do_step2() +{ + echo "" + echo "Configure network using DHCP or manually?" + echo "" + echo "1. Automatically using DHCP" + echo "2. Manually" + echo "" + + while [ "$step2" != ok ] + do + echo -n "Configure method? [1] "; read config + test -z $config && config=1 + + case "$config" in + 1) step2="ok"; dhcp="yes" ; ;; + 2) step2="ok"; manual="do"; ;; + *) warn "choose a number" + esac + done + + # Use manual parameters? + if [ -n "$manual" ]; then + # Query user for settings + # Hostname + if [ -z $hostname_prev ]; then + hostname_prev=$hostname_default + fi + echo -n "Hostname [$hostname_prev]: " + read hostname + if [ ! -z $hostname ]; then + hostname_prev=$hostname + else + hostname=$hostname_prev + fi + + # IP address + if [ -z $ip_prev ]; then + ip_prev=$ip_default + fi + echo -n "IP address [$ip_prev]: " + read ip + if [ ! -z $ip ]; then + ip_prev=$ip + else + ip=$ip_prev + fi + + # Netmask + if [ -z $netmask_prev ]; then + netmask_prev=$netmask_default + fi + echo -n "Netmask [$netmask_prev]: " + read netmask + if [ ! -z $netmask ]; then + netmask_prev=$netmask + else + netmask=$netmask_prev + fi + + # 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" && dns1=$dns1_prev + if [ ! -z "$dns1" ]; then + dns1_prev=$dns1 + + echo -n "Secondary DNS Server [$dns2_prev]: " + read dns2 + if [ ! -z $dns2 ]; then + dns2_prev=$dns2 + fi + else + # If no primary DNS, then also no secondary DNS + dns2="" + fi + fi +} + +# Parse options +while getopts ":qe:p:aH:i:n:g:d:s:hc" arg; do + case "$arg" in + q) v=0; ;; + e) ethernet=$OPTARG; + test "$ethernet" -ge 0 -a "$ethernet" -le 7 2>/dev/null || usage + drv_params $ethernet + ;; + p) prefix=$OPTARG; ;; + a) dhcp="yes"; ;; + H) hostname=$OPTARG; manual_opts=`expr $manual_opts '+' 1`;; + i) ip=$OPTARG; manual_opts=`expr $manual_opts '+' 1`;; + n) netmask=$OPTARG; manual_opts=`expr $manual_opts '+' 1`;; + g) gateway=$OPTARG; manual_opts=`expr $manual_opts '+' 1`;; + d) dns1=$OPTARG; ;; + s) dns2=$OPTARG; ;; + h) usage ;; + c) echo -e "The following cards are supported by Minix:\n"; + cards; exit 0 + ;; + \?) echo "Unknown option -$OPTARG"; usage ;; + :) echo "Missing required argument for -$OPTARG"; usage ;; + *) usage ;; + esac +done + +# Verify parameter count +if [ "$dhcp" != "yes" ] ; then + if [ $manual_opts -gt 0 ] ; then + test $manual_opts -eq 4 -a -n "$dns1" || usage + manual="do" + fi +fi + +if [ -n "$prefix" ] ; then + LOCALRC=$prefix$LOCALRC + INETCONF=$prefix$INETCONF + RCNET=$prefix$RCNET + HOSTS=$prefix$HOSTS + HOSTNAME=$prefix$HOSTNAME + if [ ! -f $INETCONF ]; then + echo -e "It seems the supplied prefix (\`$prefix') is invalid." + exit 1 + fi +fi + +if [ "$USER" != root ] ; then + test "$v" = 1 && echo "Please run netconf as root." + exit 1 +fi + +# Are we running from CD? +if [ -f "$USRKBFILE" ] ; then + echo "Running from CD" + cd="yes" # We are running from CD +fi + +# 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 [ -n "$manual" ] + then + # 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 +fi + +test "$cd" != "yes" && test "$v" = 1 && echo " +You might have to reboot for the changes to take effect." +exit 0 diff --git a/commands/scripts/setup.sh b/commands/scripts/setup.sh index e0fb1ca93..9d6f6f23e 100755 --- a/commands/scripts/setup.sh +++ b/commands/scripts/setup.sh @@ -130,59 +130,11 @@ done # end Step 1 # begin Step 2 -echo "" -echo " --- Step 2: Select your Ethernet chip ---------------------------------" -echo "" - -# Ask user about networking -echo "MINIX 3 currently supports the following Ethernet cards. Please choose: " - echo "" - echo "0. No Ethernet card (no networking)" - echo "1. Intel Pro/100" - echo "2. 3Com 501 or 3Com 509 based card" - echo "3. Realtek 8139 based card (also emulated by KVM)" - echo "4. Realtek 8029 based card (also emulated by Qemu)" - echo "5. NE2000, 3com 503 or WD based card (also emulated by Bochs)" - echo "6. AMD LANCE (also emulated by VMWare and VirtualBox)" - echo "7. Different Ethernet card (no networking)" - echo "" - echo "You can always change your mind after the setup." - echo "" -step2="" -while [ "$step2" != ok ] -do - eth="" - echo -n "Ethernet card? [0] "; read eth - test -z $eth && eth=0 - driver="" - driverargs="" - case "$eth" in - 0) step2="ok"; ;; - 1) step2="ok"; driver=fxp; ;; - 2) step2="ok"; driver=dpeth; driverargs="#dpeth_arg='DPETH0=port:irq:memory'"; - echo "" - echo "Note: After installing, edit $LOCALRC to the right configuration." - ;; - 3) step2="ok"; driver=rtl8139; ;; - 4) step2="ok"; driver=dp8390; driverargs="dp8390_arg='DPETH0=pci'"; ;; - 5) step2="ok"; driver=dp8390; driverargs="dp8390_arg='DPETH0=240:9'"; - echo "" - echo "Note: After installing, edit $LOCALRC to the right configuration." - echo " chose option 4, the defaults for emulation by Bochs have been set." - ;; - 6) driver="lance"; step2="ok"; ;; - 7) step2="ok"; ;; - *) warn "choose a number" - esac -done -# end Step 2 - -# begin Step 3 -#step3="" -#while [ "$step3" != ok ] +#step2="" +#while [ "$step2" != ok ] #do # echo "" -# echo " --- Step 3: Select minimal or full distribution -----------------------" +# echo " --- Step 2: Select minimal or full distribution -----------------------" # echo "" # echo "You can install MINIX as (M)inimal or (F)ull. (M)inimal" # echo "includes only the binary system and basic system sources." @@ -195,24 +147,24 @@ done # echo -n "Basic (M)inimal or (F)ull install? [F] " # read conf # case "$conf" in -# "") step3="ok"; nobigsource="" ;; -# [Ff]*) step3="ok"; nobigsource="" ;; -# [Mm]*) step3="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;; +# "") step2="ok"; nobigsource="" ;; +# [Ff]*) step2="ok"; nobigsource="" ;; +# [Mm]*) step2="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;; # esac #done -# end Step 3 +# end Step 2 echo "" -echo " --- Step 3: Selecting full distribution -------------------------------" +echo " --- Step 2: Selecting full distribution -------------------------------" echo "" nobigsource="" -# begin Step 4 -step4="" -while [ "$step4" != ok ] +# begin Step 3 +step3="" +while [ "$step3" != ok ] do echo "" - echo " --- Step 4: Create or select a partition for MINIX 3 -------------------" + echo " --- Step 3: Create or select a partition for MINIX 3 -------------------" echo "" echo "Now you need to create a MINIX 3 partition on your hard disk." @@ -282,7 +234,7 @@ Please finish the name of the primary partition you have created: do echo -n "Are you sure you want to continue? Please enter 'yes' or 'no': " read confirmation - if [ "$confirmation" = yes ]; then step4=ok; fi + if [ "$confirmation" = yes ]; then step3=ok; fi done biosdrivename="Actual BIOS device name unknown, due to expert mode." else @@ -311,23 +263,23 @@ Please finish the name of the primary partition you have created: # them messy. atnormalize - if [ -n "$primary" ]; then step4=ok; fi + if [ -n "$primary" ]; then step3=ok; fi fi fi if [ ! -b "/dev/$primary" ] - then echo Doing step 4 again. - step4="" + then echo Doing step 3 again. + step3="" else devsize="`devsize /dev/$primary`" if [ "$devsize" -lt 1 ] then echo "/dev/$primary is a 0-sized device." - step4="" + step3="" fi fi -done # while step4 != ok -# end Step 4 +done # while step3 != ok +# end Step 3 root=${primary}s0 home=${primary}s1 @@ -359,7 +311,7 @@ while [ "$confirm" = "" ] do auto="" echo "" -echo " --- Step 5: Reinstall choice ------------------------------------------" +echo " --- Step 4: Reinstall choice ------------------------------------------" if mount -r /dev/$home $TMPMP >/dev/null 2>&1 then umount /dev/$home >/dev/null 2>&1 echo "" @@ -391,7 +343,7 @@ homesize="" if [ ! "$auto" = r ] then echo "" -echo " --- Step 6: Select the size of /home ----------------------------------" +echo " --- Step 5: Select the size of /home ----------------------------------" while [ -z "$homesize" ] do @@ -448,7 +400,7 @@ blockdefault=4 if [ ! "$auto" = "r" ] then echo "" -echo " --- Step 7: Select a block size ---------------------------------------" +echo " --- Step 6: Select a block size ---------------------------------------" echo "" echo "The default file system block size is $blockdefault KB." @@ -505,10 +457,9 @@ else fshome="" fi echo "" -echo " --- Step 8: Wait for files to be copied -------------------------------" +echo " --- Step 7: Wait for files to be copied -------------------------------" echo "" -echo "This is the final step of the MINIX 3 setup. All files will now be" -echo "copied to your hard disk. This may take a while." +echo "All files will now be copied to your hard disk. This may take a while." echo "" mount /dev/$usr /mnt >/dev/null || exit # Mount the intended /usr. @@ -521,10 +472,6 @@ mount /dev/$usr /mnt >/dev/null || exit # Mount the intended /usr. done ) | progressbar "$USRFILES" || exit # Copy the usr floppy. -if [ -n "$driver" ] -then echo "$driverargs" >$MYLOCALRC -fi - umount /dev/$usr >/dev/null || exit # Unmount the intended /usr. mount /dev/$root /mnt >/dev/null || exit @@ -536,10 +483,6 @@ cp /mnt/etc/motd.install /mnt/etc/motd rm /mnt/var/log ln -s /usr/log /mnt/var/log -if [ -n "$driver" ] -then echo "eth0 $driver 0 { default; };" >/mnt/etc/inet.conf -fi - # CD remnants that aren't for the installed system rm /mnt/etc/issue /mnt/CD /mnt/.* 2>/dev/null # Change /etc/fstab. (No swap.) @@ -554,7 +497,7 @@ $fshome" # National keyboard map. test -n "$keymap" && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap -umount /dev/$root >/dev/null || exit # Unmount the new root. +umount /dev/$root >/dev/null || exit # Unmount the new root. mount /dev/$usr /mnt >/dev/null || exit # Make bootable. @@ -587,6 +530,21 @@ fi echo "Saving random data.." dd if=/dev/random of=/mnt/adm/random.dat bs=1024 count=1 +umount /dev/$usr >/dev/null || exit + +# Networking. +echo "" +echo " --- Step 8: Select your Ethernet chip ---------------------------------" +echo "" + +mount /dev/$root /mnt >/dev/null || exit +mount /dev/$usr /mnt/usr >/dev/null || exit + +/bin/netconf -p /mnt || echo FAILED TO CONFIGURE NETWORK + +umount /dev/$usr && echo Unmounted $usr +umount /dev/$root && echo Unmounted $root + echo " Please type 'shutdown' to exit MINIX 3 and enter the boot monitor. At the boot monitor prompt, type 'boot $bios', where X is the bios drive