use CRONUSER if USER is blank
[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 # SHELL_DEBUG: 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 SHELL_DEBUG=true
18
19 ##############
20
21 # patch the user variable if we were launched by one of our cron jobs.
22 if [ -z "$USER" -a ! -z "$CRONUSER" ]; then
23   export USER="$CRONUSER"
24 fi
25
26 ##############
27
28 export ERROR_OCCURRED=
29   # there have been no errors to start with, at least.  we will set this
30   # to non-empty if something bad happens.
31
32 if [ -z "$FEISTY_MEOW_LOADING_DOCK" ]; then
33   # FEISTY_MEOW_LOADING_DOCK is where the generated files are located.
34   # this is our single entry point we can use without knowing any variables
35   # yet in the initialization process.
36   export FEISTY_MEOW_LOADING_DOCK="$HOME/.zz_feisty_loading"
37 #hmmm: the above is kind of a constant.  that's not so great.
38
39   # make sure our main variables are established.
40   FEISTY_MEOW_VARIABLES_LOADING_FILE="$FEISTY_MEOW_LOADING_DOCK/fmc_variables.sh"
41   if [ ! -f "$FEISTY_MEOW_VARIABLES_LOADING_FILE" ]; then
42     echo -e '\n\n'
43     echo "Feisty meow scripts need initialization via the bootstrap process, e.g.:"
44     echo "  bash $HOME/feisty_meow/scripts/core/reconfigure_feisty_meow.sh"
45     echo -e '\n\n'
46     ERROR_OCCURRED=true
47   fi
48
49   ##############
50
51   # pull in our generated variables that are the minimal set we need to find
52   # the rest of our resources.
53   source "$FEISTY_MEOW_VARIABLES_LOADING_FILE"
54
55   # Set up the temporary directory.
56   source "$FEISTY_MEOW_SCRIPTS/core/create_tempdir.sh"
57
58 fi
59
60 ##############
61
62 # load the larger body of standard feisty meow variables into the environment.
63 # we actually want this to always run also; it will decide what variables need
64 # to be set again.
65 source "$FEISTY_MEOW_SCRIPTS/core/variables.sh"
66
67 ##############
68   
69 # include helpful functions.  we do this every time rather than making it part
70 # of variable initialization, because functions cannot be exported to
71 # sub-shells in bash (much like aliases cannot, to our infinite chagrin after
72 # having migrated from korn shell...).
73 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
74   
75 # load some helper methods for the terminal which we'll use below.
76 source "$FEISTY_MEOW_SCRIPTS/tty/terminal_titler.sh"
77
78 ##############
79   
80 # check hash table before searching path.
81 shopt -s checkhash
82 # don't check path for sourced files.
83 shopt -u sourcepath
84 # ignore duplicate lines.
85 HISTCONTROL=ignoredups
86 # append to the history file.
87 shopt -s histappend
88 # automatically update window size if needed.
89 shopt -s checkwinsize
90
91 ##############
92
93 # make history writes immediate to avoid losing history if bash is zapped.
94 echo $PROMPT_COMMAND | grep -q history
95 if [ $? -ne 0 ]; then
96   # we only change the prompt command if we think it hasn't already been done.
97   export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
98 fi
99
100 ##############
101
102 # perform the bulkier parts of the initialization process.
103
104 if [ ! -z "$SHELL_DEBUG" ]; then echo "heavyweight init begins..."; fi
105
106 # set up the aliases for the shell, but only if they are not already set.
107 type CORE_ALIASES_LOADED &>/dev/null
108 if [ $? -ne 0 ]; then
109   if [ ! -z "$SHELL_DEBUG" ]; then
110     echo "the aliases were missing, now they are being added..."
111   fi
112   source "$FEISTY_MEOW_LOADING_DOCK/fmc_core_and_custom_aliases.sh"
113 fi
114
115 #echo before the new labelling, terminal titles have:
116 #show_terminal_titles
117
118 # a minor tickle of the title of the terminal, unless we already have some history.
119 label_terminal_with_info
120
121 if [ ! -z "$SHELL_DEBUG" ]; then echo "heavyweight init is done."; fi
122
123 if [ -z "$ERROR_OCCURRED" ]; then
124   # set a sentinel variable to say we loaded the feisty meow environment.
125   export FEISTY_MEOW_SCRIPTS_LOADED=true
126 fi
127