Linux HOWTOs

About | Home | Search


HOWTO: slocate
Description: Secure Locate - locates only files that the user has access to
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything


# Secure Locate 3.1
# =================
# Slackware 12.0, 12.1, 12.2, 13.0, 13.1, 13.37: slocate 3.1
#
# Slackware 8.1 and up split the 'find' package (GNU findutils) into two
# packages: 'slocate' and 'findutils' (the find utils minus locate).
# If you're replacing the 'find' package from Slackware 8.0 or less, go to
# the findutils howto first.

# If you ever want to uninstall slocate, or clean up files from an old
# version before installing a new one, skip down to the bottom for
# instructions.

# As I write this, the slocate home page at http://slocate.trakker.ca/
# is down.  The FQDN does not resolve, though the domain is still registered,
# trakker.ca and www.trakker.ca don't go anywhere.  The Freecode project page
# still links to the down home page URL.  Another possibility, if it ever
# picks up again is the Sourceforge project page:
# http://slocate.sourceforge.net/
# The home page URL linked to there (www.geekreview.org/slocate/ is 404
# too).

# If you are looking for an updatedb/locate that is in active development,
# you may want to consider one of these:
# GNU findutils' locate
# mlocate

# If by the time you try to download this it is no longer available at the
# download URL below, you can probably get it from another 
# Slackware mirror under /pub/slackware/slackware-xx/source/a/slocate/

# Get
cd
test -f installed/slocate-3.1.tar.gz && mv installed/slocate-3.1.tar.gz .
test ! -f slocate-3.1.tar.gz &&
 wget ftp://slackware.mirrors.tds.net/pub/slackware/slackware-13.37/\
source/a/slocate/slocate-3.1.tar.gz

# Verify tarball w/ md5sum:
# (this came from my gpg-verified tarball)
echo "908e6949d959ae7b686c10bb76b35bf3  slocate-3.1.tar.gz" | md5sum -c

# Verify tarball w/ md5sum:
# (this also came from my gpg-verified tarball)
echo "e427552664385b86931b7626c26bd95ae5f9f085  slocate-3.1.tar.gz" | \
 sha1sum -c

# Verify tarball w/ gpg:
( gpg --list-keys 746C51F4 > /dev/null 2>&1 || gpg --recv-keys 746C51F4 ) &&
 wget ftp://slackware.mirrors.tds.net/pub/slackware/slackware-13.37/\
source/a/slocate/slocate-3.1.tar.gz.sign &&
  gpg --verify slocate-3.1.tar.gz.sign && rm slocate-3.1.tar.gz.sign

# 'make install' will try to add a group 'slocate' if one doesn't already
# exist.  If you use something other than passwd/shadow/group like LDAP,
# add the group there before running make install below.

# 'make install' will run ./install-cron which tries to set up cron to run
# slocate every morning.  If you have the
# /etc/cron.(hourly|daily|weekly|monthly) directories set up, it'll put a
# slocate script in /etc/cron.daily/  If not, it'll try to add a crontab
# entry to /etc/crontab, which does not exist.  See the bottom of the
# howto for more info about cron.

# Extract the source
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "slocate-*" -exec rm -r {} \;
tar xzvf ~/slocate-3.1.tar.gz
cd slocate-3.1
test $UID = 0 && chown -R root:root .

# Build it
make

# Become root to install it
su

# Remove the Slackware package
test -x /sbin/removepkg && /sbin/removepkg slocate

# Add a slocate group, if you don't already have them
getent group | egrep "^slocate:" || groupadd slocate

# Install it
install -s -m 2755 -g slocate src/slocate /usr/bin/
ln -sf /usr/bin/slocate /usr/bin/locate
ln -sf /usr/bin/slocate /usr/bin/updatedb
install -d -m 0750 -g slocate /var/lib/slocate
install -m 0644 doc/slocate.1 doc/updatedb.1 /usr/man/man1/

# If this is a new installation (if not, you're done):
cat << EOF > /etc/updatedb.conf
export PRUNEFS="devpts NFS nfs afs proc smbfs autofs iso9660 udf"
export PRUNEPATHS="/dev /proc /sys /tmp /usr/tmp /var/tmp /afs /net"
EOF
chmod 600 /etc/updatedb.conf

# If you have the /etc/cron.(hourly|daily|weekly|monthly) directories set up
# (Slack >= 8.1 comes with a crontab that will use them), create a a
# new /etc/cron.daily/slocate script.
test -d /etc/cron.daily &&
 ( cp debian/cron.daily /etc/cron.daily/slocate
   chmod 700 /etc/cron.daily/slocate )

# If you don't have the cron.* directories set up, add a cron job to root's
# crontab like this:
#
## Update the slocate database at 6am:
# 0 6 * * *       /usr/bin/updatedb

# And finally, run /usr/bin/updatedb manually to build the slocate database
# the first time
/usr/bin/updatedb

# The updatedb and locate commands are symlinks to the slocate binary.  If
# you have another locate, like the one from GNU findutils, you can run
# 'slocate -u -c /etc/updatedb.conf' to update the database like 'updatedb'
# does, and 'slocate -i' or 'slocate -r' to do a search like 'locate' does.

# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .

# Become yourself again
exit

# Save the tarball for later
cd
mkdir -p installed
rm -f installed/slocate-*.tar.gz
mv slocate-3.1.tar.gz installed/


# If you ever want to uninstall Secure Locate, this should do it:
cd
su
test -d src/slocate-* && ( cd src/slocate-* ; make uninstall )
rm -f /usr/bin/slocate /usr/man/man1/slocate.1 /usr/man/man1/updatedb.1
test -L /usr/bin/locate && rm /usr/bin/locate
test -L /usr/bin/updatedb && rm /usr/bin/updatedb
test -d /var/lib/slocate && rm -r /var/lib/slocate
exit
find ~/src -maxdepth 1 -type d -name "slocate-*" -exec rm -r {} \;
rm -f ~/installed/slocate-*.tar.*

Back to the list


Last updated: Tue, 07 Aug 2018 12:06:17 -0400
Jason Englander <jason at englanders dot us>