home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / delix / initrd / initrd-fixes.30.06.97 / usr / adm / setup / netsetup < prev   
Encoding:
Text File  |  1997-06-25  |  6.4 KB  |  290 lines

  1. #!/bin/sh
  2. #
  3. ####################################################
  4. #                                                                    #
  5. # File:        netsetup                                            #
  6. # Authors:    Niels Mache, Ngo Than                        #
  7. # Last change:    07/05/1997                                    #
  8. #                                                                    #
  9. # DLD - German Linux Distribution -                        #
  10. #                                                                    #
  11. # Copyright (c) 1993-1997  delix Computer GmbH        #
  12. #                          Schlo▀stra▀e 98            #
  13. #                          D-70176 Stuttgart            #
  14. # All rights reserved.                                        #
  15. #                                                                    #
  16. ####################################################
  17.  
  18. PATH=/sbin:/bin:/usr/bin
  19. RootPath="/dest"
  20. IPath=$RootPath
  21. clear="H"
  22. [ -z "$DLDVersion" ] && DLDVersion="5.2"
  23. [ -z "$DIALOGTITLE" ] && DIALOGTITLE=" DLD $DLDVersion (C) 1993-1997 by delix GmbH, Schlo▀str. 98, 70176 Stuttgart, Germany"
  24. title="Netzwerk Konfiguration"
  25.  
  26. if [ "$TERM" = "xterm" ]; then
  27.     export TERM=color_xterm
  28. fi
  29.  
  30. mydialog() { 
  31.     dialog --backtitle "$DIALOGTITLE" "$@"
  32.  
  33.  
  34. cleanup()  {
  35.     rm -f /tmp/ret /tmp/ret.set /tmp/err.set
  36. }
  37.  
  38. error() {
  39.     mydialog --title "Fehler:" --msgbox "$@" 10 73
  40. }
  41.  
  42. errorCheck() {
  43.     if [ -s /tmp/err.set ]; then
  44.         error "`cat /tmp/err.set`"
  45.     fi
  46.     rm -f /tmp/err.set
  47. }
  48.  
  49. #  Main
  50.  
  51. unset IPADDR NETWORK NETMASK BROADCAST GATEWAY HOSTNAME DOMAINNAME NAMESERVER
  52.  
  53. [ -f /tmp/NETINST ] && source /tmp/NETINST
  54.  
  55. while [ 1 ] ; do
  56.  
  57.     mydialog --title "$title" --inputbox \
  58. "\nBitte geben Sie den Hostname dieses Rechners ein:\n" \
  59. 11 55 "$HOSTNAME" 2> /tmp/ret.set
  60.  
  61.     [ "$?" != "0" ] && exit 1
  62.     hostn=`cat /tmp/ret.set`
  63.  
  64.     DOMAINNAME=`echo $hostn | sed "s/[aA0-zZ9]*.//"`
  65.     mydialog --title "$title" --inputbox \
  66. "\nBitte geben Sie den Domainname dieses Rechners ein:\n" \
  67. 11 57 "$DOMAINNAME" 2> /tmp/ret.set
  68.  
  69.     [ "$?" != "0" ] && exit 1
  70.     domain=`cat /tmp/ret.set`
  71.  
  72.     mydialog --title "$title" --inputbox \
  73. "\nGeben Sie die IP Adresse dieses Rechners ein:\n" \
  74. 11 52 "$IPADDR" 2> /tmp/ret.set
  75.  
  76.     [ "$?" != "0" ] && exit 1
  77.     ipaddr=`cat /tmp/ret.set`
  78.  
  79.     if [ ! -f /tmp/NETINST ]; then
  80.         NETMASK="255.255.255.0"
  81.         NETWORK=`echo $ipaddr | sed "/[0-9]*$/s//0/"`
  82.         BROADCAST=`echo $ipaddr | sed "/[0-9]*$/s//255/"`
  83.         GATEWAY=`echo $ipaddr | sed "/[0-9]*$/s//1/"`
  84.     fi
  85.  
  86.     mydialog --title "$title" --inputbox \
  87. "\nGeben Sie die Netzwerkadresse dieses Rechners ein:\n" \
  88. 11 56 "$NETWORK" 2> /tmp/ret.set
  89.  
  90.     [ "$?" != "0" ] && exit 1
  91.     network=`cat /tmp/ret.set`
  92.  
  93.     mydialog --title "$title" --inputbox \
  94. "\nGeben Sie die Netzmaskierung dieses Rechners ein:\n" \
  95. 11 55 "$NETMASK" 2> /tmp/ret.set
  96.  
  97.     [ "$?" != "0" ] && exit 1
  98.     netmask=`cat /tmp/ret.set`
  99.  
  100.     mydialog --title "$title" --inputbox \
  101. "\nGeben Sie die Broadcastadresse dieses Rechners ein:\n" \
  102. 11 58 "$BROADCAST" 2> /tmp/ret.set
  103.  
  104.     [ "$?" != "0" ] && exit 1
  105.     broadcast=`cat /tmp/ret.set`
  106.  
  107.     mydialog --title "$title" --inputbox \
  108. "\nGeben Sie die IP Adresse Ihres Gateways ein:\n" \
  109. 11 51 "$GATEWAY" 2> /tmp/ret.set
  110.  
  111.     [ "$?" != "0" ] && exit 1
  112.     gateway=`cat /tmp/ret.set`
  113.  
  114.     if [ "$gateway" = "" ] ; then
  115.         gateway=
  116.     elif [ "$gateway" = "$ipaddr" ] ; then
  117.         gateway=
  118.     fi
  119.  
  120.     mydialog --title "$title" --inputbox \
  121. "\nBitte geben Sie die IP-Adresse des Nameservers ein:\n" \
  122. 11 58 "$NAMESERVER"  2> /tmp/ret.set
  123.  
  124.     [ "$?" != "0" ] && exit 1
  125.     nameserver=`cat /tmp/ret.set`
  126.  
  127.     mydialog --title "Einstellungen" --yesno \
  128. "\n      Sind Sie zufrieden mit diesen Einstellungen?\n\n\
  129. Hostname   :  $hostn\n\
  130. Domainname :  $domain\n\
  131. Adresse    :  $ipaddr\n\
  132. Netzwerk   :  $network\n\
  133. Netzmaske  :  $netmask\n\
  134. Broadcast  :  $broadcast\n\
  135. Gateway    :  $gateway\n\
  136. Nameserver :  $nameserver" 16 60
  137.  
  138.     Status="$?"
  139.     HOSTNAME="$hostn"
  140.     DOMAINNAME="$domain"
  141.     IPADDR="$ipaddr"
  142.     NETWORK="$network"
  143.     NETMASK="$netmask"
  144.     BROADCAST="$broadcast"
  145.     GATEWAY="$gateway"
  146.     NAMESERVER="$nameserver"
  147.  
  148.     if [ "$Status" = "0" ]; then
  149.         break
  150.     else
  151.         mydialog --title "Netzwerk Konfiguration" --yesno \
  152. "\n     Wollen Sie Netzwerk Konfiguration wiederholen?\n" 7 60
  153.  
  154.         if [ "$?" != "0" ]; then
  155.             exit 1
  156.         fi
  157.     fi
  158.  
  159. done
  160.  
  161.     mydialog  --title "Netzwerk Konfiguration" --infobox \
  162. "\n Die Konfiguration des Netzwerks kann u.U. 1-2 Minuten\n\
  163.  dauern. Haben Sie bitte etwas Geduld.\n" 6 59
  164.  
  165.     # Attach the loopback device.
  166.     ifconfig lo 127.0.0.1 2>/dev/null
  167.     route add -net 127.0.0.0 2>/dev/null
  168.  
  169.     start=1
  170.     for i in /proc/[1-9]*; do
  171.         if [ "`cat $i/cmdline`" = "/sbin/portmap" ]; then
  172.             start=0
  173.             break
  174.         fi
  175.     done
  176.  
  177.     if [ $start = 1 ]; then
  178.         /sbin/portmap 2>/dev/null
  179.     fi
  180.  
  181.     start=1
  182.     for i in /proc/[1-9]*; do
  183.         if [ "`cat $i/cmdline`" = "/sbin/inetd" ]; then
  184.             start=0
  185.             break
  186.         fi
  187.     done
  188.  
  189.     if [ $start = 1 ]; then
  190.         /sbin/inetd 2>/dev/null
  191.     fi
  192.  
  193.     if [ -n "$broadcast" ]; then
  194.         ifconfig eth0 $ipaddr netmask $netmask broadcast $broadcast 2> /tmp/err.set
  195.     else
  196.         ifconfig eth0 $ipaddr netmask $netmask 2> /tmp/err.set
  197.     fi
  198.  
  199.     errorCheck
  200.  
  201.     route add -net $network netmask $netmask 2> /tmp/err.set
  202.     errorCheck
  203.  
  204.     if [ "$gateway" != "" ]; then
  205.         route add default gw $gateway metric 1 2> /tmp/err.set
  206.         errorCheck
  207.     fi
  208.  
  209.     echo "Einstellungen:" > /tmp/ret
  210.     ifconfig >> /tmp/ret
  211.     route >> /tmp/ret
  212.  
  213.     mydialog --title "$title" --textbox \
  214. /tmp/ret 20 73
  215.  
  216.  
  217.     while [ 1 ]; do
  218.         mydialog --title "Netzwerk Setup" --inputbox \
  219. "Geben Sie die IP Adresse des NFS-Servers ein :" 8 54 $NFSSERVER 2> /tmp/ret.doi
  220.         if [ "$?" != "0" ]; then
  221.             exit 1
  222.         fi
  223.         nfsserver=`cat /tmp/ret.doi`
  224.         if [ "$nfsserver" != "" ]; then
  225.             break
  226.         fi
  227.     done
  228.  
  229. mydialog --title "Netzwerk Setup" --inputbox \
  230. "\nGeben Sie das Verzeichnis auf dem NFS-Server an,\n\
  231. in dem sich die DLD Distribution befindet:\n" 12 54 $NFSPATH 2> /tmp/ret.doi
  232.  
  233. if [ "$?" != "0" ]; then
  234.     exit 1
  235. fi
  236.  
  237. nfspath=`cat /tmp/ret.doi`
  238.  
  239. if [ "$nfspath" = "" ]; then
  240.     nfspath="/cdrom/delix"
  241. fi
  242.  
  243. cat << EOF > /tmp/NETINST
  244. HOSTNAME="$hostn"
  245. DOMAINNAME="$domain"
  246. IPADDR="$ipaddr"
  247. NETMASK="$netmask"
  248. NETWORK="$network"
  249. BROADCAST="$broadcast"
  250. GATEWAY="$gateway"
  251. NFSSERVER="$nfsserver"
  252. NFSPATH="$nfspath"
  253. NAMESERVER="$nameserver"
  254. EOF
  255.  
  256. mkdir -p $IPath/etc/sysconfig
  257. cat << EOF > $IPath/etc/sysconfig/network
  258. NETWORKING=yes
  259. HOSTNAME="$hostn"
  260. DOMAINNAME="$domain"
  261. GATEWAY="$gateway"
  262. GATEWAYDEV=eth0
  263. NAMESERVER="$nameserver"
  264. EOF
  265.  
  266. echo "127.0.0.1 localhost" > $IPath/etc/hosts
  267. echo "$ipaddr $hostn" >> $IPath/etc/hosts
  268. echo "$hostn" > $IPath/etc/HOSTNAME
  269. echo "search $domain" > $IPath/etc/resolv.conf
  270. echo "nameserver $nameserver" >> $IPath/etc/resolv.conf
  271.  
  272. mkdir -p $IPath/etc/sysconfig/network-scripts
  273.  
  274. cat << EOF > $IPath/etc/sysconfig/network-scripts/ifcfg-eth0
  275. DEVICE="eth0"
  276. IPADDR="$ipaddr"
  277. NETMASK="$netmask"
  278. NETWORK="$network"
  279. BROADCAST="$broadcast"
  280. ONBOOT=yes
  281. BOOTP=no
  282. EOF
  283.  
  284. chmod a+x $IPath/etc/sysconfig/network-scripts/ifcfg-eth0
  285.  
  286. cleanup
  287. echo $clear
  288. exit 0
  289.