home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / NETCFG / _NETCFG.TAR / sbin / netconfig.tty < prev   
Encoding:
Text File  |  1995-01-09  |  13.6 KB  |  477 lines

  1. #!/bin/sh 
  2. # This checks IP address syntax.
  3. # usage: syntax_check ADDRESS #-OF-EXPECTED-SEGMENTS (up to 4)
  4. # example: syntax_check 123.22.43.1 4
  5. # returns: 0=found correct  1=too many fields  2=non numeric field found
  6. syntax_check() {
  7.   RET_CODE=0 
  8.   SCRATCH=$1
  9.   SCRATCH=`echo $SCRATCH | tr "." "/"`
  10.   INDEX=$2
  11.   while [ ! "$INDEX" = "0" ]; do
  12.     # OK, so I'm a LISP-head :^)
  13.     FIELD=`basename $SCRATCH`
  14.     SCRATCH=`dirname $SCRATCH`
  15.     if expr $FIELD + 1 1> /dev/null 2> /dev/null; then
  16.       GOOD=y
  17.     else
  18.       RET_CODE=2; # non-numeric field
  19.     fi
  20.     INDEX=`expr $INDEX - 1`
  21.   done
  22.   if [ ! "$SCRATCH" = "." ]; then
  23.     RET_CODE=1; # too many arguments
  24.   fi
  25.   if [ "$3" = "WARN" -a ! "$RET_CODE" = "0" ]; then
  26.     cat << EOF
  27.  
  28. The address you have entered seems to be non-standard. We were expecting $2
  29. groups of numbers seperated by dots, like: 127.0.0.1
  30. Are you absolutely sure you want to use the address $1?
  31.  
  32. EOF
  33.     echo -n "Use funny address $1 ([y]es, [n]o)? "
  34.     read USE_FUNNY;
  35.     echo
  36.     if [ "$USE_FUNNY" = "y" ]; then
  37.       RET_CODE = 0;
  38.     fi
  39.   else
  40.     if [ "$3" = "ECHO" ]; then
  41.       echo $RET_CODE;
  42.     fi
  43.   fi
  44.   return $RET_CODE;
  45. }
  46.  
  47. if [ ! -d lost+found -a ! -d vmlinuz -a ! -d proc ]; then # cheap, but it works :^)
  48.  cd /
  49. fi;
  50.  
  51. ############################################################################
  52. #
  53. #  Disclaimer:
  54. #
  55. #  WARNING! USE THIS SCRIPT AT YOUR OWN RISK, I HAVE NO IDEA WHAT IT
  56. #  WILL DO IF RUN ON YOUR COMPUTER! I ACCEPT NO RESPONSIBILITY!
  57. #
  58. #  A script to help get you on the net. Original idea from the MCC
  59. #  install.net.  This script asks you for your hostname, domainname, IP
  60. #  address, network address, gateway, netmask, broadcast address, and
  61. #  your DNS server.  It then proceeds to set up the networking files
  62. #  using the answers you gave it.  Make sure that the files and programs 
  63. #  point to the right directory.  This is set up as documented in the 
  64. #  NET-2-HOWTO. Please email me about any problems with, or errors in, 
  65. #  the script.
  66. #
  67. #                            Jim Robinson
  68. #                            jimr@simons-rock.edu
  69. ############################################################################
  70. #
  71. # IMPORTANT!!! NO LEADING '/' in the paths below, or this script will not
  72. # function from the bootdisk.
  73. IFCONFIG=sbin/ifconfig            # Where ifconfig program is.
  74. ROUTE=sbin/route            # Where route program is.
  75. RC=etc/rc.d/rc.inet1            # Where rc.inet1 file is.
  76. RESOLV=etc/resolv.conf            # Where resolv.conf file is.
  77. HOSTS=etc/hosts                 # Where hosts file is.
  78. ETCNETWORKS=etc/networks        # Where networks file is.
  79. SMAIL=var/lib/smail/config        # Smail configuration file
  80. ELMRC=var/lib/elm/elm.rc        # ELM rc file
  81. #
  82. # defaults:
  83. NETWORK=127.0.0.0
  84. IPADDR=127.0.0.1
  85. #
  86. ############################################################################
  87. #             Question and answer.
  88. ############################################################################
  89. #
  90. cat << EOF
  91.  
  92. NETWORK CONFIGURATION
  93.  
  94. Now we will attempt to configure your mail and TCP/IP. This process probably
  95. won't work on all possible network configurations, but should give you a good
  96. start. You will be able to reconfigure your system at any time by typing:
  97.   
  98.   netconfig
  99.  
  100. EOF
  101. HOSTNAME=""
  102. while [ "$HOSTNAME" = "" ]; do
  103. cat << EOF
  104. First, we'll need the name you'd like to give your host. Only the base
  105. hostname is needed right now. (not the domain)
  106.  
  107. EOF
  108.  echo -n "Enter hostname: "
  109.  read HOSTNAME
  110. done
  111.  
  112. while [ "$DOMAIN" = "" ]; do
  113. cat << EOF
  114.  
  115. Now, we need the domain name. Do not supply a leading '.'
  116.  
  117. EOF
  118.  echo -n "Enter domain name for $HOSTNAME: "
  119.  read DOMAIN
  120. done
  121. echo
  122.  
  123. cat << EOF
  124. If you only plan to use TCP/IP through loopback, then your IP address will
  125. be 127.0.0.1 and we can skip a lot of the following questions.
  126.  
  127. EOF
  128.  
  129. LOOPBACK=unknown
  130. while [ ! "$LOOPBACK" = "y" -a ! "$LOOPBACK" = "n" ]; do
  131.  echo -n "Do you plan to ONLY use loopback ([y]es, [n]o)? "
  132.  read LOOPBACK;
  133.  echo
  134. done
  135.  
  136. if [ -r etc/rc.d/rc.inet1 -a "$LOOPBACK" = "n" ]; then
  137.  
  138.  while [ 0 ]; do
  139.   echo "Enter your IP address for the local machine. Example: 111.112.113.114"
  140.   echo -n "Enter IP address for $HOSTNAME (aaa.bbb.ccc.ddd): "
  141.   read IPADDR
  142.   if [ "$IPADDR" = "" ]; then
  143.     continue;
  144.   fi
  145.   syntax_check $IPADDR 4 WARN
  146.   if [ $? = 0 ]; then
  147.     break;
  148.   fi
  149.  done
  150.  echo
  151.  
  152. # while [ 0 ]; do
  153. #  echo "Enter your network address. This will usually be your IP address"
  154. #  echo "with the last number replaced by 0, such as 111.112.113.0"
  155. #  echo -n "Enter network address (aaa.bbb.ccc.ddd): "
  156. #  read NETWORK
  157. #  if [ "$NETWORK" = "" ]; then
  158. #    continue;
  159. #  fi
  160. #  syntax_check $NETWORK 4 WARN
  161. #  if [ $? = 0 ]; then
  162. #    break;
  163. #  fi
  164. # done
  165. # echo
  166.  
  167.  while [ 0 ]; do
  168.   echo "Enter your gateway address, such as 111.112.113.1"
  169.   echo "If you don't have a gateway, you can edit /etc/rc.d/rc.inet1 later,"
  170.   echo "or you can probably get away with entering your own IP address here."
  171.   echo -n "Enter gateway address (aaa.bbb.ccc.ddd): "
  172.   read GATEWAY
  173.   if [ "$GATEWAY" = "" ]; then
  174.     continue;
  175.   fi
  176.   syntax_check $GATEWAY 4 WARN
  177.   if [ $? = 0 ]; then
  178.     break;
  179.   fi
  180.  done
  181.  echo
  182.  
  183.  while [ 0 ]; do
  184.   echo "Enter your netmask. This will generally look something"
  185.   echo "like this: 255.255.255.0"
  186.   echo -n "Enter netmask (aaa.bbb.ccc.ddd): "
  187.   read NETMASK
  188.   if [ "$NETMASK" = "" ]; then
  189.     continue;
  190.   fi
  191.   syntax_check $NETMASK 4 WARN
  192.   if [ $? = 0 ]; then
  193.     break;
  194.   fi
  195.  done
  196.  echo
  197.  
  198. # while [ "$BROADCAST" = "" ]; do
  199. #  echo "Your broadcast address will usually be your IP address"
  200. #  echo "with 255 replacing the last value, such as: 111.112.113.255"
  201. #  echo -n "Enter broadcast address (aaa.bbb.ccc.ddd): "
  202. #  read BROADCAST
  203. #  if [ "$BROADCAST" = "" ]; then
  204. #    continue;
  205. #  fi
  206. #  syntax_check $BROADCAST 4 WARN
  207. #  if [ $? = 0 ]; then
  208. #    break;
  209. #  fi
  210. # done
  211. # echo
  212.  
  213. BROADCAST=`ipmask $NETMASK $IPADDR | cut -f 1 -d ' '`
  214. NETWORK=`ipmask $NETMASK $IPADDR | cut -f 2 -d ' '`
  215.  
  216.  echo "Setting up TCP/IP..."
  217. else
  218.  if [ ! -r etc/rc.d/rc.inet1 ]; then
  219.  cat << EOF
  220.  
  221. You do not seem to have TCP/IP installed, so all I can really set up for
  222. you is your hostname/domainname. This won't mean much since you're not on
  223. the network, but it will let you have the hostname you prefer shown at the
  224. login prompt.
  225.  
  226. EOF
  227.  fi
  228. fi
  229.  
  230. echo "Creating /etc/HOSTNAME..."
  231. echo $HOSTNAME.$DOMAIN > etc/HOSTNAME
  232.  
  233. #
  234. ############################################################################
  235. #              The rc.inet1 file.
  236. ############################################################################
  237. #
  238. if [ -f $RC ]; then 
  239.  cp $RC tmp/`basename $RC`.OLD
  240.  echo "Creating /$RC..."
  241. if [ "$LOOPBACK" = "n" ]; then # we are using an ethernet card
  242.  /bin/cat <<EOF >$RC
  243. #! /bin/sh
  244. #
  245. # rc.inet1    This shell script boots up the base INET system.
  246. #
  247. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  248. #
  249.  
  250. HOSTNAME=\`cat /etc/HOSTNAME\`
  251.  
  252. # Attach the loopback device.
  253. /$IFCONFIG lo 127.0.0.1
  254. /$ROUTE add -net 127.0.0.0
  255.  
  256. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  257. # eth0 interface. If you're only using loopback or SLIP, don't include the
  258. # rest of the lines in this file.
  259.  
  260. # Edit for your setup.
  261. IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  262. NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  263. NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  264. BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  265.             # have one. If not, leave blank and edit below.
  266. GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  267.  
  268. # Uncomment ONLY ONE of the three lines below. If one doesn't work, try again.
  269. # /$IFCONFIG eth0 \${IPADDR} netmask \${NETMASK} broadcast \${BROADCAST}
  270. /$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  271. # /$IFCONFIG  eth0 \${IPADDR} netmask \${NETMASK} 
  272.  
  273. # Uncomment these to set up your IP routing table.
  274. /$ROUTE add -net \${NETWORK} netmask \${NETMASK}
  275. /$ROUTE add default gw \${GATEWAY} metric 1
  276.  
  277. # End of rc.inet1
  278. EOF
  279.   chmod 755 $RC
  280.  else # we are only using loopback
  281.   /bin/cat <<EOF >$RC
  282. #! /bin/sh
  283. #
  284. # rc.inet1    This shell script boots up the base INET system.
  285. #
  286. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  287. #
  288.  
  289. HOSTNAME=\`cat /etc/HOSTNAME\`
  290.  
  291. # Attach the loopback device.
  292. /$IFCONFIG lo 127.0.0.1
  293. /$ROUTE add -net 127.0.0.0
  294.  
  295. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  296. # eth0 interface. If you're only using loopback or SLIP, don't include the
  297. # rest of the lines in this file.
  298.  
  299. # Edit for your setup.
  300. #IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  301. #NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  302. #NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  303. #BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  304.             # have one. If not, leave blank and edit below.
  305. #GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  306.  
  307. # Uncomment ONLY ONE of the three lines below. If one doesn't work, try again.
  308. # /$IFCONFIG eth0 \${IPADDR} netmask \${NETMASK} broadcast \${BROADCAST}
  309. #/$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  310. # /$IFCONFIG  eth0 \${IPADDR} netmask \${NETMASK} 
  311.  
  312. # Uncomment these to set up your IP routing table.
  313. #/$ROUTE -n add \${NETWORK} netmask \${NETMASK}
  314. #/$ROUTE add default gw \${GATEWAY} metric 1
  315.  
  316. # End of rc.inet1
  317. EOF
  318.   chmod 755 $RC
  319.  fi # write out the script
  320. fi # only alter if it already exists
  321. #
  322. ############################################################################
  323. #              The networks file.
  324. ############################################################################
  325. #
  326. if [ -f $ETCNETWORKS ]; then cp $ETCNETWORKS tmp/`basename $ETCNETWORKS`.OLD;fi
  327. echo "Creating /$ETCNETWORKS..."
  328. /bin/cat <<EOF >$ETCNETWORKS
  329. #
  330. # networks    This file describes a number of netname-to-address
  331. #        mappings for the TCP/IP subsystem.  It is mostly
  332. #        used at boot time, when no name servers are running.
  333. #
  334.  
  335. loopback    127.0.0.0
  336. localnet    $NETWORK
  337.  
  338. # End of networks.
  339. EOF
  340. chmod 644 $ETCNETWORKS
  341. #
  342. ############################################################################
  343. #               The hosts file.
  344. ############################################################################
  345. #
  346. echo "Creating /$HOSTS..."
  347. if [ -f $HOSTS ];then cp $HOSTS tmp/`basename $HOSTS`.OLD;fi
  348. /bin/cat <<EOF >$HOSTS
  349. #
  350. # hosts        This file describes a number of hostname-to-address
  351. #        mappings for the TCP/IP subsystem.  It is mostly
  352. #        used at boot time, when no name servers are running.
  353. #        On small systems, this file can be used instead of a
  354. #        "named" name server.  Just add the names, addresses
  355. #        and any aliases to this file...
  356. #
  357. # By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
  358. # should NEVER be named with the name of the machine.  It causes problems
  359. # for some (stupid) programs, irc and reputedly talk. :^)
  360. #
  361.  
  362. # For loopbacking.
  363. 127.0.0.1    localhost
  364. $IPADDR     $HOSTNAME.$DOMAIN $HOSTNAME
  365.  
  366. # End of hosts.
  367. EOF
  368. chmod 644 $HOSTS
  369. #
  370. ##########################################################################
  371. # The Smail 3.1.28 configuration file 
  372. ##########################################################################
  373. #
  374. #mkdir -p `dirname $SMAIL`
  375. #if [ -f $SMAIL ];then 
  376. # cp $SMAIL tmp/`basename $SMAIL`.OLD
  377. #fi
  378. #echo "Creating /$SMAIL..."
  379. #/bin/cat <<EOF >$SMAIL
  380. ##
  381. ##    smail configuration for $HOSTNAME
  382. ## (see smail(5) man page for details and other options)
  383. ##
  384. #-smtp_debug
  385. #hostname=$HOSTNAME.$DOMAIN
  386. #visible_domain=$DOMAIN
  387. #more_hostnames=$HOSTNAME.$DOMAIN
  388. #postmaster=postmaster
  389. #smtp_accept_max=10
  390. #EOF
  391. #echo 'smtp_banner="$primary_name Linux Smail$version #$compile_num ready at $date"' >> $SMAIL
  392. #echo 'received_field="Received: \' >> $SMAIL
  393. #echo '    ${if def:sender_host \' >> $SMAIL
  394. #echo '        {from $sender_host by $primary_name \' >> $SMAIL
  395. #echo '        ${if def:sender_proto: with $sender_proto}\' >> $SMAIL
  396. #echo '        \n\t(Linux Smail$version #$compile_num) }\' >> $SMAIL
  397. #echo '    else{by $primary_name ${if def:sender_proto:with $sender_proto }\' >> $SMAIL
  398. #echo '        (Linux Smail$version #$compile_num)\n\t}}\' >> $SMAIL
  399. #echo '    id $message_id; $spool_date"' >> $SMAIL
  400. #chmod 644 $SMAIL
  401. ##
  402. ############################################################################
  403. # The ELM rc file
  404. ############################################################################
  405. #
  406. mkdir -p `dirname $ELMRC`
  407. if [ -f $ELMRC ];then
  408.  cp $ELMRC tmp/`basename $ELMRC`.OLD
  409. fi
  410. echo "Creating /$ELMRC..."
  411. /bin/cat <<EOF >$ELMRC
  412. #------------------------ global elm.rc file ------------------
  413. #
  414. # this expects any global aliases in /usr/lib/aliases.text
  415. #
  416. # you probably also want to set the visible_name parameter in 
  417. # /usr/lib/smail/config if you use smail3.1.28
  418. #
  419. # this is the unqualified hostname
  420. #
  421. hostname = $HOSTNAME
  422. #
  423. # this is the local domain
  424. #
  425. hostdomain = .$DOMAIN
  426. #
  427. # this is the fully qualified hostname
  428. #
  429. hostfullname = $HOSTNAME.$DOMAIN
  430. EOF
  431. chmod 644 $ELMRC
  432. #
  433. ############################################################################
  434. #            The resolv.conf file.
  435. ############################################################################
  436. #
  437. if [ "$LOOPBACK" = "n" ]; then
  438.  echo
  439.  echo -n "Will you be accessing a nameserver ([y]es, [n]o)? "
  440.  read NAMESV;
  441.  if [ "$NAMESV" = "y" -o "$NAMESV" = "Y" ]; then
  442.   cat << EOF
  443. Here is your current IP address, full hostname, and base hostname:
  444. $IPADDR       $HOSTNAME.$DOMAIN    $HOSTNAME
  445.  
  446. Please give the IP address of the name server to use. 
  447. You can add more Domain Name Servers by editing /$RESOLV.
  448.  
  449. EOF
  450.   while [ "$NAMESERVER" = "" ]; do
  451.    echo -n "Name Server for domain $DOMAIN (aaa.bbb.ccc.ddd): "
  452.    read NAMESERVER
  453.   done
  454.  
  455.   if [ -f $RESOLV ]; then cp $RESOLV tmp/`basename $RESOLV`.OLD;fi
  456.   echo "domain $DOMAIN" >$RESOLV
  457.   echo "nameserver $NAMESERVER" >>$RESOLV
  458.  else
  459.   echo "domain $DOMAIN" >$RESOLV
  460.  fi
  461. fi
  462. if [ "$LOOPBACK" = "n" ]; then chmod 644 $RESOLV ;fi
  463. #
  464. ############################################################################
  465. #             Change permissions and exit.
  466. ############################################################################
  467. #
  468. chown root.root $HOSTS $RESOLV $RC
  469. chmod 644 $HOSTS $RESOLV
  470. chmod 754 $RC
  471.  
  472. cat << EOF
  473.  
  474. Your networking software has now been configured. 
  475.  
  476. EOF
  477.