improved reload, where incorrect usage of alias on a function was just always reloadi...
[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.
82   # this mask disallows writes by "group" and "others".
83   umask 022
84   # this mask disallows writes by the "group" and disallows "others" completely.
85   #umask 027
86
87   # ulimit sets user limits.  we set the maximum allowed core dump file size
88   # to zero, because it is obnoxious to see the core dumps from crashed
89   # programs lying around everywhere.
90   ulimit -c 0
91   
92   ##############
93   
94   # user variables, sort of...  if they haven't given themselves a name yet,
95   # then we will make one up for them.
96   
97   # define a default name, if one wasn't already set.
98   if [ -z "$NAME" ]; then
99     export NAME='Unset Q. Namington, Fixley Your Name III'
100   fi
101   
102   ##############
103   
104   # variables for perl.
105   
106   export PERLLIB+="/usr/lib/perl5"
107   if [ "$OS" == "Windows_NT" ]; then
108     export PERLIO=:perlio
109       # choose perl's IO over the ms-windows version so we can handle file
110       # bytes properly.
111   fi
112   
113   # iterate across our sub-directories and find the perl scripts.
114   # this currently only looks one level down.
115   for i in $FEISTY_MEOW_SCRIPTS/*; do
116     if [ -d "$i" ]; then
117       # check if there is a perl file present; add the folder to PERLLIB if so.
118       ls $i/*.pl &>/dev/null
119       if [ $? -eq 0 ]; then
120         PERLLIB+=":$(dos_to_unix_path $i)"
121       fi
122     fi
123   done
124   #echo PERLLIB is now $PERLLIB
125   
126   ##############
127   
128   # set this so nechung can find its data.
129   export NECHUNG=$FEISTY_MEOW_DIR/infobase/fortunes.dat
130   
131   # ensure we use the right kind of secure shell.
132 #  export CVS_RSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
133 #  export GIT_SSH=$FEISTY_MEOW_SCRIPTS/security/ssh.sh
134   
135   # the base checkout list is just to update feisty_meow.  additional folder
136   # names can be added in your customized scripts.  the space at the end of
137   # this variable is important and allows users to extend the list like:
138   #    export REPOSITORY_DIR+="muppets configs"
139   export REPOSITORY_LIST="feisty_meow "
140   
141   # initializes the feisty meow build variables, if possible.
142   function initialize_build_variables()
143   {
144     found_build_vars=0
145     # we need to know the feisty meow directory, or we bail.
146     if [ -z "$FEISTY_MEOW_DIR" ]; then return; fi
147     # pick from our expected generator folder, but make sure it's there...
148     buildvars="$FEISTY_MEOW_SCRIPTS/generator/build_variables.sh"
149     if [ -f "$buildvars" ]; then
150       # yep, that one looks good, so pull in the build defs.
151       source "$buildvars" "$buildvars"
152       found_build_vars=1
153     fi
154     # now augment the environment if we found our build variables.
155     if [ $found_build_vars == 1 ]; then
156       # the binary directory contains handy programs we use a lot.  we set
157       # up the path to it here based on the operating system.
158       export BINDIR=$FEISTY_MEOW_DIR/production/binaries
159       # add binaries created within build to the path.
160       export PATH="$(dos_to_unix_path $BINDIR):$PATH"
161       # Shared libraries are located via this variable.
162       export LD_LIBRARY_PATH="$(dos_to_unix_path $LD_LIBRARY_PATH):$(dos_to_unix_path $BINDIR)"
163     fi
164   }
165   
166   ##############
167   
168   # windoze specific patching up missing things.
169   
170   if [ "$OS" == "Windows_NT" ]; then
171     export HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
172   fi
173   
174   ##############
175   
176   # load in the build environment.
177   initialize_build_variables
178   
179   ##############
180   
181   # add to the PATH variables used for locating applications.  this step is taken after any
182   # potential overrides from the user.
183   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"
184   
185   ##############
186
187   # set the SHUNIT_DIR so our shunit tests can find the codebase.
188   export SHUNIT_DIR="$FEISTY_MEOW_SCRIPTS/shunit"
189   
190   ##############
191   
192   if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization ends....; fi
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