~ubuntu-branches/ubuntu/oneiric/nis/oneiric-proposed

« back to all changes in this revision

Viewing changes to ypserv-2.18/scripts/ypinit.in

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2005-11-16 23:42:06 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20051116234206-p00omaw5ji5q0qhr
Tags: 3.15-3ubuntu1
Resynchronise with Debian.  (me)

Show diffs side-by-side

added added

removed removed

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