argh, the crucial fix still not working.
[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 # we start out thinking things are good.
28 NO_REPAIRS_NEEDED=true
29
30 # check if any crucial folder is hosed.  we will torch the existing config
31 # to the extent we can.
32 if [ ! -d "$FEISTY_MEOW_APEX" ]; then
33   # flag some problems.
34   unset NO_REPAIRS_NEEDED
35   # wipe out the offending variable(s).
36   unset FEISTY_MEOW_SCRIPTS FEISTY_MEOW_APEX
37   # clean out any unfortunate wrongness that may exist in our generated areas.
38   if [ -d "$FEISTY_MEOW_LOADING_DOCK" ]; then \rm -rf "$FEISTY_MEOW_LOADING_DOCK"; fi
39   if [ -d "$FEISTY_MEOW_GENERATED_STORE" ]; then \rm -rf "$FEISTY_MEOW_GENERATED_STORE"; fi
40   # also wipe any values from the variables pointing at generated stuff.
41   unset FEISTY_MEOW_LOADING_DOCK FEISTY_MEOW_GENERATED_STORE
42   echo "
43
44 The feisty meow configuration is damaged somehow.  Please change to the
45 directory where it is stored, e.g.:
46
47     cd /opt/feistymeow.org/feisty_meow
48
49 and execute this command:
50
51     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 '
52
53 Note that this assumes that the .bashrc file could still need editing to fix
54 an erroneous FEISTY_MEOW_APEX variable, so we skip it when bash runs.   Check
55 \$HOME/.bashrc to see if a change there will fix the above error.
56
57 "
58 fi
59
60 #; source \$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh
61
62 if [ "$NO_REPAIRS_NEEDED" == "true" ]; then
63
64   # we believe it's safe to run through the rest of this script.
65
66   ##############
67   
68   # some preconditions we want to establish before loading anything...
69   
70   # make sure that aliases can be used in non-interactive shells.
71   shopt -s expand_aliases
72   
73   # patch the user variable if we were launched by one of our cron jobs.
74   if [ -z "$USER" -a ! -z "$CRONUSER" ]; then
75     export USER="$CRONUSER"
76   fi
77   
78   ##############
79   
80   export ERROR_OCCURRED=
81     # there have been no errors to start with, at least.  we will set this
82     # to non-empty if something bad happens.
83   
84   if [ -z "$FEISTY_MEOW_LOADING_DOCK" ]; then
85     # FEISTY_MEOW_LOADING_DOCK is where the generated files are located.
86     # this is our single entry point we can use without knowing any variables
87     # yet in the initialization process.
88     export FEISTY_MEOW_LOADING_DOCK="$HOME/.zz_feisty_loading"
89   #hmmm: the above is kind of a constant.  that's not so great.
90   
91     # make sure our main variables are established.
92     FEISTY_MEOW_VARIABLES_LOADING_FILE="$FEISTY_MEOW_LOADING_DOCK/fmc_variables.sh"
93     if [ ! -f "$FEISTY_MEOW_VARIABLES_LOADING_FILE" ]; then
94       echo -e "\
95   
96   The feisty meow scripts need initialization via the bootstrap process.  For\n\
97   example, if the feisty meow folder lives in '$DEFAULT_FEISTYMEOW_ORG_DIR', then this\n\
98   command bootstraps feisty meow:\n\
99   \n\
100     bash $example_dir/feisty_meow/scripts/core/reconfigure_feisty_meow.sh\n\
101   \n\
102   \n"
103       ERROR_OCCURRED=true
104     fi
105   
106     ##############
107   
108     if [ -z "$ERROR_OCCURRED" ]; then
109   
110       # pull in our generated variables that are the minimal set we need to find
111       # the rest of our resources.
112       source "$FEISTY_MEOW_VARIABLES_LOADING_FILE"
113   
114       # Set up the temporary directory.
115       source "$FEISTY_MEOW_SCRIPTS/core/create_tempdir.sh"
116     fi
117   
118   fi
119
120   ##############
121
122   if [ -z "$ERROR_OCCURRED" ]; then
123
124     # load the larger body of standard feisty meow variables into the environment.
125     # we actually want this to always run also; it will decide what variables need
126     # to be set again.
127     source "$FEISTY_MEOW_SCRIPTS/core/variables.sh"
128
129     ##############
130
131     # include helpful functions.  we do this every time rather than making it part
132     # of variable initialization, because functions cannot be exported to
133     # sub-shells in bash.
134     source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
135
136     # load some helper methods for the terminal which we'll use below.
137     source "$FEISTY_MEOW_SCRIPTS/tty/terminal_titler.sh"
138
139     ##############
140
141     # check hash table before searching path.
142     shopt -s checkhash
143     # don't check path for sourced files.
144     shopt -u sourcepath
145     # ignore duplicate lines.
146     HISTCONTROL=ignoredups
147     # append to the history file.
148     shopt -s histappend
149     # automatically update window size if needed.
150     shopt -s checkwinsize
151
152     ##############
153
154     # make history writes immediate to avoid losing history if bash is zapped.
155     echo $PROMPT_COMMAND | grep -q history
156     if [ $? -ne 0 ]; then
157       # we only change the prompt command if we think it hasn't already been done.
158       export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
159     fi
160
161     ##############
162
163     # perform the bulkier parts of the initialization process.
164
165     if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo "heavyweight init begins..."; fi
166
167     # set up the aliases for the shell, but only if they are not already set.
168     type CORE_ALIASES_LOADED &>/dev/null
169     if [ $? -ne 0 ]; then
170       if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
171         echo "the aliases were missing, now they are being added..."
172       fi
173       source "$FEISTY_MEOW_LOADING_DOCK/fmc_core_and_custom_aliases.sh"
174     fi
175
176     #echo before the new labelling, terminal titles have:
177     #show_terminal_titles
178
179     # a minor tickle of the title of the terminal, unless we already have some history.
180     label_terminal_with_info
181
182     if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo "heavyweight init is done."; fi
183
184     if [ -z "$ERROR_OCCURRED" ]; then
185       # set a sentinel variable to say we loaded the feisty meow environment.
186       export FEISTY_MEOW_SCRIPTS_LOADED=true
187     fi
188
189   fi  # no error occurred.
190
191 fi # "$NO_REPAIRS_NEEDED" was == "true" 
192