1f37bb821b9608a2a08a79738da4a902b325a65d
[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 # we'll run this again only if we think it's needed.
13 if [ -z "$NECHUNG" ]; then
14
15   if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization begins...; fi
16   
17   ##############
18   
19   # start with some simpler things.
20   
21   export SCRIPT_SYSTEM=feisty_meow
22   
23   # OS variable records the operating system we think we found.
24   if [ -z "$OS" ]; then
25     export OS=UNIX
26   fi
27   export IS_DARWIN=$(echo $OSTYPE | grep -i darwin)
28   
29   ##############
30   
31   # fallbacks to set crucial variables for feisty meow...
32   
33   # set the main root directory variable for the feisty meow codebase.
34   # this is only used for extreme failure modes, when the values were not
35   # pulled in from our auto-generated config.
36   if [ -z "$FEISTY_MEOW_DIR" ]; then
37     if [ -d "$HOME/feisty_meow" ]; then
38       export FEISTY_MEOW_DIR="$HOME/feisty_meow"
39       export FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_DIR/scripts"
40     fi
41   fi
42   
43   # similarly, make sure we have someplace to look for our generated files, if
44   # we were not handed a value.
45   if [ -z "$FEISTY_MEOW_GENERATED" ]; then
46     # The generated scripts directory is where automatically generated files live.
47     # It is separate from the main body of the shell scripts in order to keep things from
48     # exploding.
49     export FEISTY_MEOW_GENERATED=$HOME/.zz_auto_gen
50   fi
51   
52   ##############
53   
54   # umask sets a permission mask for all file creations.  the mask used here
55   # disallows writing by the "group" and "others" categories.
56   umask 022
57   # ulimit sets user limits.  we set the maximum allowed core dump file size
58   # to zero, because it is obnoxious to see the core dumps from crashed
59   # programs lying around everywhere.
60   ulimit -c 0
61   
62   ##############
63   
64   # user variables, sort of...  if they haven't given themselves a name yet,
65   # then we will make one up for them.
66   
67   # define a default name, if one wasn't already set.
68   if [ -z "$NAME" ]; then
69     export NAME='Unset Q. Namington, Fixley Your Name III'
70   fi
71   
72   ##############
73   
74   # sets the main prompt to a simple default, with user@host.
75   export PS1='\u@\h $ ';
76   
77   ##############
78   
79   # variables for perl.
80   
81   export PERLLIB
82   if [ "$OS" != "Windows_NT" ]; then
83     PERLLIB+="/usr/lib/perl5"
84   else
85     export PERLIO=:perlio
86       # choose perl's IO over the ms-windows version so we can handle file
87       # bytes properly.
88   fi
89   
90   # iterate across our sub-directories and find the perl scripts.
91   # this currently only looks one level down.
92   for i in $FEISTY_MEOW_SCRIPTS/*; do
93     if [ -d "$i" ]; then
94       # check if there is a perl file present; add the folder to PERLLIB if so.
95       ls $i/*.pl &>/dev/null
96       if [ $? -eq 0 ]; then
97         PERLLIB+=":$i"
98       fi
99     fi
100   done
101   #echo PERLLIB is now $PERLLIB
102   
103   ##############
104   
105   # set this so nechung can find its data.
106   export NECHUNG=$FEISTY_MEOW_DIR/database/fortunes.dat
107   
108   # ensure we use the right kind of rsh for security.
109   export CVS_RSH=ssh
110   
111   # sets the history length and max file size so we can get some long history around here.
112   HISTSIZE=1000000
113   HISTFILESIZE=2000000
114   
115   # the base checkout list is just to update feisty_meow.  additional folder
116   # names can be added in your customized scripts.
117   export REPOSITORY_LIST="feisty_meow"
118   
119   # set the editor for subversion if it hasn't already been set.
120   if [ -z "$SVN_EDITOR" ]; then
121   #hmmm: not sure what original reason for having these different was...
122     if [ "$OS"  == "Windows_NT" ]; then
123       export SVN_EDITOR=$(which gvim)
124     else
125       export SVN_EDITOR=$(which vi)
126     fi
127   fi
128   
129   # initializes the feisty meow build variables, if possible.
130   function initialize_build_variables()
131   {
132     found_build_vars=0
133     # we need to know the feisty meow directory, or we bail.
134     if [ -z "$FEISTY_MEOW_DIR" ]; then return; fi
135     # pick from our expected generator folder, but make sure it's there...
136     buildvars="$FEISTY_MEOW_DIR/scripts/generator/build_variables.sh"
137     if [ -f "$buildvars" ]; then
138       # yep, that one looks good, so pull in the build defs.
139       source "$buildvars" "$buildvars"
140       found_build_vars=1
141     fi
142     # now augment the environment if we found our build variables.
143     if [ $found_build_vars == 1 ]; then
144       # the binary directory contains handy programs we use a lot in yeti.  we set up the path to it
145       # here based on the operating system.
146       # note that yeti has recently become more dependent on hoople.  hoople was always the source of
147       # the binaries, but now we don't ship them with yeti any more as pre-built items.  this reduces
148       # the size of the code package a lot and shortens up our possible exposure to compromised
149       # binaries.  people can bootstrap up their own set from hoople now instead.
150       export BINDIR=$FEISTY_MEOW_DIR/production/binaries
151   
152       # add binaries created within build to the path.
153 #    export PATH="$(dos_to_msys_path $BUILD_TOP/build/bin):$PATH"
154       export PATH="$BINDIR:$PATH"
155   
156       # Shared libraries are located via this variable.
157 #    export LD_LIBRARY_PATH="$(dos_to_msys_path $LD_LIBRARY_PATH):$(dos_to_msys_path $BINDIR)"
158       export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$BINDIR"
159     fi
160   }
161   
162   # load in the build environment.
163   initialize_build_variables
164   
165   ##############
166   
167   # windoze specific patching up missing things.
168   
169   if [ "$OS" == "Windows_NT" ]; then
170     export HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
171   fi
172   
173   ##############
174   
175   # pull in the custom overrides for feisty_meow scripts.  this is done last,
176   # because we want to set everything up as expected, then let the user
177   # override individual variables and definitions.
178   for i in $FEISTY_MEOW_GENERATED/custom/*.sh; do
179     if [ ! -f "$i" ]; then
180       # skip it if it's not real.
181       continue;
182     fi
183     if [ ! -z "$SHELL_DEBUG" ]; then
184       echo "loading customization: $(basename $(dirname $i))/$(basename $i)"
185     fi
186     source $i
187   done
188   
189   ##############
190   
191   # set the path for locating applications.  this is done after any
192   # potential overrides from the user.
193   #export PATH="$(dos_to_msys_path $BINDIR):$(dos_to_msys_path $FEISTY_MEOW_GENERATED):$PATH:/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/lib:/usr/games:/usr/bin:."
194   export PATH="$FEISTY_MEOW_GENERATED:$PATH:/sbin:."
195 ###noise! :/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/lib:/usr/games:/usr/bin:.
196   
197   ##############
198   
199   if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization ends....; fi
200
201 else
202   # we are seeing this lot again, we believe, so make things easier for the
203   # rest of initialization.
204   export LIGHTWEIGHT_INIT=true
205   if [ ! -z "$SHELL_DEBUG" ]; then
206  echo skipped var init and put in lightweight mode due to belief in previous existence.; 
207 fi
208 fi
209