adopted two new variables
[feisty_meow.git] / scripts / core / functions.sh
index 6f02ae26160a62b4f6abc0b7d31104a8a7195993..6c8bc68ad64e13b805ad1fc326f536558ae2b980 100644 (file)
@@ -2,12 +2,16 @@
 
 # This defines some general, useful functions.
 
+#hmmm: starting to get a bit beefy in here.  perhaps there is a good way to refactor the functions into more specific folders, if they aren't really totally general purpose?
+
+##############
+
 # test whether we've been here before or not.
 skip_all=
 type function_sentinel &>/dev/null
 if [ $? -eq 0 ]; then
   # there was no error, so we can skip the inits.
-  if [ ! -z "$SHELL_DEBUG" ]; then
+  if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
     echo "skipping function definitions, because already defined."
   fi
   skip_all=yes
@@ -17,7 +21,7 @@ fi
 
 if [ -z "$skip_all" ]; then
 
-  if [ ! -z "$SHELL_DEBUG" ]; then
+  if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
     echo "feisty meow function definitions beginning now..."
   fi
 
@@ -698,12 +702,47 @@ return 0
 
   ##############
 
+  # count the number of sub-directories in a directory and echo the result.
+  function count_directories()
+  {
+    local appsdir="$1"; shift
+    numdirs="$(find "$appsdir" -mindepth 1 -maxdepth 1 -type d | wc -l)"
+    echo $numdirs
+  }
+
+  # takes a string and capitalizes just the first character.  any capital letters in the remainder of
+  # the string are made lower case.  the processed string is returned by an echo.
+  function capitalize_first_char()
+  {
+    local to_dromedary="$1"; shift
+    to_dromedary="$(tr '[:lower:]' '[:upper:]' <<< ${to_dromedary:0:1})$(tr '[:upper:]' '[:lower:]' <<< ${to_dromedary:1})"
+    echo "$to_dromedary"
+  }
+
+  # given a source path and a target path, this will make a symbolic link from
+  # the source to the destination, but only if the source actually exists.
+  function make_safe_link()
+  {
+    local src="$1"; shift
+    local target="$1"; shift
+  
+    if [ -d "$src" ]; then
+      ln -s "$src" "$target"
+      check_result "Creating symlink from '$src' to '$target'"
+    fi
+    echo "Created symlink from '$src' to '$target'."
+  }
+
+  ##############
+
+  # NOTE: no more function definitions are allowed after this point.
+
   function function_sentinel()
   {
     return 0; 
   }
   
-  if [ ! -z "$SHELL_DEBUG" ]; then echo "feisty meow function definitions done."; fi
+  if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo "feisty meow function definitions done."; fi
 
   ##############