#!/bin/sh
# Wrapper for updatedb that fixes plocate.db permissions after update.
# When updatedb is run directly (e.g. "sudo updatedb") instead of via
# the systemd service, the database ends up with wrong ownership and
# permissions (root:nobody 0640), making "locate" fail for normal users.
# This wrapper calls the real binary and then fixes permissions.
# See boo#1258669.

/usr/sbin/updatedb.bin "$@"
ret=$?

# Fix permissions if running as root
if [ "$(id -u)" = "0" ]; then
    chown root:root /var/lib/plocate/plocate.db 2>/dev/null
    chmod 0644 /var/lib/plocate/plocate.db 2>/dev/null
fi

exit $ret
