+#hmmm: extract to core somewhere...
+# locates a parent directory of a certain name, if possible. returns success
+# (as zero) if the directory was found, and failure if there was no parent
+# named as requested. sets a global variable PARENT_DIR_FOUND to the full
+# directory name that matched, including the name being sought (but omitting
+# any deeper directories than that).
+function find_named_parent_dir()
+{
+ local dir_name_sought="$1"; shift
+ # clear any previous global result.
+ unset PARENT_DIR_FOUND
+ # check for degenerate case of parameter count.
+ if [ -z "$dir_name_sought" ]; then
+ echo "
+find_named_parent_dir: requires a directory name parameter, which will be
+sought out above the current directory. the return value indicates whether
+the requested name was found or not.
+"
+ return 1
+ fi
+ # signal a failure by default with our return value.
+ local retval=1
+ # loop upwards in dir hierarchy to find the name.
+ while true; do
+ local currdir="$(\pwd)"
+ if [ "$currdir" == "/" ]; then
+ # we climbed out of all subdirs. this is a failure case.
+ retval=1
+ break
+ fi
+ # get the base part of our name to check on success.
+ local base="$(basename "$currdir")"
+ if [ "$base" == "$dir_name_sought" ]; then
+ # yes, that is the right name. success case. save our result.
+ export PARENT_DIR_FOUND="$currdir"
+ retval=0
+ break
+ fi
+ # hop up a directory.
+ pushd .. &>/dev/null
+ done
+
+ # rollback any directories we pushed.
+ while popd &>/dev/null; do true; done
+
+ return $retval
+}
+
+# tries to find an appropriate config file for the application.
+function locate_config_file()
+{
+ local app_dirname="$1"; shift
+
+ local configfile="$THISDIR/config/${app_dirname}.app"
+ echo "$(date_stringer): config file guessed?: $configfile" >> "$SSM_LOG_FILE"
+ if [ ! -f "$configfile" ]; then
+ # this is not a good config file. we can't auto-guess the config.
+ echo -e "$(date_stringer):
+There is no specific site configuration file in:
+ $configfile
+We will continue onward using the default and hope that this project follows
+the standard pattern for cakephp projects." >> "$SSM_LOG_FILE"
+ # we'll pull in the default config file we set earlier; this will
+ # reinitialize some variables based on the app name.
+ else
+ # they gave us a valid config file. let's try using it.
+ export SITE_MANAGEMENT_CONFIG_FILE="$configfile"
+ fi
+
+ # try to load the config.
+ source "$SITE_MANAGEMENT_CONFIG_FILE"
+ exit_on_error "loading site management configuration from: $SITE_MANAGEMENT_CONFIG_FILE"
+
+ return 0
+}
+