Merge branch 'release-2.140.93'
[feisty_meow.git] / scripts / core / launch_feisty_meow.sh
1 #!/bin/bash
2
3 ##############
4
5 # Fred Hamster's Feisty Meow Concerns Ltd. Startup Profile.
6 #
7 # This file is useful within .profile or other initialization scripts.
8 #
9 # Author: Chris Koeritz
10
11 ##############
12
13 # DEBUG_FEISTY_MEOW: if this variable is non-empty, then it causes the feisty meow
14 # scripts to print more diagnostic information when they run.  not all
15 # scripts support this, but the core ones do.
16
17 #export DEBUG_FEISTY_MEOW=true
18
19 ##############
20
21 # this script cannot handle figuring out where it lives, so approaches that
22 # get the WORKDIR will fail.  this is a consequence of this always being used
23 # in bash's 'source' directive, which does not pass the script name as
24 # argument 0.  instead, we just check for the bad condition of a malconfigured
25 # script system and try to repair it.
26
27 # check if any crucial folder is hosed.  we will torch the existing config
28 # to the extent we can.
29 if [ ! -d "$FEISTY_MEOW_SCRIPTS" -o ! -d "$FEISTY_MEOW_APEX" ]; then
30   # wipe out the offending variable(s).
31   unset FEISTY_MEOW_SCRIPTS FEISTY_MEOW_APEX
32   # clean out any unfortunate wrongness that may exist in our generated areas.
33   if [ -d "$"FEISTY_MEOW_LOADING_DOCK ]; then \rm -rf "$FEISTY_MEOW_LOADING_DOCK"; fi
34   if [ -d "$FEISTY_MEOW_GENERATED_STORE" ]; then \rm -rf "$FEISTY_MEOW_GENERATED_STORE"; fi
35   # also wipe any values from the variables pointing at generated stuff.
36   unset FEISTY_MEOW_LOADING_DOCK FEISTY_MEOW_GENERATED_STORE
37   exec "$*"
38 fi
39
40 ##############
41
42 # some preconditions we want to establish before loading anything...
43
44 # make sure that aliases can be used in non-interactive shells.
45 shopt -s expand_aliases
46
47 # patch the user variable if we were launched by one of our cron jobs.
48 if [ -z "$USER" -a ! -z "$CRONUSER" ]; then
49   export USER="$CRONUSER"
50 fi
51
52 ##############
53
54 export ERROR_OCCURRED=
55   # there have been no errors to start with, at least.  we will set this
56   # to non-empty if something bad happens.
57
58 if [ -z "$FEISTY_MEOW_LOADING_DOCK" ]; then
59   # FEISTY_MEOW_LOADING_DOCK is where the generated files are located.
60   # this is our single entry point we can use without knowing any variables
61   # yet in the initialization process.
62   export FEISTY_MEOW_LOADING_DOCK="$HOME/.zz_feisty_loading"
63 #hmmm: the above is kind of a constant.  that's not so great.
64
65   # make sure our main variables are established.
66   FEISTY_MEOW_VARIABLES_LOADING_FILE="$FEISTY_MEOW_LOADING_DOCK/fmc_variables.sh"
67   if [ ! -f "$FEISTY_MEOW_VARIABLES_LOADING_FILE" ]; then
68     echo -e "\
69
70 The feisty meow scripts need initialization via the bootstrap process.  For\n\
71 example, if the feisty meow folder lives in '$DEFAULT_FEISTYMEOW_ORG_DIR', then this\n\
72 command bootstraps feisty meow:\n\
73 \n\
74   bash $example_dir/feisty_meow/scripts/core/reconfigure_feisty_meow.sh\n\
75 \n\
76 \n"
77     ERROR_OCCURRED=true
78   fi
79
80   ##############
81
82   if [ -z "$ERROR_OCCURRED" ]; then
83
84     # pull in our generated variables that are the minimal set we need to find
85     # the rest of our resources.
86     source "$FEISTY_MEOW_VARIABLES_LOADING_FILE"
87
88     # Set up the temporary directory.
89     source "$FEISTY_MEOW_SCRIPTS/core/create_tempdir.sh"
90   fi
91
92 fi
93
94 ##############
95
96 if [ -z "$ERROR_OCCURRED" ]; then
97
98   # load the larger body of standard feisty meow variables into the environment.
99   # we actually want this to always run also; it will decide what variables need
100   # to be set again.
101   source "$FEISTY_MEOW_SCRIPTS/core/variables.sh"
102
103   ##############
104   
105   # include helpful functions.  we do this every time rather than making it part
106   # of variable initialization, because functions cannot be exported to
107   # sub-shells in bash.
108   source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
109   
110   # load some helper methods for the terminal which we'll use below.
111   source "$FEISTY_MEOW_SCRIPTS/tty/terminal_titler.sh"
112
113   ##############
114   
115   # check hash table before searching path.
116   shopt -s checkhash
117   # don't check path for sourced files.
118   shopt -u sourcepath
119   # ignore duplicate lines.
120   HISTCONTROL=ignoredups
121   # append to the history file.
122   shopt -s histappend
123   # automatically update window size if needed.
124   shopt -s checkwinsize
125
126   ##############
127
128   # make history writes immediate to avoid losing history if bash is zapped.
129   echo $PROMPT_COMMAND | grep -q history
130   if [ $? -ne 0 ]; then
131     # we only change the prompt command if we think it hasn't already been done.
132     export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
133   fi
134   
135   ##############
136   
137   # perform the bulkier parts of the initialization process.
138   
139   if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo "heavyweight init begins..."; fi
140   
141   # set up the aliases for the shell, but only if they are not already set.
142   type CORE_ALIASES_LOADED &>/dev/null
143   if [ $? -ne 0 ]; then
144     if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
145       echo "the aliases were missing, now they are being added..."
146     fi
147     source "$FEISTY_MEOW_LOADING_DOCK/fmc_core_and_custom_aliases.sh"
148   fi
149   
150   #echo before the new labelling, terminal titles have:
151   #show_terminal_titles
152   
153   # a minor tickle of the title of the terminal, unless we already have some history.
154   label_terminal_with_info
155   
156   if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo "heavyweight init is done."; fi
157   
158   if [ -z "$ERROR_OCCURRED" ]; then
159     # set a sentinel variable to say we loaded the feisty meow environment.
160     export FEISTY_MEOW_SCRIPTS_LOADED=true
161   fi
162
163 fi  # no error occurred.
164