local/bin/updatedb-local: Add FOLDERS argument and only update external drives

master
Pierre Neidhardt 2018-05-23 17:50:53 +02:00
parent e4a156c756
commit ffa143b5f6
1 changed files with 28 additions and 4 deletions

View File

@ -1,5 +1,24 @@
#!/bin/sh #!/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 '$MEDIA_DB' at the target root.
EOF
exit
fi
update() { update() {
[ $# -ne 2 ] && set -- "$1" "$1/locate.db" [ $# -ne 2 ] && set -- "$1" "$1/locate.db"
echo >&2 "Updating '$2' database for '$1'..." echo >&2 "Updating '$2' database for '$1'..."
@ -11,15 +30,20 @@ update() {
--prunenames=".git .hg .svn .cache Trash .Trash-$(id -u)" --prunenames=".git .hg .svn .cache Trash .Trash-$(id -u)"
} }
update "/" "$HOME/.cache/locate.db" update "/" "$HOME_DB_FOLDER/$DB_FILE"
## Only update external media databases.
for i in "/run/media/$USER"/* "/media/$USER"/*; do for i in "/run/media/$USER"/* "/media/$USER"/*; do
[ -d "$i" ] && update "$i" [ -f "$i/$DB_FILE" ] && update "$i"
done done
if [ ! -d "/media/$USER" ]; then if [ ! -d "/media/$USER" ]; then
for i in "/media/$USER"/*; do for i in "/media"/*; do
[ -d "$i" ] && update "$i" [ -f "$i/$DB_FILE" ] && update "$i"
done done
fi fi
## Create database for the specified folders.
for i; do
[ -d "$i" ] && update "$i"
done