#!/bin/bash # mkslocatedb--Builds the central, public locate database as user nobody, # and simultaneously steps through each user's home directory to find # those that contain an .slocatedb file. If found, an additional, private # version of the locate database will be created for that user. setglobal locatedb = '"/var/locate.db'" setglobal slocatedb = '".slocatedb'" if test $[id -nu] != "root" { echo "$0: Error: You must be root to run this command." > !2 exit 1 } if test $[grep '^nobody:' /etc/passwd] = "" { echo "$0: Error: you must have an account for user 'nobody'" > !2 echo "to create the default slocate database." > !2; exit 1 } cd / # sidestep post-su pwd permission problems # First, create or update the public database su -fm nobody -c "find / -print" > $locatedb !2 >/dev/null echo "building default slocate database (user = nobody)" echo ... result is $[wc -l < $locatedb] lines long. # Now step through the user accounts on the system to see who has # a $slocatedb file in their home directory. for account in [$[cut -d: -f1 /etc/passwd]] { setglobal homedir = $[grep "^$(account):" /etc/passwd | cut -d: -f6] if test $homedir = "/" { continue # refuse to build one for root dir } elif test -e $homedir/$slocatedb { echo "building slocate database for user $account" su -m $account -c "find / -print" > $homedir/$slocatedb \ !2 >/dev/null chmod 600 $homedir/$slocatedb chown $account $homedir/$slocatedb echo ... result is $[wc -l < $homedir/$slocatedb] lines long. } } exit 0