Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tw/updatedb.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1989-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# Glenn Fowler <[email protected]> #
18
# #
19
########################################################################
20
: gnu updatedb wrapper for tw
21
22
codes_default="lib/find/codes"
23
dirs_default="/"
24
drop_default="/afs|/backup|/dev|/proc|/tmp|/usr/tmp|/var/tmp"
25
keep_default="/home|/usr/local|/usr/common"
26
27
COMMAND=updatedb
28
case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
29
0123) ARGV0="-a $COMMAND"
30
USAGE=$'
31
[-?
32
@(#)$Id: updatedb (AT&T Labs Research) 2003-11-14 $
33
]
34
'$USAGE_LICENSE$'
35
[+NAME?updatedb - generate locate pathname database]
36
[+DESCRIPTION?\bupdatedb\b generates the locate pathname database that is used
37
by \blocate\b(1), \bfind\b(1), and \btw\b(1). Sufficient privilege
38
is required to change the system locate database.]
39
[+?This implemenation is a script that generates a \btw\b(1) command that
40
does all the work.]
41
[a:auto-home?Include the \bnis\b(1) \aauto.home\a auto mounter home directories
42
in \b/home\b. NOTE: this causes the home directories to be mounted
43
and may swamp the mount table.]
44
[d:directory|localpaths?Local directories to include in the database. If the
45
first \adir\a is \b+\b then the default list is appended.]:
46
["dir1 dir2 ...":='${dirs_default}$']
47
[i:ignore-errors?Omit inaccessible files and directory error messages.]
48
[k:keep?Directories to retain in the database; used to override
49
\b--nocrossdevice\b. If any of the paths are symbolic links then they
50
are followed. If the first \adir\a is \b+\b then the default list
51
is appended.]:["dir1 dir2 ...":='${keep_default//\|/\ }$']
52
[l:local?Do not descend into non-local filesystem directories.]
53
[r:netpaths?Network directories to include in the database. Currently
54
equivalent to \b--localpaths\b.]:["dir1 dir2 ..."]
55
[p:prunepaths|drop?Directories to exclude from the database. If the first \adir\a
56
is \b+\b then the default list is appended.]:
57
["dir1 dir2 ...":='${drop_default//\|/\ }$']
58
[o:output|codes?The path of the generated database.]:[dbfile:='${codes_default}$']
59
[P:public?Omit files that are not publicly readable and directories that
60
are not publicly searchable.]
61
[u:user|netuser?The user id used to search directories.]:[user]
62
[m:dir-format?Generate a database similar to \b--gnu-format\b, except that
63
directories are marked for efficient implementations of \bfind\b(1)
64
and \btw\b(1). This is the default database format.]
65
[g:gnu-format?Generate a machine independent gnu \blocate\b(1) compatible
66
database.]
67
[O:old-format?Generate a database compatible with the obsolete
68
\bfastfind\b(1). This format has a machine dependent encoding.]
69
[D:depth?Limit the directory traversal depth to \alevel\a.]#[level]
70
[X!:crossdevice?Retain subdirectories that cross device boundaries.]
71
[n:show?Show the underlying the \btw\b(1) command but do not execute.]
72
[+FILES]{[+'${codes_default}$'?Default locate database on \b\$PATH\b.]}
73
[+CAVEATS?If you run \bupdatedb\b as root then protected directory
74
contents may be visible to everyone via the database. Use the
75
\b--public\b option to limit the database to publically visible
76
files and directories.]
77
[+SEE ALSO?\blocate\b(1), \bfastfind\b(1), \bfind\b(1), \bnis\b(1), \btw\b(1)]
78
'
79
;;
80
*) ARGV0=""
81
USAGE="aiglnOPXd:['dir1 dir2 ...']k:['dir1 dir2 ...']o:[dbfile]p:['dir1 dir2 ...']r:['dir1 dir2 ...']u:[user]D:[level]"
82
;;
83
esac
84
85
usage()
86
{
87
OPTIND=0
88
getopts $ARGV0 "$USAGE" OPT '-?'
89
exit 2
90
}
91
92
cross=1
93
depth=
94
dirs=
95
drop=
96
format="-"
97
keep=
98
options="-P"
99
output="-"
100
public=
101
show=
102
su=
103
while getopts $ARGV0 "$USAGE" OPT
104
do case $OPT in
105
a) dirs="$dirs `{
106
ypcat auto.home | sed 's,.*/,-d /home/,'
107
ls /home | sed 's,^,-d /home/,'
108
} | sort -u`"
109
;;
110
d|r) case $OPTARG in
111
"+"|"+ "*) ;;
112
*) dirs_default= ;;
113
esac
114
for dir in $OPTARG
115
do case $dir in
116
+) ;;
117
*) dirs="$dirs -d $dir" ;;
118
esac
119
done
120
;;
121
g) format=gnu
122
;;
123
i) options="$options -i"
124
;;
125
k) case $OPTARG in
126
"+"|"+ "*) ;;
127
*) keep_default= ;;
128
esac
129
for dir in $OPTARG
130
do case $dir in
131
+) ;;
132
*) case $keep in
133
?*) keep="$keep|$dir" ;;
134
*) keep="$dir" ;;
135
esac
136
;;
137
esac
138
done
139
;;
140
l) options="$options -l"
141
;;
142
m) format="-"
143
;;
144
o) output=$OPTARG
145
;;
146
n) show="print --"
147
;;
148
p) case $OPTARG in
149
"+"|"+ "*) ;;
150
*) drop_default= ;;
151
esac
152
for dir in $OPTARG
153
do case $dir in
154
+) ;;
155
*) case $drop in
156
?*) drop="$drop|$dir" ;;
157
*) drop="$dir" ;;
158
esac
159
;;
160
esac
161
done
162
;;
163
u) su="su $OPTARG"
164
;;
165
D) depth=$OPTARG
166
;;
167
O) format=old
168
;;
169
P) public=1
170
;;
171
X) cross=
172
;;
173
*) usage
174
;;
175
esac
176
done
177
shift $OPTIND-1
178
case $# in
179
0) ;;
180
*) usage ;;
181
esac
182
183
for dir in $dirs_default
184
do dirs="$dirs -d $dir"
185
done
186
for dir in $drop_default
187
do case $drop in
188
"") drop="$dir" ;;
189
*) drop="$drop|$dir" ;;
190
esac
191
done
192
for dir in $keep_default
193
do case $keep in
194
"") keep="$dir" ;;
195
*) keep="$keep|$dir" ;;
196
esac
197
done
198
199
skip=
200
follow=
201
alt="
202
"
203
sep="
204
"
205
case $public in
206
?*) case $skip in
207
?*) skip="$skip ||" ;;
208
esac
209
skip="${skip}${alt}!(mode & 'o+r') ||${alt}type == DIR &&${alt}!(mode & 'o+x')"
210
;;
211
esac
212
case $depth in
213
?*) case $skip in
214
?*) skip="$skip ||" ;;
215
esac
216
skip="${skip}${alt}level > $depth"
217
;;
218
esac
219
case $cross in
220
"") case $skip in
221
?*) skip="$skip ||" ;;
222
esac
223
skip="${skip}${alt}fstype != '/'.fstype"
224
case $keep in
225
?*) skip="${skip} &&${alt}path != '($keep)?(/*)'"
226
esac
227
;;
228
esac
229
case $drop in
230
?*) case $skip in
231
?*) skip="$skip ||" ;;
232
esac
233
skip="${skip}${alt}path == '($drop)?(/*)'"
234
;;
235
esac
236
expr=
237
case $skip in
238
?*) expr="if (${skip}${alt})${alt} status = SKIP;" ;;
239
esac
240
case $keep in
241
?*) case $expr in
242
?*) expr="${expr}${sep}else " ;;
243
esac
244
expr="${expr}if (${alt}type == LNK &&${alt}level < 3 &&${alt}path == '($keep)?(/*)'${alt})${alt} status = FOLLOW;"
245
;;
246
esac
247
case $expr in
248
?*) case $show in
249
"") expr="-e${sep}${expr}${sep}" ;;
250
*) expr="-e \"${sep}${expr}\"${sep}" ;;
251
esac
252
;;
253
esac
254
$show $su tw $options -F "$output" -G "$format" "$expr" $dirs
255
256