adopted two new variables
[feisty_meow.git] / scripts / core / variables.sh
1 #!/bin/bash
2
3 ##############
4
5 # variables script:
6 #   Defines the environment variables used by the personalized unix
7 #   environment.
8 # Author: Chris Koeritz
9
10 ##############
11
12 #hmmm: moved from functions.sh; does that hose everything up?
13
14   # defines a variable within the feisty meow environment and remembers that
15   # this is a new or modified definition.  if the feisty meow codebase is
16   # unloaded, then so are all the variables that were defined.
17   # this function always exports the variables it defines.
18   function define_yeti_variable()
19   {
20 # if variable exists already, save old value for restore,
21 # otherwise save null value for restore,
22 # have to handle unsetting if there was no prior value of one
23 # we newly defined.
24 # add variable name to a list of feisty defined variables.
25
26 #hmmm: first implem just sets it up and exports the variable.
27 #  i.e., this method always exports.
28 export "${@}" 
29
30
31 return 0
32   }
33
34
35 ##############
36
37 # this section should always run or bash will reset them on us.
38 # these need to be as minimal as possible.
39
40 # sets the main prompt to a simple default, with user@host.
41 define_yeti_variable PS1='\u@\h $ ';
42 # sets the history length and max file size so we can get some long history around here.
43 define_yeti_variable HISTSIZE=1000000
44 define_yeti_variable HISTFILESIZE=8000000
45
46 # make the TERM available to all sub-shells.
47 define_yeti_variable TERM
48   
49 ##############
50   
51 # we'll run this again only if we think it's needed.
52 if [ -z "$CORE_VARIABLES_LOADED" ]; then
53
54   if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo variables initialization begins...; fi
55   
56   ##############
57   
58   # start with some simpler things.
59   
60   define_yeti_variable SCRIPT_SYSTEM=feisty_meow
61   
62   # OS variable records the operating system we think we found.
63   if [ -z "$OS" ]; then
64     define_yeti_variable OS=UNIX
65   fi
66   define_yeti_variable IS_DARWIN=$(echo $OSTYPE | grep -i darwin)
67   
68   ##############
69
70   # guess the current platform.
71   IS_UNIX=$(uname | grep -i linux)
72   if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i unix); fi
73   if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i darwin); fi
74   IS_DOS=$(uname | grep -i ming)
75   if [ -z "$IS_DOS" ]; then IS_DOS=$(uname | grep -i cygwin); fi
76
77   # now if we're stuck in DOS, try to determine the type of system.
78   if [ ! -z "$IS_DOS" ]; then
79     # IS_MSYS will be non-empty if this is the msys toolset.  otherwise
80     # we assume that it's cygwin.
81     IS_MSYS=$(uname | grep -i ming)
82
83     # if not MSYS, then we'll assume cygwin and set the cygwin root var.
84     if [ -z "$IS_MSYS" ]; then
85       define_yeti_variable CYGROOT=$(cygpath -w -m /)
86     fi
87   fi
88
89   ##############
90   
91   # fallbacks to set crucial variables for feisty meow...
92   
93   # set the main root directory variable for the feisty meow codebase.
94   # this is only used for extreme failure modes, when the values were not
95   # pulled in from our auto-generated config.
96   if [ -z "$FEISTY_MEOW_APEX" ]; then
97     if [ -d "$HOME/feisty_meow" ]; then
98       define_yeti_variable FEISTY_MEOW_APEX="$HOME/feisty_meow"
99       define_yeti_variable FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_SCRIPTS"
100     fi
101   fi
102
103   # main declaration of the transients area.
104   if [ -z "$TMP" ]; then
105     define_yeti_variable TMP=$HOME/.tmp
106   fi
107
108   # set up the top-level for all build creations and logs and such.
109   if [ -z "$FEISTY_MEOW_GENERATED_STORE" ]; then
110     define_yeti_variable FEISTY_MEOW_GENERATED_STORE="$TMP/generated-feisty_meow"
111   fi
112   if [ ! -d "$FEISTY_MEOW_GENERATED_STORE" ]; then
113     mkdir -p "$FEISTY_MEOW_GENERATED_STORE"
114   fi
115   # set up our effluent outsourcing valves.
116   if [ -z "$TEMPORARIES_PILE" ]; then
117     define_yeti_variable TEMPORARIES_PILE="$FEISTY_MEOW_GENERATED_STORE/temporaries"
118   fi
119   if [ ! -d "$TEMPORARIES_PILE" ]; then
120     mkdir -p "$TEMPORARIES_PILE"
121   fi
122
123   # similarly, make sure we have someplace to look for our generated files, if
124   # we were not handed a value.
125   if [ -z "$FEISTY_MEOW_LOADING_DOCK" ]; then
126     # The generated scripts directory is where automatically generated files live.
127     # It is separate from the main body of the shell scripts in order to keep things from
128     # exploding.
129     define_yeti_variable FEISTY_MEOW_LOADING_DOCK=$HOME/.zz_feisty_loading
130   fi
131   
132   ##############
133
134   # set up the color_add variable which is a flag that lets ls know colors work.
135
136   # test if we can use color in ls...
137   ls --help 2>&1 | grep -i -q color
138   if [ $? -eq 0 ]; then
139     export color_add='--color=auto'
140   else
141     export color_add=
142   fi
143   unset test_ls_colors
144   
145   ##############
146
147   # umask sets a permission mask for all file creations.
148   # this mask disallows writes by "group" and "others".
149   umask 022
150   # this mask disallows writes by the "group" and disallows "others" completely.
151   #umask 027
152
153   # ulimit sets user limits.  we set the maximum allowed core dump file size
154   # to zero, because it is obnoxious to see the core dumps from crashed
155   # programs lying around everywhere.
156   ulimit -c 0
157   
158   ##############
159   
160   # user variables, sort of...  if they haven't given themselves a name yet,
161   # then we will make one up for them.
162   
163   # define a default name, if one wasn't already set.
164   if [ -z "$NAME" ]; then
165     define_yeti_variable NAME='Unset Q. Namington, Fixley Your Name III'
166   fi
167   
168   ##############
169   
170   # variables for perl.
171   
172   define_yeti_variable PERLLIB+="/usr/lib/perl5"
173   define_yeti_variable PERL5LIB+="/usr/lib/perl5"
174   if [ "$OS" == "Windows_NT" ]; then
175     define_yeti_variable PERLIO=:perlio
176       # choose perl's IO over the ms-windows version so we can handle file
177       # bytes properly.
178   fi
179
180   # iterate across our sub-directories and find the perl scripts.
181   # this currently only looks one level down.
182   for i in $FEISTY_MEOW_SCRIPTS/*; do
183     if [ -d "$i" ]; then
184       # check if there is a perl file present; add the folder to PERLLIB if so.
185       ls $i/*.pl &>/dev/null
186       if [ $? -eq 0 ]; then
187         PERLLIB+=":$(dos_to_unix_path $i)"
188         PERL5LIB+=":$(dos_to_unix_path $i)"
189       fi
190     fi
191   done
192   #echo PERLLIB is now $PERLLIB
193   
194   ##############
195   
196   # set this so nechung can find its data.
197   define_yeti_variable NECHUNG=$FEISTY_MEOW_APEX/infobase/fortunes.dat
198   
199 ##  # establish a pipe for less to see our beloved syntax highlighting.
200 ##  define_yeti_variable LESSOPEN="| source-highlight -f esc -o STDOUT -i %s"
201
202   # the base checkout list is just to update feisty_meow.  additional folder
203   # names can be added in your customized scripts.  the space at the end of
204   # this variable is important and allows users to extend the list like:
205   #    define_yeti_variable REPOSITORY_DIR+="muppets configs"
206   # see the customize/fred folder for a live example.
207   define_yeti_variable REPOSITORY_LIST="$FEISTY_MEOW_APEX "
208   
209   # the archive collections list is a set of directories that are major
210   # repositories of data which can be synched to backup drives.
211   define_yeti_variable ARCHIVE_COLLECTIONS_LIST=
212
213   # initializes the feisty meow build variables, if possible.
214   function initialize_build_variables()
215   {
216     found_build_vars=0
217     # we need to know the feisty meow directory, or we bail.
218     if [ -z "$FEISTY_MEOW_APEX" ]; then return; fi
219     # pick from our expected generator folder, but make sure it's there...
220     buildvars="$FEISTY_MEOW_SCRIPTS/generator/build_variables.sh"
221     if [ -f "$buildvars" ]; then
222       # yep, that one looks good, so pull in the build defs.
223       source "$buildvars" "$buildvars"
224       found_build_vars=1
225     fi
226     # now augment the environment if we found our build variables.
227     if [ $found_build_vars == 1 ]; then
228       # the binary directory contains our collection of handy programs.
229       define_yeti_variable FEISTY_MEOW_BINARIES=$TARGETS_STORE
230       # add binaries created within build to the path.
231       define_yeti_variable PATH="$(dos_to_unix_path $FEISTY_MEOW_BINARIES):$PATH"
232       # Shared libraries are located via this variable.
233       define_yeti_variable LD_LIBRARY_PATH="$(dos_to_unix_path $LD_LIBRARY_PATH):$(dos_to_unix_path $FEISTY_MEOW_BINARIES)"
234     fi
235   }
236   
237   ##############
238   
239   # windoze specific patching up missing things.
240   
241   if [ "$OS" == "Windows_NT" ]; then
242     define_yeti_variable HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
243   fi
244   
245   ##############
246   
247   # load in the build environment.
248   initialize_build_variables
249   
250   ##############
251   
252   # add to the PATH variables used for locating applications.  this step is taken after any
253   # potential overrides from the user.
254   define_yeti_variable PATH="$(dos_to_unix_path $FEISTY_MEOW_LOADING_DOCK):$PATH:$(find /usr/local/games -maxdepth 1 -type d -exec echo -n {}: ';' 2>/dev/null)/sbin"
255   
256   ##############
257
258   # set the SHUNIT_PATH so our shunit tests can find the codebase.
259   define_yeti_variable SHUNIT_PATH="$FEISTY_MEOW_SCRIPTS/shunit"
260   
261   ##############
262
263   define_yeti_variable CORE_VARIABLES_LOADED=true
264   
265   if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo variables initialization ends....; fi
266 fi
267
268 ##############
269
270 # pull in the custom overrides for feisty_meow scripts.  this is done last,
271 # because we want to set everything up as expected, then let the user
272 # override individual variables and definitions.  we also don't guard this
273 # to avoid running it again, because we don't know what mix of functions and
274 # aliases they want to define in there.
275 for i in $FEISTY_MEOW_LOADING_DOCK/custom/*.sh; do
276   if [ ! -f "$i" ]; then
277     # skip it if it's not real.
278     continue;
279   fi
280   if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
281     echo "loading customization: $(basename $(dirname $i))/$(basename $i)"
282   fi
283   source "$i"
284 done
285