Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afsweb / afswsNetscape_config.sh
1 #!/bin/sh
2 # $Header$
3 #
4 # Installation and Configuration script for AFS Web Security Pack
5 #
6 # History:
7 #
8 # 19-Mar-1998 Created. (wvh@transarc.com)
9 #
10 # 06-May-1998 Added tar file stuff and tweaked to add CellServDb
11 # edits, etc.
12 #
13 # The suggested procedure would be to install everything from the CD
14 # (maybe using tar?), and then run the this script.
15 #
16 # Suggested final installation heirarchy would look like:
17 #
18 # /usr/<something>/etc - conf files for AFSWebSecure
19 # /usr/<something>/lib - location of shared library
20 # /usr/<something>/cache - real cache or symlink elsewhere
21 # /usr/<something>/log - log files
22 #
23 ##########################################################################
24 #
25 # Actual install script begins here.
26 #
27 ##########################################################################
28
29 PRODUCT="AFS Web Security Pack"
30
31 #
32 # Handle various types of failures
33 #
34 trap 'echo "" ; \
35 echo "$PRODUCT Installation cancelled." ; \
36 echo "" ; \
37 exit 1' 1 2 3 6 9 12 13 15 16 17 24 25 29
38
39 rm -f /tmp/newconf
40
41 #
42 # Figure out what OS we're running on so that we try to
43 # exec the right binaries in the script. (The uname
44 # binary lives in the same place on AIX and SunOS
45 # (Solaris) systems, else we'd have to conditionalize
46 # that, too.)
47 #
48 OSTYPE=`/usr/bin/uname | sed -e 's;\([a-zA-Z]*\).*;\1;'`
49
50 if [ x$OSTYPE = "xSunOS" ] ; then
51 HOSTNAME=/usr/ucb/hostname
52 NSLOOKUP=/usr/sbin/nslookup
53 EX=/usr/ucb/ex
54 ECHO=/bin/echo
55 ECHOFLAG="\c"
56 AFSWSLIB=nsafs.so
57 elif [ x$OSTYPE = "xAIX" ] ; then
58 HOSTNAME=/usr/bin/hostname
59 NSLOOKUP=/usr/bin/nslookup
60 EX=/usr/bin/ex
61 ECHO=echo
62 ECHOFLAG=""
63 AFSWSLIB=nsafs.a
64 else
65 $ECHO " ERROR: unsupported OSTYPE \"$OSTYPE\" returned by /usr/bin/uname."
66 exit 1
67 fi
68
69 #
70 # Check for the existence of the file to install from, and exit
71 # if not in pwd.
72 #
73 if [ ! -f ns_afswebsecure.tar ] ; then
74 $ECHO " File ns_afswebsecure.tar not found in working directory."
75 $ECHO ""
76 exit 1
77 fi
78 #
79 # Find out where the server is installed
80 #
81 $ECHO "Enter the directory where the Web server's bin directory is located [/usr/netscape/suitespot]: " $ECHOFLAG
82 read ws_srvdir
83 if [ x$ws_srvdir = "x" ] ; then
84 ws_srvdir="/usr/netscape/suitespot"
85 fi
86
87 $ECHO ""
88 #
89 # Find out the name of the Web server. Sets three variables for
90 # the hostname: lhn, which is the full host name; shn, which is
91 # the short (non-domain) host name; and dhn, which is the domain
92 # name. This uses nslookup, since we can't depend on the host
93 # actually being in /etc/hosts due to DNS and YP.
94 #
95 tmp=`$HOSTNAME`
96 lhn=`$NSLOOKUP $tmp | grep Name: | sed -e 's;Name:[ ]*;;'`
97 shn=`echo $lhn | sed -e 's;\([-_a-zA-Z0-9]*\).*;\1;'`
98 dhn=`echo $lhn | sed -e "s;$shn\.;;"`
99
100 # echo ""
101 # echo "Long host name is $lhn."
102 # echo "Short host name is $shn."
103 # echo "Domain name is $dhn."
104 # echo ""
105
106 $ECHO "Enter the Web server to use to access AFS data [$shn]: " $ECHOFLAG
107 read ws_wsname
108 case $ws_wsname in
109 '') ;;
110 *) shn=$ws_wsname;;
111 esac
112
113 ws_conf=$ws_srvdir"/https-"$shn"/config/obj.conf"
114
115 if [ ! -f $ws_conf ] ; then
116 $ECHO " ERROR: server config file \"$ws_conf\" not found."
117 exit 1
118 else
119 $ECHO ""
120 fi
121 #
122 # Make sure we can actually modify the obj.conf file
123 #
124
125 touch $ws_conf 1> /dev/null 2> /dev/null
126 if [ $? != 0 ] ; then
127 $ECHO " ERROR: No write permission to configuration file $ws_conf."
128 exit 1
129 fi
130
131 #
132 # Check if AFS WebSecure is already installed
133 #
134 grep nsafs $ws_conf 1> /dev/null 2> /dev/null
135 if [ $? = 0 ] ; then
136 $ECHO " ERROR: $PRODUCT entries already exist in $ws_conf."
137 exit 1
138 fi
139
140 #
141 # Find out where the AFSWebSecure stuff should be installed.
142 #
143
144 $ECHO "Enter the $PRODUCT installation directory [/usr/afsweb]: " $ECHOFLAG
145 read ws_wsdir
146 if [ x$ws_wsdir = "x" ] ; then
147 ws_wsdir="/usr/afsweb"
148 fi
149
150 #
151 # Install WebSecure from tar file in same directory from which the
152 # ws_config script was started. The convoluted directory creation
153 # loop lets people install in a directory tree that doesn't exist
154 # yet, which would not typically be the case, but...
155 #
156 if [ ! -d $ws_wsdir ] ; then
157 base=""
158 root=""
159 target=$ws_wsdir
160 while [ x$target != "x" ] ; do
161 base=`echo $target | sed -e 's;\(/[^/]*\)[-/a-zA-Z0-9_]*;\1;'`
162 target=`echo $target | sed -e 's;\(/[^/]*\)\([-/a-zA-Z0-9_]*\);\2;'`
163 if [ ! -d $root$base ] ; then
164 echo "Creating $root$base"
165 mkdir $root$base 1> /dev/null 2> /dev/null
166 if [ $? != 0 ] ; then
167 $ECHO "ERROR: Could not create $ws_wsdir. Check permissions and retry."
168 exit 1
169 fi
170 fi
171 root=$root$base
172 done
173 fi
174
175 $ECHO ""
176 wd=`pwd`
177 cd $ws_wsdir
178 tar xvf $wd"/ns_afswebsecure.tar"
179
180 #
181 # Use this as a check that everything went OK.
182 #
183 if [ ! -f $ws_wsdir"/lib/${AFSWSLIB}" ] ; then
184 $ECHO " ERROR: $PRODUCT shared library \"$ws_wsdir/lib/${AFSWSLIB}\" not found."
185 exit 1
186 else
187 $ECHO ""
188 fi
189
190 #
191 # Ensure that the cache dir and log files are owned by the user
192 # specified in magnus.conf that this server runs as
193 #
194 ws_mconf=$ws_srvdir/https-$shn/config/magnus.conf
195
196 if [ ! -f $ws_mconf ] ; then
197 $ECHO " ERROR: server config file \"$ws_mconf\" not found."
198 exit 1
199 else
200 $ECHO ""
201 fi
202
203 username=`grep -i User $ws_mconf | awk '{ print $2 }'`
204 chown $username $ws_wsdir/cache $ws_wsdir/log
205
206 #
207 # Enter the size of the AFS cache in 1K blocks
208 #
209
210 $ECHO "Enter the size of the $PRODUCT cache in 1K blocks [5000]: " $ECHOFLAG
211 read ws_csize
212 if [ x$ws_csize = "x" ] ; then
213 ws_csize="5000"
214 fi
215 $ECHO ""
216
217 expr $ws_csize + 1 1> /dev/null 2> /dev/null
218 if [ $? != 0 ] ; then
219 $ECHO " ERROR: Cache size must be numeric. You entered \"$ws_csize\"."
220 exit 1
221 fi
222
223 #
224 # Set default value for advanced options - number of files in the cache
225 # and number of receiving threads.
226 #
227 ws_cfiles=`expr $ws_csize / 10`
228 ws_numt="2"
229
230 #
231 # Enter the number of AFS daemon processes
232 #
233
234 $ECHO "Enter the number of AFS daemons to run [3]: " $ECHOFLAG
235 read ws_numd
236 if [ x$ws_numd = "x" ] ; then
237 ws_numd="3"
238 fi
239 $ECHO ""
240
241 expr $ws_numd + 1 1> /dev/null 2> /dev/null
242 if [ $? != 0 ] ; then
243 $ECHO " ERROR: The number of AFS daemons must be numeric. You entered \"$ws_numd\"."
244 exit 1
245 fi
246
247 #
248 # Enter the number of entries in the AFS Stat cache
249 # Default is the number of files in the cache.
250 #
251
252 $ECHO "Enter the number of entries in the AFS stat cache [$ws_cfiles]: " $ECHOFLAG
253 read ws_nums
254 if [ x$ws_nums = "x" ] ; then
255 ws_nums=$ws_cfiles
256 fi
257 $ECHO ""
258
259 expr $ws_nums + 1 1> /dev/null 2> /dev/null
260 if [ $? != 0 ] ; then
261 $ECHO " ERROR: The number of entries in the stat cache must be numeric. You entered \"$ws_nums\"."
262 exit 1
263 fi
264
265 #
266 # Find out which cells $PRODUCT should work with
267 #
268
269 $ECHO "Enter the AFS cell to access using $PRODUCT [$dhn]: " $ECHOFLAG
270 read ws_cell
271 if [ x$ws_cell = "x" ] ; then
272 ws_cell=$dhn
273 fi
274
275 #
276 # Create appropriate ThisCell file
277 #
278 echo $ws_cell > $ws_wsdir"/etc/ThisCell"
279
280 #
281 # If necessary, add entries to generic cellServDB file
282 #
283 grep $ws_cell $ws_wsdir"/etc/CellServDB" 1> /dev/null 2> /dev/null
284 if [ $? != 0 ] ; then
285 $ECHO " Cell $ws_cell not found in default CellServDB file."
286 $ECHO ""
287 $ECHO "Enter a one-line text description for this cell: " $ECHOFLAG
288 read exp
289 $ECHO ">$ws_cell # $exp" >> $ws_wsdir"/etc/CellServDB"
290 $ECHO ""
291 $ECHO "Enter the IP address of a database server for this cell ('.' to exit): " $ECHOFLAG
292 read ws_dbsrv
293 while [ x$ws_dbsrv != "x." ] ; do
294 ws_dbname=`grep $ws_dbsrv /etc/hosts | sed -e 's;[0-9\.]*[ ]*\([a-z\.A-Z0-9]*\).*;\1;'`
295 if [ x$ws_dbname = "x" ] ; then
296 ws_dbname="Unknown"
297 fi
298 $ECHO " Appending $ws_dbname, IP address $ws_dbsrv."
299 $ECHO "$ws_dbsrv #$ws_dbname" >> $ws_wsdir"/etc/CellServDB"
300 $ECHO "Enter the IP address of a database server for this cell ('.' to exit): " $ECHOFLAG
301 read ws_dbsrv
302 done
303 else
304 $ECHO " Found cell $ws_cell in $ws_wsdir/etc/CellServDB."
305 fi
306
307 $ECHO ""
308 #
309 #
310 # "Advanced" configuration items - optional. These are:
311 #
312 # - number of RX threads
313 # - number of files in the AFS WebSecure cache
314 #
315 #
316 # $ECHO "Do you want to configure advanced options? (y/n): " $ECHOFLAG
317 # read ans
318 # let=`echo $ans | sed -e 's;\(.\).*;\1;' | tr [A-Z] [a-z]`
319 # $ECHO ""
320 # if [ x$let = "xy" ] ; then
321 #
322 #
323 # Enter the number of files in the AFS cache - default is ws_csize/10
324 #
325 #
326 # $ECHO "Enter the number of files in the Websecure cache [$ws_cfiles]: " $ECHOFLAG
327 # read ws_cfiles
328 # if [ x$ws_cfiles = "x" ] ; then
329 # ws_cfiles=`expr $ws_csize / 10`
330 # fi
331 # $ECHO ""
332 #
333 # expr $ws_cfiles + 1 1> /dev/null 2> /dev/null
334 # if [ $? != 0 ] ; then
335 # $ECHO " ERROR: Number of cache files must be numeric. You entered \"$ws_cfiles\"."
336 # exit 1
337 # fi
338 #
339 #
340 # Enter the number of threads to process RX packets
341 #
342 #
343 # $ECHO "Enter the number of threads to process RX requests [2]: " $ECHOFLAG
344 # read ws_numt
345 # if [ x$ws_numt = "x" ] ; then
346 # ws_numt="2"
347 # fi
348 # $ECHO ""
349 #
350 # expr $ws_numt + 1 1> /dev/null 2> /dev/null
351 # if [ $? != 0 ] ; then
352 # $ECHO " ERROR: The number of RX threads must be numeric. You entered \"$ws_numt\"."
353 # exit 1
354 # fi
355 #
356 # fi
357 #
358 #
359 # Now that we have all the info we need, time to actually edit the obj.conf file
360 #
361 # Back up the old one if no previous backup exists
362 #
363 if [ -f $ws_conf".pre_ws" ] ; then
364 $ECHO "NOTE: Backup file \"$ws_conf.pre_ws\" already exists."
365 $ECHO " Not backing up current obj.conf file."
366 else
367 cp $ws_conf $ws_conf".pre_ws"
368 $ECHO " Creating backup copy of obj.conf file..."
369 fi
370
371 $EX $ws_conf << END_OF_FILE 1> /dev/null
372 1
373 /mime-types
374 a
375 Init fn="load-modules" shlib="$ws_wsdir/lib/${AFSWSLIB}" funcs="nsafs-init,nsafs-basic,nsafs-mount,nsafs-public,nsafs-nolinks,nsafs-check,nsafs-nocheck,nsafs-find-index,nsafs-send,nsafs-force-type,nsafs-put,nsafs-delete,nsafs-move,nsafs-index,nsafs-mkdir,nsafs-rmdir"
376 Init fn="nsafs-init" cell="$ws_cell" blocks="$ws_csize" files="$ws_cfiles" stat="$ws_nums" daemons="$ws_numd" cachedir="$ws_wsdir/cache" confdir="$ws_wsdir/etc" logfile="$ws_wsdir/log/nsafs.log" exp-max="120" timeout="30" rcvthreads="$ws_numt"
377 .
378 /default
379 a
380 AuthTrans fn="nsafs-basic"
381 NameTrans fn="nsafs-mount" mount="/afs"
382 PathCheck fn="nsafs-public" public="/afs"
383 PathCheck fn="nsafs-nolinks" nolinks="/afs/$ws_cell/usr"
384 .
385 /Service
386 i
387 Service method="(GET|HEAD)" fn="nsafs-send" index="fancy"
388 .
389 w! /tmp/newconf
390 q
391 END_OF_FILE
392
393 cp /tmp/newconf $ws_conf
394
395 $ECHO ""
396
397 $ECHO " Installation of $PRODUCT complete."