9f6f61cca5b31d7c212305092051269f955044a1
[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
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 secure shell.
131   export CVS_RSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
132   export GIT_SSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
133   
134   # the base checkout list is just to update feisty_meow.  additional folder
135   # names can be added in your customized scripts.  the space at the end of
136   # this variable is important and allows users to extend the list like:
137   #    export REPOSITORY_DIR+="muppets configs"
138   export REPOSITORY_LIST="feisty_meow "
139   
140   # initializes the feisty meow build variables, if possible.
141   function initialize_build_variables()
142   {
143     found_build_vars=0
144     # we need to know the feisty meow directory, or we bail.
145     if [ -z "$FEISTY_MEOW_DIR" ]; then return; fi
146     # pick from our expected generator folder, but make sure it's there...
147     buildvars="$FEISTY_MEOW_SCRIPTS/generator/build_variables.sh"
148     if [ -f "$buildvars" ]; then
149       # yep, that one looks good, so pull in the build defs.
150       source "$buildvars" "$buildvars"
151       found_build_vars=1
152     fi
153     # now augment the environment if we found our build variables.
154     if [ $found_build_vars == 1 ]; then
155       # the binary directory contains handy programs we use a lot.  we set
156       # up the path to it here based on the operating system.
157       export BINDIR=$FEISTY_MEOW_DIR/production/binaries
158       # add binaries created within build to the path.
159       export PATH="$BINDIR:$PATH"
160       # Shared libraries are located via this variable.
161       export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$BINDIR"
162     fi
163   }
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   # load in the build environment.
176   initialize_build_variables
177   
178   ##############
179   
180   # add to the PATH variables used for locating applications.  this step is taken after any
181   # potential overrides from the user.
182   export PATH="$FEISTY_MEOW_GENERATED:$PATH:$(find /usr/local/games -maxdepth 1 -type d -exec echo -n {}: ';' 2>/dev/null)/sbin"
183   
184   ##############
185
186   # set the SHUNIT_DIR so our shunit tests can find the codebase.
187   export SHUNIT_DIR="$FEISTY_MEOW_SCRIPTS/shunit"
188   
189   ##############
190   
191   if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization ends....; fi
192
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.  we also don't guard this
200 # to avoid running it again, because we don't know what mix of functions and
201 # aliases they want to define in there.
202 for i in $FEISTY_MEOW_GENERATED/custom/*.sh; do
203   if [ ! -f "$i" ]; then
204     # skip it if it's not real.
205     continue;
206   fi
207   if [ ! -z "$SHELL_DEBUG" ]; then
208     echo "loading customization: $(basename $(dirname $i))/$(basename $i)"
209   fi
210   source $i
211 done
212