Home | History | Annotate | Line # | Download | only in ypinit
ypinit.sh revision 1.2
      1  1.1  thorpej #!/bin/sh
      2  1.1  thorpej #
      3  1.1  thorpej #	$NetBSD: ypinit.sh,v 1.2 1996/08/09 15:09:04 thorpej Exp $
      4  1.1  thorpej #
      5  1.1  thorpej # ypinit.sh - setup a master or slave YP server
      6  1.1  thorpej #
      7  1.1  thorpej # Originally written by Mats O Jansson <moj (at] stacken.kth.se>
      8  1.1  thorpej # Modified by Jason R. Thorpe <thorpej (at] NetBSD.ORG>
      9  1.1  thorpej #
     10  1.1  thorpej 
     11  1.1  thorpej DOMAINNAME=/bin/domainname
     12  1.1  thorpej HOSTNAME=/bin/hostname
     13  1.1  thorpej YPWHICH=/usr/bin/ypwhich
     14  1.1  thorpej YPXFR=/usr/sbin/ypxfr
     15  1.1  thorpej MAKEDBM=/usr/sbin/makedbm
     16  1.1  thorpej YP_DIR=/var/yp
     17  1.1  thorpej 
     18  1.1  thorpej ERROR=USAGE				# assume usage error
     19  1.1  thorpej 
     20  1.2  thorpej if [ $# -eq 1 ]; then
     21  1.2  thorpej 	if [ $1 = "-m" ]; then		# ypinit -m
     22  1.1  thorpej 		DOMAIN=`${DOMAINNAME}`
     23  1.1  thorpej 		SERVERTYPE=MASTER
     24  1.1  thorpej 		ERROR=
     25  1.1  thorpej 	fi
     26  1.1  thorpej fi
     27  1.1  thorpej 
     28  1.2  thorpej if [ $# -eq 2 ]; then
     29  1.2  thorpej 	if [ $1 = "-m" ]; then		# ypinit -m domainname
     30  1.1  thorpej 		DOMAIN=${2}
     31  1.1  thorpej 		SERVERTYPE=MASTER
     32  1.1  thorpej 		ERROR=
     33  1.1  thorpej 	fi
     34  1.2  thorpej 	if [ $1 = "-s" ]; then		# ypinit -s master_server
     35  1.1  thorpej 		DOMAIN=`${DOMAINNAME}`
     36  1.1  thorpej 		SERVERTYPE=SLAVE
     37  1.1  thorpej 		MASTER=${2}
     38  1.1  thorpej 		ERROR=
     39  1.1  thorpej 	fi
     40  1.1  thorpej fi
     41  1.1  thorpej 
     42  1.2  thorpej if [ $# -eq 3 ]; then
     43  1.2  thorpej 	if [ $1 = "-s" ]; then		# ypinit -s master_server domainname
     44  1.1  thorpej 		DOMAIN=${3}
     45  1.1  thorpej 		SERVERTYPE=SLAVE
     46  1.1  thorpej 		MASTER=${2}
     47  1.1  thorpej 		ERROR=
     48  1.1  thorpej 	fi
     49  1.1  thorpej fi
     50  1.1  thorpej 
     51  1.2  thorpej if [ X${ERROR} = X"USAGE" ]; then
     52  1.1  thorpej 	cat << \__usage 1>&2
     53  1.1  thorpej usage: ypinit -m [domainname]
     54  1.1  thorpej        ypinit -s master_server [domainname]
     55  1.1  thorpej 
     56  1.1  thorpej The `-m' flag builds a master YP server, and the `-s' flag builds
     57  1.1  thorpej a slave YP server.  When building a slave YP server, `master_server'
     58  1.1  thorpej must be an existing, reachable YP server.
     59  1.1  thorpej __usage
     60  1.1  thorpej 
     61  1.1  thorpej 	exit 1
     62  1.1  thorpej fi
     63  1.1  thorpej 
     64  1.1  thorpej # Check if domainname is set, don't accept an empty domainname
     65  1.2  thorpej if [ X${DOMAIN} = "X" ]; then
     66  1.1  thorpej 	cat << \__no_domain 1>&2
     67  1.1  thorpej The local host's YP domain name has not been set.  Please set it with
     68  1.1  thorpej the domainname(8) command or pass the domain as an argument to ypinit(8).
     69  1.1  thorpej __no_domain
     70  1.1  thorpej 
     71  1.1  thorpej 	exit 1
     72  1.1  thorpej fi
     73  1.1  thorpej 
     74  1.1  thorpej # Check if hostname is set, don't accept an empty hostname
     75  1.1  thorpej HOST=`${HOSTNAME}`
     76  1.2  thorpej if [ X${HOST} = "X" ]; then
     77  1.1  thorpej 	cat << \__no_hostname 1>&2
     78  1.1  thorpej The local host's hostname has not been set.  Please set it with the
     79  1.1  thorpej hostname(8) command.
     80  1.1  thorpej __no_hostname
     81  1.1  thorpej 
     82  1.1  thorpej 	exit 1
     83  1.1  thorpej fi
     84  1.1  thorpej 
     85  1.1  thorpej # Check if the YP directory exists.
     86  1.1  thorpej if [ ! -d ${YP_DIR} -o -f ${YP_DIR} ]
     87  1.1  thorpej then
     88  1.1  thorpej 	echo "The directory ${YP_DIR} does not exist.  Restore it from the distribution." 1>&2
     89  1.1  thorpej 	exit 1
     90  1.1  thorpej fi
     91  1.1  thorpej 
     92  1.2  thorpej echo -n "Server type: ${SERVERTYPE} Domain: ${DOMAIN}"
     93  1.2  thorpej if [ X${SERVERTYPE} = X"SLAVE" ]; then
     94  1.2  thorpej 	echo -n " Master: ${MASTER}"
     95  1.2  thorpej fi
     96  1.2  thorpej echo ""
     97  1.1  thorpej cat << \__notice1
     98  1.1  thorpej 
     99  1.1  thorpej Installing the YP data base will require that you answer a few questions.
    100  1.1  thorpej Questions will all be asked at the beginning of the procedure.
    101  1.1  thorpej 
    102  1.1  thorpej __notice1
    103  1.1  thorpej 
    104  1.2  thorpej if [ -d "${YP_DIR}/${DOMAIN}" ]; then
    105  1.1  thorpej 	echo -n "Can we destroy the existing ${YP_DIR}/${DOMAIN} and its contents? [y/n: n]  "
    106  1.1  thorpej 	read KILL
    107  1.1  thorpej 
    108  1.1  thorpej 	ERROR=
    109  1.1  thorpej 	case ${KILL} in
    110  1.2  thorpej 	y*|Y*)
    111  1.2  thorpej 		ERROR="DELETE"
    112  1.1  thorpej 		;;
    113  1.1  thorpej 
    114  1.1  thorpej 	*)
    115  1.1  thorpej 		ERROR=
    116  1.1  thorpej 		;;
    117  1.1  thorpej 	esac
    118  1.1  thorpej 
    119  1.2  thorpej 	if [ X${ERROR} = X"DELETE" ]; then
    120  1.2  thorpej 		if ! rm -rf ${YP_DIR}/${DOMAIN}; then
    121  1.1  thorpej 			echo "Can't clean up old directory ${YP_DIR}/${DOMAIN}." 1>&2
    122  1.1  thorpej 			exit 1
    123  1.1  thorpej 		fi
    124  1.2  thorpej 	else
    125  1.2  thorpej 		echo "OK, please clean it up by hand and start again."
    126  1.2  thorpej 		exit 0
    127  1.1  thorpej 	fi
    128  1.1  thorpej fi
    129  1.1  thorpej 
    130  1.2  thorpej if ! mkdir "${YP_DIR}/${DOMAIN}"; then
    131  1.1  thorpej 	echo "Can't make new directory ${YP_DIR}/${DOMAIN}." 1>&2
    132  1.1  thorpej 	exit 1
    133  1.1  thorpej fi
    134  1.1  thorpej 
    135  1.2  thorpej if [ X${SERVERTYPE} = X"MASTER" ]; then
    136  1.1  thorpej 	if [ ! -f ${YP_DIR}/Makefile ];	then
    137  1.1  thorpej 		if [ ! -f ${YP_DIR}/Makefile.main ]; then
    138  1.1  thorpej 			echo "Can't find ${YP_DIR}/Makefile.main. " 1>&2
    139  1.1  thorpej 			exit 1
    140  1.1  thorpej 		fi
    141  1.1  thorpej 		cp ${YP_DIR}/Makefile.main ${YP_DIR}/Makefile
    142  1.1  thorpej 	fi
    143  1.1  thorpej 
    144  1.1  thorpej 	SUBDIR=`grep "^SUBDIR=" ${YP_DIR}/Makefile`
    145  1.1  thorpej 
    146  1.2  thorpej 	if [ X"${SUBDIR}" = "X" ]; then
    147  1.1  thorpej 		echo "Can't find line starting with 'SUBDIR=' in ${YP_DIR}/Makefile. " 1>&2
    148  1.1  thorpej 		exit 1
    149  1.1  thorpej 	fi
    150  1.1  thorpej 
    151  1.1  thorpej 	NEWSUBDIR="SUBDIR="
    152  1.1  thorpej 	for DIR in `echo ${SUBDIR} | cut -c8-255`; do
    153  1.1  thorpej 		if [ ${DIR} != ${DOMAIN} ]; then
    154  1.1  thorpej 			NEWSUBDIR="${NEWSUBDIR} ${DIR}"
    155  1.1  thorpej 		fi
    156  1.1  thorpej 	done
    157  1.1  thorpej 	NEWSUBDIR="${NEWSUBDIR} ${DOMAIN}"
    158  1.1  thorpej 
    159  1.1  thorpej 	if [ -f ${YP_DIR}/Makefile.tmp ]; then 
    160  1.1  thorpej 		rm ${YP_DIR}/Makefile.tmp
    161  1.1  thorpej 	fi
    162  1.1  thorpej 
    163  1.1  thorpej 	mv ${YP_DIR}/Makefile ${YP_DIR}/Makefile.tmp
    164  1.1  thorpej 	sed -e "s/^${SUBDIR}/${NEWSUBDIR}/" ${YP_DIR}/Makefile.tmp > \
    165  1.1  thorpej 	    ${YP_DIR}/Makefile
    166  1.1  thorpej 	rm ${YP_DIR}/Makefile.tmp
    167  1.1  thorpej 
    168  1.1  thorpej 	if [ ! -f ${YP_DIR}/Makefile.yp ]; then
    169  1.1  thorpej 		echo "Can't find ${YP_DIR}/Makefile.yp." 1>&2
    170  1.1  thorpej 		exit 1
    171  1.1  thorpej 	fi
    172  1.1  thorpej 
    173  1.1  thorpej 	cp ${YP_DIR}/Makefile.yp ${YP_DIR}/${DOMAIN}/Makefile
    174  1.1  thorpej 
    175  1.1  thorpej 	# Create an empty `ypservers' map so that yppush won't
    176  1.1  thorpej 	# lose when we run "make".
    177  1.1  thorpej 	(
    178  1.1  thorpej 		cd ${YP_DIR}/${DOMAIN}
    179  1.1  thorpej 		touch ypservers
    180  1.1  thorpej 		cat ypservers | ${MAKEDBM} - ypservers
    181  1.1  thorpej 	)
    182  1.2  thorpej 
    183  1.2  thorpej 	echo "Done.  Be sure to run \`make' in /var/yp."
    184  1.1  thorpej fi
    185  1.1  thorpej 
    186  1.2  thorpej if [ X${SERVERTYPE} = X"SLAVE" ]; then
    187  1.1  thorpej 	echo ""
    188  1.1  thorpej 
    189  1.1  thorpej 	for MAP in `${YPWHICH} -d ${DOMAIN} -m | cut -d\  -f1`; do
    190  1.1  thorpej 		echo "Transfering ${MAP}..."
    191  1.2  thorpej 		if ! ${YPXFR} -h ${MASTER} -c -d ${DOMAIN} ${MAP}; then
    192  1.1  thorpej 			echo "Can't transfer map ${MAP}." 1>&2
    193  1.1  thorpej 			exit 1
    194  1.1  thorpej 		fi
    195  1.1  thorpej 	done
    196  1.1  thorpej 
    197  1.1  thorpej 	echo ""
    198  1.2  thorpej 	echo "Don't forget to update the \`ypservers' on ${MASTER}."
    199  1.1  thorpej 	exit 0
    200  1.1  thorpej fi
    201