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