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