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