#!/bin/bash
# Version: 0.1.0
# Copyright (c) 2023:
#   Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
#
# Update the locate database used specifically for the search interface on slackware.uk.

# Configuration.
DBFILE="/run/mirrors.db"
FILETREE="/storage/md0"
COMMAND="/usr/bin/updatedb"

# Sanity check.
[[ ! -x "$COMMAND" ]] && {
  printf "%s: '%s' %s\\n" "${0##*/}" "$COMMAND" "is not executable" >&2
  exit 1
}

# Update the database.
nice -n 19 ionice -c3 "$COMMAND" -l 0 -o "$DBFILE" -U "$FILETREE" || {
  printf "%s: %s\\n" "${0##*/}" "failed to update locate database" >&2
  exit 1
}

exit 0
