Imported Upstream version 4.88
[platform/upstream/lsof.git] / Inventory
1 #!/bin/sh
2 #
3 # Inventory -- take an inventory of the lsof distribution's 00MANIFEST
4
5 # Establish trap and stty handling.
6
7 ISIG=":"
8 trap '$ISIG; exit 1'  1 2 3 15
9 stty -a 2>&1 | grep isig > /dev/null
10 if test $? -eq 0
11 then
12   stty -a 2>&1 | egrep -e -isig > /dev/null
13   if test $? -eq 0
14   then
15     ISIG="stty -isig"
16     stty isig
17   fi
18 fi
19
20 # Establish echo type -- Berkeley or SYSV.
21
22 j=`echo -n ""`
23 if test "X$j" = "X-n "
24 then
25   EC="\c"
26   EO=""
27 else
28   EC=""
29   EO="-n"
30 fi
31
32 # Display the introduction and basic explanation.
33
34 cat << .CAT_MARK
35
36 This configuration step (the Inventory script) takes inventory of
37 the lsof distribution.  The script runs for a minute or two while
38 it checks that all the subdirectories, information files, scripts,
39 header files and source files that should be present really are.
40
41 It's not absolutely necessary that you take inventory, but it's a
42 good idea to do it right after the lsof distribution has been
43 unpacked.  Once the inventory has been taken, this script creates
44 the file ./.ck00MAN as a signal that the inventory step has been
45 done.
46
47 You can call the Inventory script directly at any time to take
48 inventory.  You can inhibit the inventory step permanently by
49 creating the file ./.neverInv, and you can tell the Configure script
50 to skip the inventory and customization steps with the -n option.
51 .CAT_MARK
52
53 END=0
54 while test $END = 0
55 do
56   echo ""
57   echo $EO "Do you want to take inventory (y|n) [y]? $EC"
58   read ANS EXCESS
59   if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
60   then
61     exit 0
62   fi
63   if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
64   then
65     END=1
66   else
67     echo ""
68     echo "Please answer y or n."
69   fi
70 done
71
72 # The current directory is assumed to be the lsof distribution home.
73
74 D=`pwd`
75
76 # If .ck00MAN exists, the manifest has already been checked.
77 # See if the caller wants to check it again.
78
79 CK=$D/.ck00MAN
80 if test -r $CK
81 then
82   cat << .CAT_MARK
83
84 ======================================================================
85
86 The lsof distribution inventory in 00MANIFEST has already been checked.
87 .CAT_MARK
88
89   END=0
90   while test $END = 0
91   do
92     echo ""
93     echo $EO "Do you want to check the inventory again (y|n) [n]? $EC"
94     read ANS EXCESS
95     if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
96     then
97       exit 0
98     else
99       if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
100       then
101         END=1
102       else
103         echo ""
104         echo "Please answer y or n."
105       fi
106     fi
107   done
108 fi
109 echo ""
110
111 # See if manifest exists.  Exit if it does not.
112
113 if test ! -r 00MANIFEST
114 then
115   echo "FATAL: 00MANIFEST file not found or not readable; Inventory exits."
116   echo ""
117   exit 1
118 fi
119
120 # Start the inventory.
121
122 S=""
123 echo "Conducting an inventory of the lsof distribution; this will take a while."
124 echo ""
125 echo $EO "Examining ${D}:$EC"
126 ERR=0
127 OK=1
128 for i in `cat 00MANIFEST | sed 's/\*$//'`
129 do
130   if test "X$i" != "X"
131   then
132     j=`expr $i : '\(.*\)/$'`
133     if test "X$j" != "X" -a "X$j" != "X0"
134     then
135
136     # Check a subdirectory reference.
137
138       if test ! -d ${D}/${S}/$j
139       then
140         if test $OK = 1
141         then
142           echo ""
143         fi
144         echo "    Subdirectory ${S}/$j is missing. ++++"
145         ERR=1
146         OK=0
147       fi
148     else
149       s=`expr $i : '\(.*\):$'`
150       if test "X$s" != "X" -a "X$s" != "X0"
151       then
152
153       # Process a subdirectory change.
154
155         if test $OK -eq 1
156         then
157           echo " OK"
158         fi
159         OK=1
160         S=$s
161         echo $EO "Examining $S:$EC"
162         if test ! -d ${D}/$S
163         then
164           echo " ERROR"
165           echo "    Subdirectory $S is missing. ++++"
166           ERR=1
167           OK=0
168         fi
169       else
170
171         # Process a file reference.
172
173         if test ! -r ${D}/${S}/$i
174         then
175           if test $OK -eq 1
176           then
177             echo " ERROR"
178           fi
179           echo "    File ${S}/$i is missing. ++++"
180           ERR=1
181           OK=0
182         fi
183       fi
184     fi
185   fi
186 done
187 if test $OK -eq 1
188 then
189   echo " OK"
190 fi
191 echo ""
192 if test $ERR -ne 0
193 then
194   echo "+++++++++++++++++++++++++++++++++++++++++++++++"
195   echo "+                                             +"
196   echo "+  SOME FILES OR DIRECTORIES MAY BE MISSING!  +"
197   echo "+                                             +"
198   echo "+++++++++++++++++++++++++++++++++++++++++++++++"
199 else
200   echo "This lsof distribution seems to be complete."
201 fi
202 echo ""
203 echo "" >> $CK
204 exit $ERR