#!/bin/bash

RAND="$$$RANDOM"

if ionice -c3 nice -n 19 /opt/bin/updatedb -l no -o /data/sites/slackware.uk/files/search.db.$RAND -U /data/depository >/dev/null 2>&1; then
  mv /data/sites/slackware.uk/files/search.db.$RAND /data/sites/slackware.uk/files/search.db 2>/dev/null || {
    printf "%s: %s\\n" "${0##*/}" "failed to move mirrors search database into place" >&2
    rm -f /data/sites/slackware.uk/files/search.db.$RAND
    exit 1
  }
else
  printf "%s: %s\\n" "${0##*/}" "mirrors search database update failed" >&2
  rm -f "/data/sites/slackware.uk/files/search.db.$RAND"
  exit 1
fi

exit 0
