home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 4.0 PR1 / NeXT_NEXTSTEP_4.0_PR1_(beta).rar / Openstep4-Pr1User.iso / private / etc / yp / ypinit < prev    next >
Text File  |  1995-09-05  |  7KB  |  348 lines

  1. #! /bin/sh
  2.  
  3. maps="bootparams ethers.byaddr ethers.byname group.bygid \
  4. group.byname group.byusr hosts.byaddr hosts.byname mail.aliases netgroup \
  5. netgroup.byuser netgroup.byhost networks.byaddr networks.byname \
  6. passwd.byname passwd.byuid protocols.byname protocols.bynumber \
  7. rpc.bynumber services.byname ypservers"
  8.  
  9. yproot_dir=/etc/yp
  10. yproot_exe=/usr/etc/yp
  11. hf=/tmp/ypinit.hostlist.$$
  12. XFR=${YPXFR-ypxfr}
  13.  
  14. masterp=F
  15. slavep=F
  16. host=""
  17. def_dom=""
  18. master=""
  19. got_host_list=F
  20. exit_on_error=F
  21. errors_in_setup=F
  22.  
  23. PATH=/bin:/usr/bin:/usr/etc:$yproot_exe:$PATH
  24. export PATH 
  25.  
  26. case $# in
  27. 1)    case $1 in
  28.     -m)    masterp=T;;
  29.     *)    echo 'usage:'
  30.         echo '    ypinit -m'
  31.         echo '    ypinit -s master_server'
  32.         echo ""
  33.         echo "\
  34. where -m is used to build a master yp server data base, and -s is used for"
  35.         echo "\
  36. a slave data base.  master_server must be an existing reachable yp server."
  37.         exit 1;;
  38.     esac;;
  39.  
  40. 2)    case $1 in
  41.     -s)    slavep=T; master=$2;;
  42.     *)    echo 'usage:'
  43.         echo '    ypinit -m'
  44.         echo '    ypinit -s master_server'
  45.         echo ""
  46.         echo "\
  47. where -m is used to build a master yp server data base, and -s is used for"
  48.         echo "\
  49. a slave data base.  master_server must be an existing reachable yp server."
  50.         exit 1;;
  51.     esac;;
  52.  
  53. *)    echo 'usage:'
  54.     echo '    ypinit -m'
  55.     echo '    ypinit -s master_server' 
  56.     echo ""
  57.     echo "\
  58. where -m is used to build a master yp server data base, and -s is used for"
  59.     echo "\
  60. a slave data base.  master_server must be an existing reachable yp server."
  61.     exit 1;;
  62. esac
  63.  
  64.  
  65. if [ $slavep = T ]
  66. then
  67.     maps=`ypwhich -m | egrep $master$| awk '{ printf("%s ",$1) }' -`
  68.     if [ -z "$maps" ]
  69.     then
  70.         echo "Can't enumerate maps from $master. Please check that it is running."
  71.         exit 1
  72.     fi
  73. fi
  74.  
  75. host=`hostname`
  76.  
  77. if [ $? -ne 0 ]
  78. then 
  79.     echo "Can't get local host's name.  Please check your path."
  80.     exit 1
  81. fi
  82.  
  83. if [ -z "$host" ]
  84. then
  85.     echo "The local host's name hasn't been set.  Please set it."
  86.     exit 1
  87. fi
  88.  
  89. def_dom=`domainname`
  90.  
  91. if [ $? -ne 0 ]
  92. then 
  93.     echo "Can't get local host's domain name.  Please check your path."
  94.     exit 1
  95. fi
  96.  
  97. if [ -z "$def_dom" ]
  98. then
  99.     echo "The local host's domain name hasn't been set.  Please set it."
  100.     exit 1
  101. fi
  102.  
  103. domainname $def_dom
  104.  
  105. if [ $? -ne 0 ]
  106. then 
  107.     echo "\
  108. You have to be the superuser to run this.  Please log in as root."
  109.     exit 1
  110. fi
  111.  
  112. if [ ! -d $yproot_dir -o -f $yproot_dir ]
  113. then
  114.     echo "\
  115. The directory $yproot_dir doesn't exist.  Restore it from the distribution."
  116.     exit 1
  117. fi
  118.  
  119. if [ $slavep = T ]
  120. then
  121.     if [ $host = $master ]
  122.     then
  123.         echo "\
  124. The host specified should be a running master yp server, not this machine."
  125.         exit 1
  126.     fi
  127. fi
  128.  
  129. if [ "$setup" != "yes" ]; then
  130.     echo "Installing the yp data base will require that you answer a few questions."
  131.     echo "Questions will all be asked at the beginning of the procedure."
  132.     echo ""
  133.     echo -n "Do you want this procedure to quit on non-fatal errors? [y/n: n]  "
  134.     read doexit
  135. else
  136.     doexit=yes
  137. fi
  138.  
  139. case $doexit in
  140. y*)    exit_on_error=T;;
  141. Y*)    exit_on_error=T;;
  142. *)    echo "\
  143. OK, please remember to go back and redo manually whatever fails.  If you"
  144.     echo "\
  145. don't, some part of the system (perhaps the yp itself) won't work.";;
  146. esac
  147.  
  148. echo ""
  149.  
  150. for dir in $yproot_dir/$def_dom
  151. do
  152.  
  153.     if [ -d $dir ]; then
  154.         if [ "$setup" != "yes" ]; then
  155.             echo -n "Can we destroy the existing $dir and its contents? [y/n: n]  "
  156.             read kill_old_dir
  157.         else 
  158.             kill_old_dir=yes
  159.         fi
  160.  
  161.         case $kill_old_dir in
  162.         y*)    rm -r -f $dir
  163.  
  164.             if [ $?  -ne 0 ]
  165.             then
  166.             echo "Can't clean up old directory $dir.  Fatal error."
  167.                 exit 1
  168.             fi;;
  169.  
  170.         Y*)    rm -r -f $dir
  171.  
  172.             if [ $?  -ne 0 ]
  173.             then
  174.             echo "Can't clean up old directory $dir.  Fatal error."
  175.                 exit 1
  176.             fi;;
  177.  
  178.         *)    echo "OK, please clean it up by hand and start again.  Bye"
  179.             exit 0;;
  180.         esac
  181.     fi
  182.  
  183.     mkdir $dir
  184.  
  185.     if [ $?  -ne 0 ]
  186.     then
  187.         echo "Can't make new directory $dir.  Fatal error."
  188.         exit 1
  189.     fi
  190.  
  191. done
  192.  
  193. if [ $slavep = T ]
  194. then
  195.  
  196.     echo "\
  197. There will be no further questions. The remainder of the procedure should take"
  198.     echo "a few minutes, to copy the data bases from $master."
  199.  
  200.     for dom in  $def_dom
  201.     do
  202.         for map in $maps
  203.         do
  204.             echo "Transferring $map..."
  205.             $XFR -h $master -c -d $dom $map
  206.  
  207.             if [ $?  -ne 0 ]
  208.             then
  209.                 errors_in_setup=T
  210.  
  211.                 if [ $exit_on_error = T ]
  212.                 then
  213.                     exit 1
  214.                 fi
  215.             fi
  216.         done
  217.     done
  218.  
  219.     echo ""
  220.     echo -n "${host}'s yellowpages data base has been set up"
  221.  
  222.     if [ $errors_in_setup = T ]
  223.     then
  224.         echo " with errors.  Please remember"
  225.         echo "to figure out what went wrong, and fix it."
  226.     else
  227.         echo " without any errors."
  228.     fi
  229.  
  230.     echo ""
  231.     echo "\
  232. At this point, make sure that /etc/passwd, /etc/hosts, /etc/networks,"
  233.     echo "\
  234. /etc/group, /etc/protocols, /etc/services/, /etc/rpc and /etc/netgroup have"
  235.     echo "\
  236. been edited so that when the yellow pages is activated, the data bases you"
  237.     echo "\
  238. have just created will be used, instead of the /etc ASCII files."
  239.  
  240.     exit 0
  241. else
  242.  
  243.     rm -f $yproot_dir/*.time
  244.  
  245.     while [ $got_host_list = F ]; do
  246.         echo $host >$hf
  247.         if [ "$setup" != "yes" ]; then
  248.             echo ""
  249.             echo "\
  250.     At this point, we have to construct a list of the hosts which will run yp"
  251.             echo "\
  252.     servers.  $host is in the list of yp server hosts.  Please continue to add"
  253.             echo "\
  254.     the names for the other hosts, one per line.  When you are done with the"
  255.             echo "list, type a <control D>."
  256.             echo "    next host to add:  $host"
  257.             echo -n "    next host to add:  "
  258.  
  259.             while read h
  260.             do
  261.                 echo -n "    next host to add:  "
  262.                 echo $h >>$hf
  263.             done
  264.  
  265.             echo ""
  266.             echo "The current list of yp servers looks like this:"
  267.             echo ""
  268.  
  269.             cat $hf
  270.             echo ""
  271.             echo -n "Is this correct?  [y/n: y]  "
  272.             read hlist_ok
  273.  
  274.             case $hlist_ok in
  275.             n*)    got_host_list=F
  276.                 echo "Let's try the whole thing again...";;
  277.             N*)    got_host_list=F
  278.                 echo "Let's try the whole thing again...";;
  279.             *)    got_host_list=T;;
  280.             esac
  281.         else 
  282.             got_host_list=T
  283.         fi
  284.     done
  285.  
  286.     echo "\
  287. There will be no further questions. The remainder of the procedure should take"
  288.     echo "5 to 10 minutes."
  289.  
  290.     echo "Building $yproot_dir/$def_dom/ypservers..."
  291.     $yproot_exe/makedbm $hf $yproot_dir/$def_dom/ypservers
  292.  
  293.     if [ $?  -ne 0 ]
  294.     then
  295.         echo "\
  296. Couldn't build yp data base $yproot_dir/ypservers."
  297.         errors_in_setup=T
  298.  
  299.         if [ $exit_on_error = T ]
  300.         then
  301.             exit 1
  302.         fi
  303.     fi
  304.  
  305.     rm $hf
  306.  
  307.     in_pwd=`pwd`
  308.     cd $yproot_dir
  309.     echo -n "Running "
  310.     echo -n $yproot_dir
  311.     echo "/Makefile..."
  312.     make NOPUSH=1 
  313.  
  314.     if [ $?  -ne 0 ]
  315.     then
  316.         echo "\
  317. Error running Makefile."
  318.         errors_in_setup=T
  319.         
  320.         if [ $exit_on_error = T ]
  321.         then
  322.             exit 1
  323.         fi
  324.     fi
  325.  
  326.     cd $in_pwd
  327.     echo ""
  328.     echo -n "\
  329. $host has been set up as a yp master server"
  330.  
  331.     if [ $errors_in_setup = T ]
  332.     then
  333.         echo " with errors.  Please remember"
  334.         echo "to figure out what went wrong, and fix it."
  335.     else
  336.         echo " without any errors."
  337.     fi
  338.  
  339.     echo ""
  340.     echo "\
  341. If there are running slave yp servers, run yppush now for any data bases"
  342.     echo "\
  343. which have been changed.  If there are no running slaves, run ypinit on"
  344.     echo "\
  345. those hosts which are to be slave servers."
  346.  
  347. fi
  348.