moved define_yeti_variable into the variables, since we potentially need it there...
[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 "$NECHUNG" ]; then
53
54   if [ ! -z "$SHELL_DEBUG" ]; 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   fi
83
84   ##############
85   
86   # fallbacks to set crucial variables for feisty meow...
87   
88   # set the main root directory variable for the feisty meow codebase.
89   # this is only used for extreme failure modes, when the values were not
90   # pulled in from our auto-generated config.
91   if [ -z "$FEISTY_MEOW_DIR" ]; then
92     if [ -d "$HOME/feisty_meow" ]; then
93       define_yeti_variable FEISTY_MEOW_DIR="$HOME/feisty_meow"
94       define_yeti_variable FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_SCRIPTS"
95     fi
96   fi
97   
98   # similarly, make sure we have someplace to look for our generated files, if
99   # we were not handed a value.
100   if [ -z "$FEISTY_MEOW_GENERATED" ]; then
101     # The generated scripts directory is where automatically generated files live.
102     # It is separate from the main body of the shell scripts in order to keep things from
103     # exploding.
104     define_yeti_variable FEISTY_MEOW_GENERATED=$HOME/.zz_auto_gen
105   fi
106   
107   ##############
108   
109   # umask sets a permission mask for all file creations.
110   # this mask disallows writes by "group" and "others".
111   umask 022
112   # this mask disallows writes by the "group" and disallows "others" completely.
113   #umask 027
114
115   # ulimit sets user limits.  we set the maximum allowed core dump file size
116   # to zero, because it is obnoxious to see the core dumps from crashed
117   # programs lying around everywhere.
118   ulimit -c 0
119   
120   ##############
121   
122   # user variables, sort of...  if they haven't given themselves a name yet,
123   # then we will make one up for them.
124   
125   # define a default name, if one wasn't already set.
126   if [ -z "$NAME" ]; then
127     define_yeti_variable NAME='Unset Q. Namington, Fixley Your Name III'
128   fi
129   
130   ##############
131   
132   # variables for perl.
133   
134   define_yeti_variable PERLLIB+="/usr/lib/perl5"
135   if [ "$OS" == "Windows_NT" ]; then
136     define_yeti_variable PERLIO=:perlio
137       # choose perl's IO over the ms-windows version so we can handle file
138       # bytes properly.
139   fi
140   
141   # iterate across our sub-directories and find the perl scripts.
142   # this currently only looks one level down.
143   for i in $FEISTY_MEOW_SCRIPTS/*; do
144     if [ -d "$i" ]; then
145       # check if there is a perl file present; add the folder to PERLLIB if so.
146       ls $i/*.pl &>/dev/null
147       if [ $? -eq 0 ]; then
148         PERLLIB+=":$(dos_to_unix_path $i)"
149       fi
150     fi
151   done
152   #echo PERLLIB is now $PERLLIB
153   
154   ##############
155   
156   # set this so nechung can find its data.
157   define_yeti_variable NECHUNG=$FEISTY_MEOW_DIR/infobase/fortunes.dat
158   
159   # ensure we use the right kind of secure shell.
160 #  define_yeti_variable CVS_RSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
161 #  define_yeti_variable GIT_SSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
162   
163   # the base checkout list is just to update feisty_meow.  additional folder
164   # names can be added in your customized scripts.  the space at the end of
165   # this variable is important and allows users to extend the list like:
166   #    define_yeti_variable REPOSITORY_DIR+="muppets configs"
167   define_yeti_variable REPOSITORY_LIST="feisty_meow "
168   
169   # initializes the feisty meow build variables, if possible.
170   function initialize_build_variables()
171   {
172     found_build_vars=0
173     # we need to know the feisty meow directory, or we bail.
174     if [ -z "$FEISTY_MEOW_DIR" ]; then return; fi
175     # pick from our expected generator folder, but make sure it's there...
176     buildvars="$FEISTY_MEOW_SCRIPTS/generator/build_variables.sh"
177     if [ -f "$buildvars" ]; then
178       # yep, that one looks good, so pull in the build defs.
179       source "$buildvars" "$buildvars"
180       found_build_vars=1
181     fi
182     # now augment the environment if we found our build variables.
183     if [ $found_build_vars == 1 ]; then
184       # the binary directory contains handy programs we use a lot.  we set
185       # up the path to it here based on the operating system.
186       define_yeti_variable BINDIR=$FEISTY_MEOW_DIR/production/binaries
187       # add binaries created within build to the path.
188       define_yeti_variable PATH="$(dos_to_unix_path $BINDIR):$PATH"
189       # Shared libraries are located via this variable.
190       define_yeti_variable LD_LIBRARY_PATH="$(dos_to_unix_path $LD_LIBRARY_PATH):$(dos_to_unix_path $BINDIR)"
191     fi
192   }
193   
194   ##############
195   
196   # windoze specific patching up missing things.
197   
198   if [ "$OS" == "Windows_NT" ]; then
199     define_yeti_variable HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
200   fi
201   
202   ##############
203   
204   # load in the build environment.
205   initialize_build_variables
206   
207   ##############
208   
209   # add to the PATH variables used for locating applications.  this step is taken after any
210   # potential overrides from the user.
211   define_yeti_variable PATH="$(dos_to_unix_path $FEISTY_MEOW_GENERATED):$PATH:$(find /usr/local/games -maxdepth 1 -type d -exec echo -n {}: ';' 2>/dev/null)/sbin"
212   
213   ##############
214
215   # set the SHUNIT_DIR so our shunit tests can find the codebase.
216   define_yeti_variable SHUNIT_DIR="$FEISTY_MEOW_SCRIPTS/shunit"
217   
218   ##############
219   
220   if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization ends....; fi
221 fi
222
223 ##############
224
225 # pull in the custom overrides for feisty_meow scripts.  this is done last,
226 # because we want to set everything up as expected, then let the user
227 # override individual variables and definitions.  we also don't guard this
228 # to avoid running it again, because we don't know what mix of functions and
229 # aliases they want to define in there.
230 for i in $FEISTY_MEOW_GENERATED/custom/*.sh; do
231   if [ ! -f "$i" ]; then
232     # skip it if it's not real.
233     continue;
234   fi
235   if [ ! -z "$SHELL_DEBUG" ]; then
236     echo "loading customization: $(basename $(dirname $i))/$(basename $i)"
237   fi
238   source "$i"
239 done
240