##
# Helper function(s)
#
#	                __ __             __   _             
#	  _____ ____   / // /___   _____ / /_ (_)____   ____ 
#	 / ___// __ \ / // // _ \ / ___// __// // __ \ / __ \
#	/ /__ / /_/ // // //  __// /__ / /_ / // /_/ // / / /
#	\___/ \____//_//_/ \___/ \___/ \__//_/ \____//_/ /_/ 
#
#	Setup various directories/files
#		for output, logs, reports, 
##

function ingest {

  # evaluate ingestDir properties and access
  if [ -d ${ingestDir} ]
    then
	# look for content
	if [ $(ls -d ${ingestDir} 2>/dev/null | wc -l) -eq 0 ]
	  then
		echo "=> Note : no content to assess/evaluate"
		exit 1
	fi
    else
	mkdir -p ${ingestDir} || \
		echo "=> Error : cannot create ingestDir : ${ingestDir}" && \
			exit 1
  fi

}

function sandbox {
  
  # evaluate scratchDir properties
  if [ -d ${scratchDir} ]
    then
	# validate write access
	testfile="${scratchDir}/tmp$$"
	if touch ${testfile} 2>/dev/null
	  then
		rm -f ${testfile} 2>/dev/null
	  else
		echo "=> Error : cannot write to scratchDir : ${scratchDir}"
		exit 1
	fi
    else
	mkdir -p ${scratchDir} || \
		echo "=> Error : cannot create scratchDir : ${scratchDir}"
  fi

}

function archive {
  
  # check archiveDir
  if [ -d ${archiveDir} ]
    then
	# validate write access
	testfile="${archiveDir}/tmp$$"
	if touch ${testfile} 2>/dev/null
	  then
		rm -f ${testfile} 2>/dev/null
	  else
		echo "=> Error : cannot write to archiveDir : ${archiveDir}"
		exit 1
	fi
	
	# look for previous run interval
	if [ ! -e ${archiveDir}/${archiveEval} ]
	  then
		touch -t 197001010000 ${archiveDir}/${archiveEval}
	fi
    else
	echo "=> Error : missing archiveDir : ${archiveDir}"
  fi

}

#function outDir {
#
#  # prepare collection directory
#  export mID=$(cat /etc/machine-id)
#  [ -d ${collectionDir}/${mID} ] || mkdir -p ${collectionDir}/${mID}
#  export outputDir="${collectionDir}/${mID}"
#
#}
#
#function artifacts {
## prep various output artifacts for this run
#
#  # use the currrent run timestamp as parent
#  mkdir -p ${outputDir}/${runTSISO} && \
#  	export oDir="${outputDir}/${runTSISO}"
#
#  # prep the log/report files
#  export LF="${oDir}/${logFile}" && \
#  	echo "#### taksi ############################" > ${LF} && \
#       	echo "     Current Run  : ${runTSISO}" >>${LF} && \
#       	echo "     Previous Run : ${prevTSISO}" >>${LF} && \
#	echo "#######################################" >> ${LF}
#  export RF="${oDir}/${reportFile}" && \
#  	echo "Hints" > ${RF}
#
#}
