#!/bin/sh

if [ "$(id -u)" -eq 0 ]; then
    echo "WARNING: Running updatedb as root will index the entire file" >&2
    echo "hierarchy, so everyone with access to the database file will be" >&2
    echo "able to see it, including the content of private directories." >&2
    echo "This is a security risk." >&2
    echo >&2
    echo "To update the global database according to the settings in" >&2
    echo "/etc/sysconfig/locate, run:" >&2
    echo "  systemctl start plocate-updatedb" >&2
    echo "To run it automatically once a day, run:" >&2
    echo "  systemctl enable --now plocate-updatedb.timer" >&2
    echo "Alternatively, to update your personal database with your user privileges, run:" >&2
    echo "  user-updatedb" >&2
    echo "Or, to run it automatically once a day, run:" >&2
    echo "  systemctl --user enable --now plocate-user-updatedb.timer" >&2

    if [ -t 0 ]; then
        echo "Continue anyway? (y/N)"
        read -r reply
        if [ "$reply" != "y" ] && [ "$reply" != "Y" ]; then
            exit 1
        fi
    fi
fi

exec /usr/sbin/updatedb.bin "$@"
