ambevar-dotfiles/.local/bin/updatedb-local

50 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
HOME_DB_FOLDER="$HOME/.cache"
DB_FILE="locate.db"
if [ "$1" = "-h" ]; then
cat <<EOF>&2
Usage: ${0##*/} [FOLDERS]
Update the 'locate' databases for the home folder, external drives and the FOLDERS arguments.
For external drives, databases are only updated if found, they are not
automatically created (unless explicitly specified in the FOLDERS arguments).
- The database for the home folder is store in '$HOME_DB_FOLDER/$DB_FILE'.
- Other databases are stored in '$DB_FILE' at the target root.
EOF
exit
fi
update() {
[ $# -ne 2 ] && set -- "$1" "$1/locate.db"
echo >&2 "Updating '$2' database for '$1'..."
## From https://git.archlinux.org/svntogit/packages.git/tree/trunk/updatedb.conf?h=packages/mlocate.
updatedb -l 0 -o "$2" -U "$1" \
--prune-bind-mounts=1 \
--prunefs="9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset cramfs debugfs devpts devtmpfs ecryptfs exofs ftpfs fuse fuse.encfs fuse.sshfs fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs shfs smbfs sockfs sshfs sysfs tmpfs ubifs udf usbfs vboxsf" \
--prunepaths="/gnu/store /afs /mnt /net /sfs /tmp /udev /var/cache /var/lib/pacman/local /var/lock /var/run /var/spool /var/tmp" \
--prunenames=".git .hg .svn .cache Trash .Trash-$(id -u) .snapshots"
}
update "/" "$HOME_DB_FOLDER/$DB_FILE"
## Only update external media databases.
for i in "/run/media/$USER"/* "/media/$USER"/*; do
[ -f "$i/$DB_FILE" ] && update "$i"
done
if [ ! -d "/media/$USER" ]; then
for i in "/media"/*; do
[ -f "$i/$DB_FILE" ] && update "$i"
done
fi
## Create database for the specified folders.
for i; do
[ -d "$i" ] && update "$i"
done