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