ac708df3f2ae9de03e7a428ff8dcdbc3329f986e
[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 # this section should always run or bash will reset them on us.
13 # these need to be as minimal as possible.
14
15 # sets the main prompt to a simple default, with user@host.
16 export PS1='\u@\h $ ';
17 # sets the history length and max file size so we can get some long history around here.
18 export HISTSIZE=1000000
19 export HISTFILESIZE=8000000
20   
21 ##############
22   
23 # we'll run this again only if we think it's needed.
24 if [ -z "$NECHUNG" ]; then
25
26   if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization begins...; fi
27   
28   ##############
29   
30   # start with some simpler things.
31   
32   export SCRIPT_SYSTEM=feisty_meow
33   
34   # OS variable records the operating system we think we found.
35   if [ -z "$OS" ]; then
36     export OS=UNIX
37   fi
38   export IS_DARWIN=$(echo $OSTYPE | grep -i darwin)
39   
40   ##############
41
42   # guess the current platform.
43   IS_UNIX=$(uname | grep -i linux)
44   if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i unix); fi
45   if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i darwin); fi
46   IS_DOS=$(uname | grep -i ming)
47   if [ -z "$IS_DOS" ]; then IS_DOS=$(uname | grep -i cygwin); fi
48
49   # now if we're stuck in DOS, try to determine the type of system.
50   if [ ! -z "$IS_DOS" ]; then
51     # IS_MSYS will be non-empty if this is the msys toolset.  otherwise
52     # we assume that it's cygwin.
53     IS_MSYS=$(uname | grep -i ming)
54   fi
55
56   ##############
57   
58   # fallbacks to set crucial variables for feisty meow...
59   
60   # set the main root directory variable for the feisty meow codebase.
61   # this is only used for extreme failure modes, when the values were not
62   # pulled in from our auto-generated config.
63   if [ -z "$FEISTY_MEOW_DIR" ]; then
64     if [ -d "$HOME/feisty_meow" ]; then
65       export FEISTY_MEOW_DIR="$HOME/feisty_meow"
66       export FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_SCRIPTS"
67     fi
68   fi
69   
70   # similarly, make sure we have someplace to look for our generated files, if
71   # we were not handed a value.
72   if [ -z "$FEISTY_MEOW_GENERATED" ]; then
73     # The generated scripts directory is where automatically generated files live.
74     # It is separate from the main body of the shell scripts in order to keep things from
75     # exploding.
76     export FEISTY_MEOW_GENERATED=$HOME/.zz_auto_gen
77   fi
78   
79   ##############
80   
81   # umask sets a permission mask for all file creations.  the mask used here
82   # disallows writes by the "group" and disallows "others" completely.
83   umask 027
84   # ulimit sets user limits.  we set the maximum allowed core dump file size
85   # to zero, because it is obnoxious to see the core dumps from crashed
86   # programs lying around everywhere.
87   ulimit -c 0
88   
89   ##############
90   
91   # user variables, sort of...  if they haven't given themselves a name yet,
92   # then we will make one up for them.
93   
94   # define a default name, if one wasn't already set.
95   if [ -z "$NAME" ]; then
96     export NAME='Unset Q. Namington, Fixley Your Name III'
97   fi
98   
99   ##############
100   
101   # variables for perl.
102   
103   export PERLLIB+="/usr/lib/perl5"
104   if [ "$OS" == "Windows_NT" ]; then
105     export PERLIO=:perlio
106       # choose perl's IO over the ms-windows version so we can handle file
107       # bytes properly.
108   fi
109   
110   # iterate across our sub-directories and find the perl scripts.
111   # this currently only looks one level down.
112   for i in $FEISTY_MEOW_SCRIPTS/*; do
113     if [ -d "$i" ]; then
114       # check if there is a perl file present; add the folder to PERLLIB if so.
115       ls $i/*.pl &>/dev/null
116       if [ $? -eq 0 ]; then
117         PERLLIB+=":$(dos_to_unix_path $i)"
118       fi
119     fi
120   done
121   #echo PERLLIB is now $PERLLIB
122   
123   ##############
124   
125   # set this so nechung can find its data.
126   export NECHUNG=$FEISTY_MEOW_DIR/database/fortunes.dat
127   
128   # ensure we use the right kind of secure shell.
129   export CVS_RSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
130   export GIT_SSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
131   
132   # the base checkout list is just to update feisty_meow.  additional folder
133   # names can be added in your customized scripts.  the space at the end of
134   # this variable is important and allows users to extend the list like:
135   #    export REPOSITORY_DIR+="muppets configs"
136   export REPOSITORY_LIST="feisty_meow "
137   
138   # initializes the feisty meow build variables, if possible.
139   function initialize_build_variables()
140   {
141     found_build_vars=0
142     # we need to know the feisty meow directory, or we bail.
143     if [ -z "$FEISTY_MEOW_DIR" ]; then return; fi
144     # pick from our expected generator folder, but make sure it's there...
145     buildvars="$FEISTY_MEOW_SCRIPTS/generator/build_variables.sh"
146     if [ -f "$buildvars" ]; then
147       # yep, that one looks good, so pull in the build defs.
148       source "$buildvars" "$buildvars"
149       found_build_vars=1
150     fi
151     # now augment the environment if we found our build variables.
152     if [ $found_build_vars == 1 ]; then
153       # the binary directory contains handy programs we use a lot.  we set
154       # up the path to it here based on the operating system.
155       export BINDIR=$FEISTY_MEOW_DIR/production/binaries
156       # add binaries created within build to the path.
157       export PATH="$(dos_to_unix_path $BINDIR):$PATH"
158       # Shared libraries are located via this variable.
159       export LD_LIBRARY_PATH="$(dos_to_unix_path $LD_LIBRARY_PATH):$(dos_to_unix_path $BINDIR)"
160     fi
161   }
162   
163   ##############
164   
165   # windoze specific patching up missing things.
166   
167   if [ "$OS" == "Windows_NT" ]; then
168     export HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
169   fi
170   
171   ##############
172   
173   # load in the build environment.
174   initialize_build_variables
175   
176   ##############
177   
178   # add to the PATH variables used for locating applications.  this step is taken after any
179   # potential overrides from the user.
180   export PATH="$(dos_to_unix_path $FEISTY_MEOW_GENERATED):$PATH:$(find /usr/local/games -maxdepth 1 -type d -exec echo -n {}: ';' 2>/dev/null)/sbin"
181   
182   ##############
183
184   # set the SHUNIT_DIR so our shunit tests can find the codebase.
185   export SHUNIT_DIR="$FEISTY_MEOW_SCRIPTS/shunit"
186   
187   ##############
188   
189   if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization ends....; fi
190
191 fi
192
193 ##############
194
195 # pull in the custom overrides for feisty_meow scripts.  this is done last,
196 # because we want to set everything up as expected, then let the user
197 # override individual variables and definitions.  we also don't guard this
198 # to avoid running it again, because we don't know what mix of functions and
199 # aliases they want to define in there.
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