]>
git.saurik.com Git - apple/network_cmds.git/blob - ypinit.tproj/ypinit.sh
2 # $Id: ypinit.sh,v 1.2 2002/03/26 14:38:48 epeyton Exp $
4 # ypinit.sh - setup an master or slave server.
6 DOMAINNAME
=/bin
/domainname
8 YPWHICH
=/usr
/bin
/ypwhich
11 MAKEDBM
=/usr
/sbin
/makedbm
18 ERROR
=USAGE
# assume usage error
22 if [ $1 = "-m" ] # ypinit -m
24 DOMAIN
=`${DOMAINNAME}`
29 if [ $1 = "-u" ] # ypinit -u
31 DOMAIN
=`${DOMAINNAME}`
39 if [ $1 = "-m" ] # ypinit -m domainname
46 if [ $1 = "-s" ] # ypinit -s master_server
48 DOMAIN
=`${DOMAINNAME}`
54 if [ $1 = "-u" ] # ypinit -u domainname
64 if [ $1 = "-s" ] # ypinit -s master_server domainname
73 if [ "${ERROR}" = "USAGE" ]; then
75 usage
: ypinit
-m [domainname
]
76 ypinit
-s master_server
[domainname
]
77 ypinit
-u [domainname
]
79 The
`-m' flag builds a master YP server, and the `-s' flag builds
80 a slave YP server. When building a slave YP server, `master_server'
81 must be an existing
, reachable YP server.
82 The
`-u' is for updating the ypservers map on a master server.
88 # Check if domainname is set, don't accept an empty domainname
89 if [ -z "${DOMAIN}" ]; then
90 cat << \__no_domain 1>&2
91 The local host's YP domain name has not been set. Please set it with
92 the domainname(8) command or pass the domain as an argument to ypinit(8).
98 # Check if hostname is set, don't accept an empty hostname
100 if [ -z "${HOST}" ]; then
101 cat << \__no_hostname 1>&2
102 The local host's hostname has not been set. Please set it with the
109 # Check if we have contact with master.
110 if [ "${SERVERTYPE}" = "SLAVE" ];
112 COUNT=`${YPWHICH} -d ${DOMAIN} -m 2>/dev
/null
| grep -i ${MASTER} | wc -l | tr -d " "`
113 if [ "$COUNT" = "0" ]
115 echo "Can't enumerate maps from ${MASTER}. Please check that it is running." 1>&2
120 # Check if user is root
122 if [ "${ID}" != "0" ]; then
123 echo "You have to be the superuser to run this. Please login as root." 1>&2
127 # Check if the YP directory exists.
129 if [ ! -d ${YP_DIR} -o -f ${YP_DIR} ]
131 echo "The directory ${YP_DIR} doesn't exist. Restore it from the distribution." 1>&2
136 echo -n "Server Type: ${SERVERTYPE} Domain: ${DOMAIN}"
137 if [ "${SERVERTYPE}" = "SLAVE" ]; then
138 echo -n " Master: ${MASTER}"
142 if [ "${SERVERTYPE}" != "UPDATE" ];
146 Creating an YP server will require that you answer a few questions.
147 Questions will all be asked at the beginning of the procedure.
151 echo -n "Do you want this procedure to quit on non-fatal errors? [y/n: n] "
161 echo "Ok, please remember to go back and redo manually whatever fails."
162 echo "If you don't, something might not work. "
166 if [ -d "${YP_DIR}/${DOMAIN}" ]; then
168 echo -n "Can we destroy the existing ${YP_DIR}/${DOMAIN} and its contents? [y/n: n] "
181 if [ "${ERROR}" = "DELETE" ]; then
182 if ! rm -rf ${YP_DIR}/${DOMAIN}; then
183 echo "Can't clean up old directory ${YP_DIR}/${DOMAIN}." 1>&2
187 echo "OK, please clean it up by hand and start again. Bye"
193 if ! mkdir "${YP_DIR}/${DOMAIN}"; then
194 echo "Can't make new directory ${YP_DIR}/${DOMAIN}." 1>&2
199 if [ "${SERVERTYPE}" = "MASTER" ];
202 if [ ! -f ${YP_DIR}/Makefile ]
204 if [ ! -f ${YP_DIR}/Makefile.main ]
206 echo "Can't find ${YP_DIR}/Makefile.main. " 1>&2
209 cp ${YP_DIR}/Makefile.main ${YP_DIR}/Makefile
212 SUBDIR=`grep "^SUBDIR=" ${YP_DIR}/Makefile
`
214 if [ -z "${SUBDIR}" ]
216 echo "Can't find line starting with 'SUBDIR=' in ${YP_DIR}/Makefile. " 1>&2
221 for DIR in `echo ${SUBDIR} | cut
-c8-255`; do
222 if [ ${DIR} != ${DOMAIN} ]; then
223 NEWSUBDIR="${NEWSUBDIR} ${DIR}"
226 NEWSUBDIR="${NEWSUBDIR} ${DOMAIN}"
228 if [ -f ${YP_DIR}/Makefile.tmp ]; then
229 rm ${YP_DIR}/Makefile.tmp
232 mv ${YP_DIR}/Makefile ${YP_DIR}/Makefile.tmp
233 sed -e "s/^${SUBDIR}/${NEWSUBDIR}/" ${YP_DIR}/Makefile.tmp > \
235 rm ${YP_DIR}/Makefile.tmp
237 if [ ! -f ${YP_DIR}/Makefile.yp ]; then
238 echo "Can't find ${YP_DIR}/Makefile.yp. " 1>&2
242 cp ${YP_DIR}/Makefile.yp ${YP_DIR}/${DOMAIN}/Makefile
246 if [ "${SERVERTYPE}" = "SLAVE" ];
249 echo "There will be no further questions. The remainder of the procedure"
250 echo "should take a few minutes, to copy the databases from ${MASTER}."
252 for MAP in `${YPWHICH} -d ${DOMAIN} -m | cut
-d\
-f1`
254 echo "Transfering ${MAP}..."
255 if ! ${YPXFR} -h ${MASTER} -c -d ${DOMAIN} ${MAP}; then
256 echo "Can't transfer map ${MAP}." 1>&2
258 if [ "${ERROR_EXIT}" = "YES" ]; then
265 if [ "${ERROR_EXISTS}" = "YES" ]; then
266 echo "${HOST} has been setup as an YP slave server with errors. " 1>&2
267 echo "Please remember fix any problem that occurred." 1>&2
269 echo "${HOST} has been setup as an YP slave server without any errors. "
272 echo "Don't forget to update map ypservers on ${MASTER}."
278 while [ "${LIST_OK}" = "NO" ];
281 if [ "${SERVERTYPE}" = "MASTER" ];
285 echo "At this point, we have to construct a list of this domains YP servers."
286 echo "${HOST} is already known as master server."
287 echo "Please continue to add any slave servers, one per line. When you are"
288 echo "done with the list, type a <control D>."
289 echo " master server : ${HOST}"
292 if [ "${SERVERTYPE}" = "UPDATE" ];
297 SHORT_HOST=`echo ${HOST} | cut
-d.
-f1`
298 if [ -f ${YP_DIR}/${DOMAIN}/ypservers.db ];
300 for srv in `${MAKEDBM} -u ${YP_DIR}/${DOMAIN}/ypservers
| grep -v "^YP" | tr "\t" " " | cut
-d\
-f1`;
302 short_srv=`echo ${srv} | cut
-d.
-f1`
303 if [ "${SHORT_HOST}" != "${short_srv}" ]
305 if [ "${NEW_LIST}" = "" ];
309 NEW_LIST="${NEW_LIST} ${srv}"
313 MASTER_NAME=`${MAKEDBM} -u ${YP_DIR}/${DOMAIN}/ypservers
| grep "^YP_MASTER_NAME" | tr "\t" " " | cut
-d\
-f2`
316 echo "Update the list of hosts running YP servers in domain ${DOMAIN}."
317 echo "Master for this domain is ${MASTER_NAME}."
319 echo "First verify old servers, type \\ to remove a server."
320 echo "Then add new servers, one per line. When done type a <control D>."
322 echo " master server : ${HOST}"
323 if [ "${NEW_LIST}" != "" ]; then
324 for node in $NEW_LIST; do
325 echo -n " verify host : [${node}] "
327 if [ "${verify}" != "\\" ]; then
328 HOST_LIST="${HOST_LIST} ${node}"
334 echo -n " next host to add: "
338 echo -n " next host to add: "
339 HOST_LIST="${HOST_LIST} ${h}"
343 echo "The current list of NIS servers looks like this:"
346 for h in `echo ${HOST_LIST}`;
352 echo -n "Is this correct? [y/n: y] "
356 n*) echo "Let's try the whole thing again...";;
357 N*) echo "Let's try the whole thing again...";;
363 echo "Building ${YP_DIR}/${DOMAIN}/ypservers..."
364 for host in ${HOST_LIST};
366 echo "${host} ${host}"
367 done | ${MAKEDBM} - ${YP_DIR}/${DOMAIN}/ypservers
369 if [ $? -ne 0 ]; then
371 echo "Couldn't build yp data base ${YP_DIR}/${DOMAIN}/ypservers." 1>&2
373 if [ "${ERROR_EXIT}" = "YES" ]; then
378 if [ "${SERVERTYPE}" = "MASTER" ]; then
381 cd ${YP_DIR}/${DOMAIN}
382 echo "Running ${YP_DIR}/${DOMAIN}/Makefile..."
383 if ! ${MAKE} NOPUSH=1; then
385 echo "Error running Makefile." 1>&2
387 if [ "${ERROR_EXIT}" = "YES" ]; then
395 if [ "${ERROR_EXISTS}" = "YES" ]; then
396 echo "${HOST} has been setup as an YP master server with errors. " 1>&2
397 echo "Please remember fix any problem that occurred." 1>&2
399 echo "${HOST} has been setup as an YP master server without any errors. "