-
Notifications
You must be signed in to change notification settings - Fork 0
/
39b-slocate
39 lines (31 loc) · 1.23 KB
/
39b-slocate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# slocate--Tries to search the user's own secure slocatedb database for the
# specified pattern. If the pattern doesn't match, it means no database exists, so it outputs a warning and creates
# one. If personal slocatedb
# is empty, it uses system database instead.
locatedb="/var/locate.db"
slocatedb="$HOME/.slocatedb"
if [ ! -e $slocatedb -o "$1" = "--explain" ] ; then
cat << "EOF" >&2
Warning: Secure locate keeps a private database for each user, and your
database hasn't yet been created. Until it is (probably late tonight),
I'll just use the public locate database, which will show you all
publicly accessible matches rather than those explicitly available to
account ${USER:-$LOGNAME}.
EOF
if [ "$1" = "--explain" ] ; then
exit 0
fi
# Before we go, create a .slocatedb so that cron will fill it
# the next time the mkslocatedb script is run.
touch $slocatedb # mkslocatedb will build it next time through
chmod 600 $slocatedb # start on the right foot with permissions
elif [ -s $slocatedb ] ; then
locatedb=$slocatedb
else
echo "Warning: using public database. Use \"$0 --explain\" for details." >&2
fi
if [ -z "$1" ] ; then
echo "Usage: $0 pattern" >&2; exit 1
fi
exec grep -i "$1" $locatedb