#!/bin/bash
#                       /usr/local/bin/heard
# https://crystalfaeries.net/posix/bin/heard
# celeste:crystalfaery HEARD 2021-03-31 04:27:49+00:00
# https://crystalfaeries.net/posix/bin/saw
#                       /usr/local/bin/saw
# The purpose of this script is to mark as heard or seen
# an entire folder of media of the same file .extension
# as that we have been prompted to examine (e.g. via "monitor")
# ONE of the media contained within that folder,
# and we wish to not have to step through
# each media in the folder via our /usr/local/bin/monitor script.

# WE SHOULD recode this to accept multiple arguments vs only 1.
if [ $# -ne 1 ]
then
	head -n 10 "${0}"	# minimal help :-)
	exit	0		# help is normal
else	# accept:
	# a /home absolute file path (with leading garbage we ignore), or:
	# a file:	URL syntax prefix, or
	# a http:	URL prefix for our own website content, or
	# a https:	URL prefix for our own website content, AND THEN
	# We translate /home/crystalfaeries.net to ${HOME}/crystalfaeries.net
	# (implying we expect to access our website content via our login directory,
	#  as our webhost does not give us permission to play in /home,
	#  we depend upon $HOME/symlinks to have equal paths for script to work)
cd	# There's no place like Om...
	target=$(echo "${1}" | sed 's/^file:\/\///; s/^http:\/\/crystalfaeries.net\//\/home\/celeste\/crystalfaeries.net\//; s/^https:\/\/crystalfaeries.net\//\/home\/celeste\/crystalfaeries.net\//; s/^\/home\/celeste\/crystalfaeries.net//')
echo   "TARGET: ${target}"													# debug
	real="$(realpath "${target}")"
echo   "REAL: ${real}"														# debug
	rdir="${real%/*}"
echo   "RDIR: ${rdir}"														# debug
	rname="${real##*/}"
echo   "RNAME: ${rname}"													# debug
	rext="${rname##*.}"
echo   "REXT: ${rext}"														# debug
	ls -d "${rdir}"/*."${rext}"	>>	~/.dush.media.txt
fi

