Imported Upstream version 4.89
[platform/upstream/lsof.git] / AFSConfig
1 #!/bin/sh
2 #
3 # $Id: AFSConfig,v 1.2 99/05/09 14:49:54 abe Exp $
4 #
5 # AFSConfig: configure for AFS
6
7 AFSD=/usr/vice/etc/afsd
8 AH=AFSHeaders
9 AV=AFSVersion
10 STD=/usr/afsws/include
11
12 # Establish trap and stty handling.
13
14 ISIG=":"
15 trap 'rm -f $AH $AV; $ISIG; exit 1'  1 2 3 15
16 stty -a 2>&1 | grep isig > /dev/null
17 if test $? -eq 0
18 then
19   stty -a 2>&1 | egrep -e -isig > /dev/null
20   if test $? -eq 0
21   then
22     ISIG="stty -isig"
23     stty isig
24   fi
25 fi
26
27 # Decide how to use echo.
28
29 ECHO=`echo -n ""`
30 if test "X$ECHO" = "X-n "
31 then
32   EC="\c"
33   EO=""
34 else
35   EC=""
36   EO="-n"
37 fi
38
39 # Decide (perhaps for a second time) that AFS is installed.
40
41 CELL=""
42 if test -r /usr/vice/etc/ThisCell
43 then
44   cell=`awk '{print $1}' /usr/vice/etc/ThisCell`
45   if test -d /afs/$cell
46   then
47     CELL=$cell
48   else
49     CELL=`echo $cell | sed 's/\([^.]*\)\..*/\1/'`
50     if test "X$CELL" != "X"
51     then
52       if test ! -d /afs/$CELL
53       then
54         CELL=""
55       fi
56     fi
57   fi
58 fi
59 if test "X$CELL" = "X"
60 then
61   echo ""
62   echo "This system does not appear to have AFS installed."
63   exit 1
64 fi
65
66 # See if AFS configuration is wanted.
67
68 cat << .CAT_MARK
69
70 AFS appears to be installed on this system; cell name "$CELL".
71
72 Lsof needs to be configured for AFS by identifying: 1) the directory
73 that includes the AFS header files needed to compile AFS support into
74 lsof; and 2) the version of AFS that is installed.
75 .CAT_MARK
76
77 END=0
78 while test $END = 0
79 do
80   echo ""
81   echo $EO "Do you want to configure lsof for AFS (y|n) [y]? $EC"
82   read ANS EXCESS
83   if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
84   then
85     exit 1
86   fi
87   if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
88   then
89     END=1
90   else
91     echo ""
92     echo "Please answer y or n."
93   fi
94 done
95
96 # See if $AH exists and points to a likely place.
97
98 AHOK=""
99 echo ""
100 echo "====================================================================="
101 echo ""
102 if test -r $AH
103 then
104   AHP=`cat $AH`
105   if test -r $AHP
106   then
107     if test -r $AHP/afs/afs.h
108     then
109       cat << .CAT_MARK
110 The location of the AFS header files required by lsof has been
111 previously identified as "$AHP".
112
113 Since <afs/afs.h> can be found there, that's probably correct.
114 .CAT_MARK
115
116       END=0
117       while test $END = 0
118       do
119         echo ""
120         echo $EO "Do you want to use $AHP again (y|n) [y]? $EC"
121         read ANS EXCESS
122         if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
123         then
124           AHOK="ok"
125           END=1
126         else
127           if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
128           then
129             rm -f $AH
130             AHP=""
131             END=1
132           else
133             echo ""
134             echo "Please answer y or n."
135           fi
136         fi
137       done
138     else
139       echo "\"$AHP\" has been previously specified as the location of the"
140       echo "AFS header files, but it lacks an afs/afs.h header file."
141       rm -f $AH
142       AHP=""
143     fi
144   else
145     echo "The file ./$AH exists, but has no AFS header file path in it."
146     rm -f $AH
147     AHP=""
148   fi
149 else
150   echo "No previous header location has been specified."
151   rm -f $AH
152   AHP=""
153 fi
154
155 # See if the header files are in the "standard" place.
156
157 if test "X$AHOK" != "Xok"
158 then
159   if test -r $STD
160   then
161     echo ""
162     echo "====================================================================="
163     echo ""
164     echo "The AFS header files appear to be in the \"standard\" location --"
165     echo "i.e.: \"$STD\"."
166     END=0
167     while test $END = 0
168     do
169       echo ""
170       echo $EO "Do you want to let lsof use them (y|n) [y]? $EC"
171       read ANS EXCESS
172       if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
173       then
174         echo $STD > $AH
175         AHOK="ok"
176         END=1
177       else
178         if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
179         then
180           END=1
181         else
182           echo ""
183           echo "Please answer y or n."
184         fi
185       fi
186     done
187   fi
188 fi
189
190 # Ask for the AFS header file location.
191
192 if test "X$AHOK" != "Xok"
193 then
194   echo ""
195   echo "====================================================================="
196   echo ""
197   echo "Please specify the full path where lsof can find the AFS header"
198   echo "files.  A possible location is: \"/afs/$CELL/<sysname>/include\"."
199   cat << .CAT_MARK
200 The <sysname> component of the path is the AFS system name that
201 was used to configure and build AFS on this system.  It is usually
202 constructed from a manufacturer or Unix operating system designation,
203 followed by a version number -- e.g., hp800_ux90, sun4m_54, vax_ul43,
204 etc.  You may have to consult your AFS documentation to determine
205 what <sysname> applies to your configuration.
206 .CAT_MARK
207
208   END=0
209   while test $END = 0
210   do
211     echo ""
212     echo $EO "Do you want to see the contents of /afs/$CELL (y|n) [y]? $EC"
213     read ANS EXCESS
214     if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
215     then
216       END=1
217     else
218       if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
219       then
220         echo ""
221         ls -C /afs/$CELL
222         END=1
223       else
224         echo ""
225         echo "Please answer y or n."
226       fi
227     fi
228   done
229   END=0
230   while test $END = 0
231   do
232     echo ""
233     echo $EO "AFS header file path: $EC"
234     read ANS EXCESS
235     fc=`expr "${ANS}X" : '\(.\).*'`
236     if test "X$fc" = "X/"
237     then
238       if test -r $ANS/afs/afs.h
239       then
240         echo $ANS > $AH
241         AHOK="ok"
242         END=1
243       else
244         echo ""
245         echo "$ANS/afs/afs.h doesn't exist."
246         echo "Please enter a path whose afs subdirectory contains afs.h"
247       fi
248     else
249       echo ""
250       echo "Please enter an absolute path name."
251     fi
252   done
253 fi
254 if test "X$AHOK" != "Xok"
255 then
256   echo "AFSConfig: unknown error"
257   exit 1
258 fi
259
260 # Determine AFS version.
261
262 if test -r $AV
263 then
264   echo ""
265   echo "====================================================================="
266   echo ""
267   AVN=`cat $AV`
268   cat << .CAT_MARK
269 The AFS version was previously specified as: $AVN
270 .CAT_MARK
271
272   END=0
273   while test $END = 0
274   do
275     echo ""
276     echo $EO "Is this the correct version number (y|n) [y]? $EC"
277     read ANS EXCESS
278     if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
279     then
280       exit 0
281     fi
282     if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
283     then
284       rm -f $AV
285       END=1
286     else
287       echo "Please answer y or n."
288     fi
289   done
290 fi
291
292 # See if the version number can be determined.
293
294 if test -r $AFSD
295 then
296   ANS=`strings $AFSD | grep "Base configuration afs" | sed 's/^.*ion afs\([^ ]*\) .*/\1/'`
297   TV=`echo $ANS | sed 's/^\([0-9]*\)\.\([0-9]*\)\(.*\)/\1 \2 \3/' | awk '{printf "%d.%d%s\n",$1,$2,$3}'`
298   if test "X$ANS" = "X$TV"
299   then
300     echo ""
301     echo "====================================================================="
302     echo ""
303     cat << .CAT_MARK
304 Examining $AFSD the AFS version number appears to be: $TV
305 .CAT_MARK
306
307     END=0
308     while test $END = 0
309     do
310       echo ""
311       echo $EO "Do you want to use this version number (y/n) [y]? $EC"
312       read ANS EXCESS
313       if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
314       then
315         END=1
316       else
317         if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
318         then
319           echo $TV > $AV
320           exit 0
321         else
322           echo ""
323           echo "Please answer y or n."
324         fi
325       fi
326     done
327   fi
328 fi
329
330 # Ask for the version number.
331
332 echo ""
333 echo "====================================================================="
334 END=0
335 while test $END = 0
336 do
337   echo ""
338   echo $EO "Please enter the AFS version number: $EC"
339   read ANS EXCESS
340   TV=`echo $ANS | sed 's/^\([0-9]*\)\.\([0-9]*\)\(.*\)/\1 \2 \3/' | awk '{printf "%d.%d%s\n",$1,$2,$3}'`
341   if test "X$ANS" = "X$TV"
342   then
343     echo $TV > $AV
344     exit 0
345   fi
346 done