#!/bin/bash

#only argument is dir of scripts to run, if omitted use current directory
if [ -z "$1" ] ; then
	echo "usage: $0 directory-with-scripts-to-run"
	exit 0
else
	SDIR=$1
fi

#could use run-parts --verbose --regex '^[0-9.]*[a-zA-Z0-9_-]+$'  $SDIR
# but what if behaviour of run-parts changes  in regards to ordering with decimals? better if we have full control
# we use decimals so we can insert things in-between ad-infinitum

#we'll source things to keep variables easily available
# BUT NOTE: if you do an exit from within one of these script the entire thing will stop !

echo $0 running scripts from $SDIR

for T in `ls $SDIR | egrep '^[0-9.]*[a-zA-Z0-9_-]+$' | sort -n `  ; do 
	#don't need to make each one executable, not meant to be executed on their own
	#if [ -x $T ] ; then
	bash -n $SDIR/$T > /dev/null 2>&1
	if [ $? -eq 0 ] ; then
		echo gsbp sourcing: $T 
		. $SDIR/$T
	else
		echo "gsbp NOT sourcing due to bash syntax error: $T"
	fi
	
done

