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