bindsetup.sh
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· Shell 代码 · 共 1,811 行 · 第 1/3 页
SH
1,811 行
#!/bin/sh# @(#)bindsetup.sh 4.4 (ULTRIX) 2/14/91# # Copyright (c) 1988 - 1990 by# Digital Equipment Corporation, Maynard, MA # All rights reserved. # # This software is furnished under a license and may be used and # copied only in accordance with the terms of such license and # with the inclusion of the above copyright notice. This # software or any other copies thereof may not be provided or # otherwise made available to any other person. No title to and # ownership of the software is hereby transferred. # # The information in this software is subject to change without # notice and should not be construed as a commitment by Digital # Equipment Corporation. # # Digital assumes no responsibility for the use or reliability # of its software on equipment which is not supplied by Digital. ## Purpose: Set up Berkeley Internet Name Domain (BIND) and Hesiod# Usage: bindsetup# Environment: Bourne shell script# # Remarks:# Sets up files:# /etc/hosts# /etc/sendmail.cf# /etc/resolv.conf# /etc/hesiod.conf# /etc/rc.local# /var/dss/namedb/named.boot# /var/dss/namedb/named.ca# /var/dss/namedb/named.local# /var/dss/namedb/named.hosts# /var/dss/namedb/named.rev### Modification History:## 17-Feb-88 logcher# This script sets up a BIND Client interactively# and silently (diskless setup) modifying /etc/svcorder,# /etc/resolv.conf, and /etc/rc.local with the complete # (hostname+binddomain). For a BIND Primary or Secondary Server# setup, it sets up the /etc/svcorder, /etc/rc.local with the new# hostname plus the named, and /etc/named.boot file after interactive# queries and then asks the user to set up the remaining BIND data# files and points to the Network Manager's Guide.## 08-Mar-88 logcher# Modifications after Documentation looked at script output# plus a bug (: => ;) fix and other cleanup.## 16-Mar-88 logcher# Changed a few comments on the RESOLVC and NAMEDBO files to remain# consistent with the comments in the default /etc/namedb files on# kit.## 31-Mar-88 logcher# Removed code that asks for the reverse network number for servers# and instead use some dms code and call a c program, revnetnum,# so that the reverse network number is extracted from the system# per smu-02198.## 14-Apr-88 logcher# Changed references of Remote Server to Client. Added local to# $SVCORDER file as well as adding full hostname to $HOSTS per# smu-02244. Fixed bug in grep for "bind" or "BIND" to include# a "^" character. Allow for multiple servers on client setup,# both interactively and silently. Put in missing setup for# caching only and slave servers.## 26-Apr-88 logcher# Changes needed to use bindsetup -c ... for diskless client /# BIND client setup. Needed to add an argument that contained# the directory path of the root filesystem, CLIENTROOT.## 08-Jun-88 logcher# Moved the editing of /etc/svcorder to the end of the script so# that in a server configuration the local service is the only one# defined for the "arp" command and thus avoids the time-out period# for a non-active bind entry.## 13-Jun-88 logcher# Put the "verbose" check on the /etc/svcorder message for diskless# addition.## 01-Dec-88 logcher# Added Donnie Cherng's fix that uses netmasks to get the network# number.## 24-Feb-89 logcher# Bug fixes from u32_qar 640, v24_qar 781, pmax_bar 379.# Check if NAMEDDIR is a file and loop. If not a directory,# then mkdir it. Change ed to cat because of 64 char limit# on ed pathnames. Changed other ed's to cd to the directory.# Added code to cleanup old files if changing configuration# If server to client, remove BIND stuff from RCFILE and remove# NAMEDPID file. If client to server, mv RESOLVC to RESOLVC.old. ## 28-Feb-89 logcher# This is the real bug fix for u32_qar 640. When configuring a# client, check if arg is a directory. If not, check if first# character in arg is a "/". If so, print a message that not a# directory and exit. Else, it is assumed that there is no client# root directory and arg is assumed to be the domain name.## 08-Mar-89 logcher# Added umask 022 to make sure a user can read necessary files,# like resolv.conf.## 09-May-89 logcher# Removed all code that modifies the hostname. A RESOLVC file is# now required for all configurations with at least the "domain"# entry. This change is in conjuction with the gethostent change# that strips of the local domain, if it exists. Added code to make# the NAMEDLO and NAMEDCA files and start secondary and slave servers# up automatically. Removed caching only server from list since it's# meaning is very little. Removed code that calls revnetnum(). Only# need network number, not network number plus subnets.## 24-Jul-89 sue# Added code to automatically setup all configurations.## 03-Aug-89 sue# Set auto to y for automatic named startup and only ask if auto# setup is desired if auto is y. Check if# /var/dss/namedb/src/hosts is a file before trying to manipulate# it. Change name of sri-nic.arpa. to nic.ddn.mil. per mail from# Win Treese.## 16-Aug-89 sue# Brought back caching server setup. It does have meaning.# Removed forwarding server from primary and secondary.# Changed the names of the hosts databases to hosts.db and# hosts.rev. Removed setup for these files. It is now performed # in /var/dss/namedb/bin/make_hosts which is run when setting up a# primary server. Added Hesiod setup to primary and secondary.## 22-Aug-89 sue# Added Kerberos questions to setup. Can only be used in# conjuction with Kerberos setup which is manually right now.## 19-Sep-89 sue# Added code to the primary server setup to check if a passwd# file exists in the src directory and then add code to the # RCFILE and start the hesupd automatically.## 04-Oct-89 sue# Added cache files to the secondary server named.boot file.# Fixed incorrect names in named.ca.## 13-Nov-89 sue# Added code to modify the $SENDMAIL file with the domain name.## 12-Dec-89 sue# Modified the silent client command line input. Now conforms to# that of svcsetup. Do checking for the $CLIENTROOT$HOSTS file in# silent client mode. Check and see if diskless client was a # server once before and remove lines from $CLIENTROOT$RCFILE.# Add example domain name in prompt. Added more specifics to# greps. Really brought back caching server.## 07-Feb-90 sue# Check to see if user added a dot at the end of the domain name.# If so, remove it. Loop for more than one Kerberos server, and# add to /etc/hosts if not there already. Bring back the long# hostname setup. Setting /bin/hostname, and changing# /etc/rc.local.## 28-Feb-90 sue# Updated the root name servers in named.ca; re mail from Win.## 17-Jul-90 sue# Updated the root name servers in named.ca; re mail from Win.## 15-Oct-90 sue# Added a "cd /" before changing the .$SENDMAIL and .$RCFILE# files if $CLIENTROOT is null.# filescase $1 inDEBUG) shift DEBUG=1 RCFILE=/tmp/rc.local HOSTS=/tmp/hosts SENDMAIL=/tmp/sendmail.cf HESIOD=/tmp/hesiod.conf RESOLVC=/tmp/resolv.conf SVC=/tmp/svc.conf SVCORDER=/tmp/svcorder NAMEDBO=/tmp/named.boot NAMEDPID=/tmp/named.pidecho "Running in DEBUG mode ..." ;;*) RCFILE=/etc/rc.local HOSTS=/etc/hosts SENDMAIL=/etc/sendmail.cf HESIOD=/etc/hesiod.conf RESOLVC=/etc/resolv.conf SVC=/etc/svc.conf SVCORDER=/etc/svcorder NAMEDBO=/var/dss/namedb/named.boot NAMEDPID=/etc/named.pid ;;esac## Default named file locations#NAMEDDIR=/var/dss/namedbNAMEDSRC=$NAMEDDIR/srcNAMEDBIN=$NAMEDDIR/binNAMEDLO=named.localNAMEDCA=named.caNAMEDHO=hosts.dbNAMEDRE=hosts.revHO=hostsDATABASES="aliases auth group hosts networks passwd protocols rpc services"KRBFLAGS=DOM=domainSVCSETUP=/usr/etc/svcsetup## Other declarations#umask 022CLIENTROOT=""RESTMP=/tmp/resolv.tmp.$$HOSTSTMP=/tmp/hosts.tmp.$$BINDTMP=/tmp/bindsetup.tmp.$$RCTMP=/tmp/bindsetup.rc.$$HOSTNAME=/bin/hostnameNULL=/dev/null# definesLOCAL_KEY="echo -n 'local daemons:'"BINDSTART_KEY="# %BINDSTART% - BIND daemon added by \"bindsetup\""BINDEND_KEY="# %BINDEND%"NFSSTART_KEY="# %NFSSTART% - NFS daemons added by \"nfssetup\""PATH=$PATH:$NAMEDDIRexport PATHtypeserver=""server=""slash=""PRINTMAIL=""PRINTRC="y"PRINTHO="y"verbose=yfirst_time=yscratch_maps=yauto=y## Set up interrupt handlers:#QUIT=' if [ -r $RESTMP ] then rm $RESTMP fi if [ -r $HOSTSTMP ] then rm $HOSTSTMP fi if [ -r $BINDTMP ] then rm $BINDTMP fi if [ -r $RCTMP ] then rm $RCTMP fi echo "bindsetup terminated with no installations made." exit 1'## Trap ^c signal, etc.#trap 'eval "$QUIT"' 1 2 3 15## PHASE ONE: Gather data!!#if [ -n "$1" ]then # # Require it to be run by root # if [ \! -w $RCFILE ] then exit 1 fi # # Run fast and silent for DMS client setup. # case $1 in -c) verbose="" typeserver=c shift ;; *) echo "usage: bindsetup [ -c [ -d directory ] -b binddomain name1,ip1 name2,ip2 ... ]" eval "$QUIT" ;; esac while [ -n "$1" ] do case $1 in -d) shift if [ -d $1 ] then CLIENTROOT=$1 shift else echo "$1 is not a directory." eval "$QUIT" fi ;; -b) shift if [ -n "$1" ] then binddomain=$1 echo $binddomain | egrep -s "\.$" if [ $? -eq 0 ] then binddomain=`echo $binddomain | sed s/\.$//` fi shift fi ;; *) name=`echo $1 | awk -F, '{print $1}'` number=`echo $1 | awk -F, '{print $2}'` if [ -z "$name" -o -z "$number" ] then echo "name,ip argument is improperly formatted" echo "usage: bindsetup [ -c [ -d directory ] -b binddomain name1,ip1 name2,ip2 ... ]" eval "$QUIT" else echo "nameserver $number" >> $RESTMP if [ -f $CLIENTROOT$HOSTS ] then egrep -s "[ ]$name" $CLIENTROOT$HOSTS if [ $? -ne 0 ] then name=`echo $name | sed s/.$binddomain//` echo "$number $name.$binddomain $name # BIND Server" >> $HOSTSTMP fi else echo "$CLIENTROOT$HOSTS is not a file." eval "$QUIT" fi shift fi ;; esac done egrep -s "$BINDSTART_KEY" $CLIENTROOT$RCFILE if [ $? -eq 0 ] then egrep -s "$BINDEND_KEY" $CLIENTROOT$RCFILE if [ $? -eq 0 ] then first_time="" fi fifiif [ $verbose ]then # # Require it to be run by root # if [ \! -w $RCFILE ] then echo "Su to root first." eval "$QUIT" fi # # Be sure network has already been set up, and this system has # a name!! # hname=`$HOSTNAME` if [ $? -ne 0 ] then echo "Bring the system to multi-user mode before running bindsetup." eval "$QUIT" fi echo -n "The bindsetup command allows you to add, modify, or remove aconfiguration of the Berkeley Internet Name Domain (BIND) Server onyour system. BIND is a network naming service that enables serversto name resources or objects and share information with other objectson the network." echo "The bindsetup command takes you through the configuration process toset the default BIND domain name of your system, determine the typeof server or client, and construct the BIND database files for thisBIND domain. Default answers are shown in square brackets ([]). Touse a default answer, press the RETURN key.[ Press the RETURN key to continue ]: " read junk done= while test -z "$done" do echo " Berkeley Internet Name Domain (BIND) Action Menu for Configuration Add => a Modify => m Remove => r Exit => e" echo echo -n "Enter your choice [a]: " read action case $action in A|a|M|m|R|r|e|E|"") done=done;; esac done case $action in [AaMm]|"") # # See if this is a re-install # egrep -s "$BINDSTART_KEY" $RCFILE if [ $? -eq 0 ] then egrep -s "$BINDEND_KEY" $RCFILE if [ $? -ne 0 ] then echo "The BIND environment for this host has already been installed butcan not be reconfigured automatically. To change the current BINDconfiguration, edit the file $RCFILE to remove the old BINDenvironment and run bindsetup again." eval "$QUIT" fi echo "The BIND environment for this host has already been installed.Would you like to change the current BIND configuration?" again=y while [ $again ] do again="" echo -n "Enter \"y\" or \"n\" [no default]: " read ans case $ans in [yY]*) first_time="" ;; [nN]*) eval "$QUIT" ;; *) again=y ;; esac done fi # # Ask for the binddomain # echo "You must know the default BIND domain name for your site in order tocontinue the configuration process. The name "dec.com" is an exampleBIND domain name. If you do not know the name, contact your siteadministrator." answer=y while [ $answer ] do echo -n "Enter \"e\" to EXIT or \"c\" to CONTINUE [no default] ? " read ans case $ans in [cC]*) answer="" ;; [eE]*) eval "$QUIT" ;; *) ;; esac done if [ -f $RESOLVC ] then set xx `(grep "^$DOM" $RESOLVC)` if [ -n "$3" ] then binddomain=$3 fi fi if [ -z "$binddomain" ] then binddomain=`expr $hname : '[^.]*\.\(.*\)'` fi again=y while [ $again ] do echo -n "Enter the default BIND domain name [$binddomain]: " read ans case $ans in "") if [ $binddomain ] then again="" fi ;; *) again="" binddomain=$ans echo $binddomain | egrep -s "\.$" if [ $? -eq 0 ] then binddomain=`echo $binddomain | sed s/\.$//` fi ;; esac done done= while test -z "$done" do echo " Berkeley Internet Name Domain (BIND) Configuration Menu for domain \"${binddomain}\" Primary Server => p Secondary Server => s Caching Server => a Slave Server => l Client => c Exit => e" echo echo -n "Enter your choice [c]: " read typeserver case $typeserver in P|p|S|s|A|a|L|l|C|c|e|E|"") done=done;; esac done case $typeserver in [pP]) cp $NULL $RESTMP /bin/ls $NAMEDSRC > $BINDTMP if [ -s $BINDTMP ] then for i in `cat $BINDTMP` do for j in $DATABASES do if [ "$i" = "$j" ] then echo $i >> $RESTMP fi done done fi if [ -s $RESTMP ] then echo "Bindsetup has found the following files in $NAMEDSRC:" for i in `cat $RESTMP` do echo " $i" done answer=y while [ $answer ] do echo -n "Would you like bindsetup to convert the \"etc\" style source filesto the BIND/Hesiod database format? If you answer \"y\", the sourcefiles remain in $NAMEDSRC and BIND/Hesiod database will becreated in $NAMEDDIR. If you answer \"n\", the BIND/Hesioddatabase will not be created, but all other configuration files willbe created. (y/n) ? " read ans case $ans in [yY]*) auto=y answer="" ;; [nN]*)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?