version 1.40.130 release
[feisty_meow.git] / scripts / core / launch_feisty_meow.sh
index 631d78e90717f1a5089b25ed6f38c6e72e85354b..2f8aca0832a1000cd97cbaa150c5ecb725cf7d0b 100644 (file)
 
 ##############
 
+# first step--capture the current path if we haven't already.
+if [ -z "$FEISTY_MEOW_ORIGINAL_PATH" ]; then
+  export FEISTY_MEOW_ORIGINAL_PATH="$PATH"
+fi
+
+##############
+
 # this script cannot handle figuring out where it lives, so approaches that
-# get the WORKDIR will fail.  this is a consequence of this always being used
+# get the THISDIR will fail.  this is a consequence of this always being used
 # in bash's 'source' directive, which does not pass the script name as
 # argument 0.  instead, we just check for the bad condition of a malconfigured
 # script system and try to repair it.
@@ -44,21 +51,39 @@ if [ ! -d "$FEISTY_MEOW_APEX" ]; then
 The feisty meow configuration is damaged somehow.  Please change to the
 directory where it is stored, e.g.:
 
-    cd /opt/feistymeow.org/feisty_meow
+  cd /opt/feistymeow.org/feisty_meow
+
+and run this command (the whole unwieldy multiple line chunk inside the bars):
+
 
-and execute this command:
+##############
+  exec bash -i 3<<EOF 4<&0 <&3
+    echo -e '\n\n^^^ errors above here indicate potential problems in .bashrc ^^^';
+    export FEISTY_MEOW_APEX=\"\$(pwd)\"; export FEISTY_MEOW_SCRIPTS=\$FEISTY_MEOW_APEX/scripts;
+    export FEISTY_MEOW_SHOW_LAUNCH_GREETING=yes;
+    /bin/bash \$(pwd)/scripts/core/reconfigure_feisty_meow.sh;
+    source \$(pwd)/scripts/core/launch_feisty_meow.sh; exec 3>&- <&4
+EOF
+##############
 
-    export FEISTY_MEOW_APEX=\$(pwd); echo \"export FEISTY_MEOW_APEX=\$FEISTY_MEOW_APEX\" \> \$HOME/\$USER.fm-fix ; exec /bin/bash -c 'source \$HOME/\$USER.fm-fix; /bin/bash \$FEISTY_MEOW_APEX/scripts/core/reconfigure_feisty_meow.sh ; source \$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh ; /bin/bash -i --norc --noprofile '
 
-Note that this assumes that the .bashrc file could still need editing to fix
-an erroneous FEISTY_MEOW_APEX variable, so we skip it when bash runs.   Check
-\$HOME/.bashrc to see if a change there will fix the above error.
+This code snippet assumes that the .bashrc file could still need editing to
+fix an erroneous FEISTY_MEOW_APEX variable, so we skip it above when bash
+runs.  Check \$HOME/.bashrc to see if a change there will fix the problem.
 
 "
+else
+  # apex is good, so let's make the scripts good too.
+  if [ -z "$FEISTY_MEOW_SCRIPTS" -o ! -d "$FEISTY_MEOW_SCRIPTS" ]; then
+    export FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_APEX/scripts"
+  fi
+  # check again to test our belief system...
+  if [ ! -d "$FEISTY_MEOW_SCRIPTS" ]; then
+    unset NO_REPAIRS_NEEDED
+    echo -e "The feisty meow scripts cannot be found under the current top:\n  FEISTY_MEOW_APEX=$FEISTY_MEOW_APEX"
+  fi
 fi
 
-#; source \$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh
-
 if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
 
   # we believe it's safe to run through the rest of this script.
@@ -68,12 +93,26 @@ if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
   # some preconditions we want to establish before loading anything...
   
   # make sure that aliases can be used in non-interactive shells.
+  # this causes all aliases that are currently defined for this shell to
+  # be inherited by subshells that this shell starts.  this is unusual,
+  # but is preferred for my workflow in feisty meow scripts; it saves me
+  # time re-adding aliases if i can count on them already being there.
+  # this is a problem if you *don't* want the aliases there though.  we can
+  # solve that problem by running bash with the "-O expand_aliases" flags to
+  # stop the expansion for the next subshell.
   shopt -s expand_aliases
   
   # patch the user variable if we were launched by one of our cron jobs.
   if [ -z "$USER" -a ! -z "$CRONUSER" ]; then
     export USER="$CRONUSER"
   fi
+
+  # use the xauth info if we were given one in the environment.
+  # this allows root or other su'd identities to create windows with same
+  # display variable.
+  if [ ! -z "$DISPLAY" -a ! -z "$IMPORTED_XAUTH" ]; then
+    xauth add $DISPLAY . $IMPORTED_XAUTH
+  fi
   
   ##############
   
@@ -86,7 +125,7 @@ if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
     # this is our single entry point we can use without knowing any variables
     # yet in the initialization process.
     export FEISTY_MEOW_LOADING_DOCK="$HOME/.zz_feisty_loading"
-  #hmmm: the above is kind of a constant.  that's not so great.
+#hmmm: the above is kind of a constant.  that's not so great.
   
     # make sure our main variables are established.
     FEISTY_MEOW_VARIABLES_LOADING_FILE="$FEISTY_MEOW_LOADING_DOCK/fmc_variables.sh"
@@ -104,9 +143,8 @@ if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
     fi
   
     ##############
-  
+
     if [ -z "$ERROR_OCCURRED" ]; then
-  
       # pull in our generated variables that are the minimal set we need to find
       # the rest of our resources.
       source "$FEISTY_MEOW_VARIABLES_LOADING_FILE"
@@ -120,10 +158,9 @@ if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
   ##############
 
   if [ -z "$ERROR_OCCURRED" ]; then
-
-    # load the larger body of standard feisty meow variables into the environment.
-    # we actually want this to always run also; it will decide what variables need
-    # to be set again.
+    # no error occurred in our tests above, so load the larger body of standard feisty
+    # meow variables into the environment.  we actually want this to always run also;
+    # it will decide what variables need to be set again.
     source "$FEISTY_MEOW_SCRIPTS/core/variables.sh"
 
     ##############
@@ -138,6 +175,7 @@ if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
 
     ##############
 
+#hmmm: abstract this to a twiddle shell options method.
     # check hash table before searching path.
     shopt -s checkhash
     # don't check path for sourced files.
@@ -188,5 +226,35 @@ if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
 
   fi  # no error occurred.
 
+  if [ ! -z "$FEISTY_MEOW_SHOW_LAUNCH_GREETING" ]; then
+    echo
+    echo
+    echo "welcome to the feisty meow zone of peace, one of many refuges in the uncountably"
+    echo "infinite multiverses that are hypothetically possible."
+    echo
+    echo
+    unset FEISTY_MEOW_SHOW_LAUNCH_GREETING
+  fi
+
+  # only run this hello file if the core feisty meow support haven't been loaded already.  this
+  # hopefully guarantees we show the info at most once in one shell continuum.
+  # this can also be disabled if the NO_HELLO variable has a non-empty value.
+  type CORE_VARIABLES_LOADED &>/dev/null
+  if [ $? -ne 0 -a -z "$NO_HELLO" ]; then
+    # print out a personalized hello file if we find one.
+    if [ -f ~/hello.txt ]; then
+      echo
+      sep 28
+      perl $FEISTY_MEOW_SCRIPTS/*/filedump.pl ~/hello.txt
+      sep 28
+      echo
+    fi
+    # from now on there should be no extra helloing.
+    export NO_HELLO=true
+  fi
+
+  # load the last bits we do here.
+  source "$FEISTY_MEOW_LOADING_DOCK/fmc_ending_sentinel.sh"
+
 fi # "$NO_REPAIRS_NEEDED" was == "true"