#!/bin/sh
set -e

SCRATCH="$(pwd)/notmuch-perf_$(date +%F_%T)"
CONFIG_ORIG=${NOTMUCH_CONFIG:-$HOME/.notmuch-config}

if ! [ -f "$CONFIG_ORIG" ]; then
   echo "Error: No configuration found at $CONFIG_ORIG"
   echo "Please provide a default configuration file to specify the mail to index."
   exit 1
fi

mkdir "$SCRATCH"
cd "$SCRATCH"

MAIL_PATH_ORIG=$(notmuch config get database.path)
MAIL_PATH="$SCRATCH/mail"

export NOTMUCH_CONFIG="$SCRATCH/notmuch-config"
cp "$CONFIG_ORIG" "$NOTMUCH_CONFIG"

ln -s "$MAIL_PATH_ORIG" "$MAIL_PATH"

echo "Now running notmuch new to index all mail"
time notmuch new

