/usr/lib/yp/ypinit is in nis 3.17-32ubuntu6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | #! /bin/sh
#
# ypinit - set up the YP directory on a master server or a slave server.
#
### some variables
YPMAPDIR=/var/yp
YPBINDIR=/usr/lib/yp
HOST=""
DOMAIN=""
MASTER=""
is_correct=F
### some functions, which make the life easier
ypinit_slave()
{
if [ $HOST = $MASTER ]
then
echo "The host specified should be a running master NIS server, not this machine."
exit 1
fi
# maps=`ypwhich -m | egrep $MASTER$| awk '{ printf("%s ",$1) }' -`
maps=`$YPBINDIR/yphelper --maps $MASTER`
if [ -z "$maps" ]
then
echo "Can't enumerate maps from $MASTER. Please check that it is running."
exit 1
fi
mkdir -p $YPMAPDIR/$DOMAIN
echo "We will need a few minutes to copy the data from $MASTER."
for map in $maps
do
echo "Transferring $map..."
$YPBINDIR/ypxfr -f -h $MASTER -c -d $DOMAIN $map
if [ $? -ne 0 ]
then
echo "YPINIT: WARNING: Couldn't exec $YPBINDIR/ypxfr -f -h $MASTER -c -d $DOMAIN $map"
fi
done
echo ""
echo "${HOST}'s NIS data base has been set up."
echo "If there were warnings, please figure out what went wrong, and fix it."
echo ""
echo "At this point, make sure that /etc/passwd and /etc/group have"
echo "been edited so that when the NIS is activated, the data bases you"
echo "have just created will be used, instead of the /etc ASCII files."
exit 0
}
ypinit_master()
{
mkdir -p $YPMAPDIR/$DOMAIN
rm -f $YPMAPDIR/$DOMAIN/*
while [ $is_correct = F ]; do
echo $HOST >$YPMAPDIR/ypservers
echo ""
echo "At this point, we have to construct a list of the hosts which will run NIS"
echo "servers. $HOST is in the list of NIS server hosts. Please continue to add"
echo "the names for the other hosts, one per line. When you are done with the"
echo "list, type a <control D>."
echo " next host to add: $HOST"
echo -n " next host to add: "
while read h
do
echo -n " next host to add: "
echo $h >>$YPMAPDIR/ypservers
done
echo ""
echo "The current list of NIS servers looks like this:"
echo ""
cat $YPMAPDIR/ypservers
echo ""
echo -n "Is this correct? [y/n: y] "
read hostlist_ok
case $hostlist_ok in
N) echo "Let's try again...";;
n) echo "Let's try again...";;
*) is_correct=T;;
esac
done
echo "We need a few minutes to build the databases..."
echo "Building $YPMAPDIR/$DOMAIN/ypservers..."
cat $YPMAPDIR/ypservers | awk '{print $$0, $$0}' | $YPBINDIR/makedbm - $YPMAPDIR/$DOMAIN/ypservers
if [ $? -ne 0 ]
then
echo "Couldn't build yp data base $YPMAPDIR/$DOMAIN/ypservers."
echo "Please fix it."
fi
echo "Running $YPMAPDIR/Makefile..."
cd $YPMAPDIR && make NOPUSH=true
if [ $? -ne 0 ]
then
echo "Error running Makefile."
echo "Please try it by hand."
else
echo ""
echo "$HOST has been set up as a NIS master server."
echo ""
echo "Now you can run ypinit -s $HOST on all slave server."
fi
}
usage()
{
echo "usage:"
echo " ypinit -m"
echo " ypinit -s master"
echo ""
echo "where -m is used to build the data bases on a master NIS server,"
echo "and -s is used for a slave data base. master must be an existing"
echo "reachable NIS server."
exit 1
}
### Begin of the shell script
HOST=`$YPBINDIR/yphelper --hostname`
if [ $? -ne 0 ]
then
echo "Can't get local host's name. Please check your path."
exit 1
fi
if [ -z "$HOST" ]
then
echo "The local host's name hasn't been set. Please set it."
exit 1
fi
DOMAIN=`domainname`
if [ $? -ne 0 ]
then
echo "Can't find domainname. Please fix your PATH"
exit 1
fi
if [ -z "$DOMAIN" ]
then
echo "The local host's domain name hasn't been set. Please set it."
exit 1
fi
if [ ! -d $YPMAPDIR -o -f $YPMAPDIR ]
then
echo "The directory $YPMAPDIR doesn't exist."
echo "Create it or run make install-* from the sourcen."
exit 1
fi
case $# in
1) case $1 in
-m) ypinit_master;;
*) usage;;
esac;;
2) case $1 in
-s) MASTER=$2
ypinit_slave;;
*) usage;;
esac;;
*) usage;;
esac
|