#!/bin/bash
set -u

FIND_BIN='find'

if [ $# -ne 2 ]; then
	(
		echo "Usage: $0 MINUTES STORAGE_DIR"
		echo "Tests if there are recent snapshots in a specified folder."
		echo -e "\nArguments list:"
		echo -e "\tMINUTES       If the last snapshot is older than this time, an error is issued."
		echo -e "\tSTORAGE_DIR   Where the screenshots are stored.\n"
	) >&2
	exit 1
fi

MINUTES="$1"
DIR="$2"

if [[ -z $("$FIND_BIN" "$DIR" -mindepth 1 -maxdepth 1 -type d -mmin -"$MINUTES") ]]; then
	echo "Error, no recent desktop snapshots were found in '$DIR' for the last $MINUTES minutes."
fi

