d3d12f2a4a6c711bb95df0cf49ff16f084f72d06
[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 if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization begins...; fi
13
14 ##############
15
16 # System variables...
17
18 # OS variable records the operating system we think we found.
19 if [ -z "$OS" ]; then
20   export OS=UNIX
21 fi
22 export IS_DARWIN=$(echo $OSTYPE | grep -i darwin)
23
24 if [ -z "$HOME" ]; then
25   if [ "$OS" == "Windows_NT" ]; then
26     export HOME=/c/home
27     if [ ! -d $HOME ]; then
28       mkdir $HOME
29     fi
30   fi
31 fi
32
33 # patch home to undo cygwin style of drive letter.
34 export HOME=$(echo $HOME | sed -e 's/\/cygdrive\//\//g')
35 #echo HOME is now $HOME
36
37 if [ "$OS" == "Windows_NT" ]; then
38   export HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
39 fi
40
41 # ulimit and umask.  umask sets a permission mask for all file
42 # creations.  The mask shown here disallows writing by the "group" and
43 # "others" categories of users.  ulimit sets the user limits.  the core
44 # file size is set to zero.
45 umask 022
46 ulimit -c 0
47
48 ##############
49
50 # Directory variables...
51
52 export SCRIPT_SYSTEM=feisty_meow
53
54 #if [ -z "$FEISTY_MEOW_DIR" ]; then export FEISTY_MEOW_DIR="$HOME/$SCRIPT_SYSTEM"; fi
55 #if [ -z "$FEISTY_MEOW_SCRIPTS" ]; then export FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_DIR/scripts"; fi
56 #if [ -z "$FEISTY_MEOW_SCRIPTS" ]; then export FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_SCRIPTS"; fi
57
58 # include helpful functions.
59 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
60
61 # LIBDIR is an older variable that points at the root of the yeti code.
62 export LIBDIR=$FEISTY_MEOW_DIR
63
64 if [ -z "$FEISTY_MEOW_GENERATED" ]; then
65   # The generated scripts directory is where automatically generated files live.
66   # It is separate from the main body of the shell scripts in order to keep things from
67   # exploding.
68   export FEISTY_MEOW_GENERATED=$HOME/.zz_auto_gen
69 fi
70
71 ##############
72
73 # user variables...
74
75 # define a default name, if one wasn't already set.
76 if [ -z "$NAME" ]; then
77   export NAME='Unset Q. Namington, Fixley Your Name III'
78 fi
79
80 ##############
81
82
83 ##############################################################################
84 # other variables...
85 ##############################################################################
86
87 # pull in the custom overrides for feisty_meow scripts.
88 for i in $FEISTY_MEOW_GENERATED/custom/*.sh; do
89   if [ ! -f "$i" ]; then
90     # skip it if it's not real.
91     continue;
92   fi
93   if [ ! -z "$SHELL_DEBUG" ]; then
94     echo "loading customization: $(basename $(dirname $i))/$(basename $i)"
95   fi
96   source $i
97 done
98
99 # sets the prompts to what we (i.e., i) like...
100 # there are four different prompts.  the first one, PS1, is the one that users
101 # see the most often. 
102 export PS1='\u@\h $ ';
103 ### export PS2='> '; export PS3='#? '; export PS4='+ '
104
105 # variables for perl.
106 export PERLLIB
107 if [ "$OS" != "Windows_NT" ]; then
108   PERLLIB+="/usr/lib/perl5"
109 else
110
111 #echo "the scripts dir is $FEISTY_MEOW_SCRIPTS"
112 #  FEISTY_MEOW_SCRIPTS="$(echo $FEISTY_MEOW_SCRIPTS | sed -e 's/\\/\//g')"
113 #  FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_SCRIPTS"
114 #echo "the scripts dir is now $FEISTY_MEOW_SCRIPTS"
115
116   export PERLIO=:perlio
117     # choose perl's IO over the ms-windows version so we can handle file
118     # bytes properly.
119 fi
120
121 # iterate across our sub-directories and find the perl scripts.
122 # this currently only looks one level down.
123 for i in $FEISTY_MEOW_SCRIPTS/*; do
124   if [ -d "$i" ]; then
125     # check if there is a perl file present; add the folder to PERLLIB if so.
126     ls $i/*.pl &>/dev/null
127     if [ $? -eq 0 ]; then
128       PERLLIB+=":$i"
129     fi
130   fi
131 done
132 #echo PERLLIB is now $PERLLIB
133
134 # set this so nechung can find its data.
135 export NECHUNG=$LIBDIR/database/fortunes.dat
136
137 # ensure we use the right kind of rsh for security.
138 export CVS_RSH=ssh
139
140 # sets the history length and max file size so we can get some long history around here.
141 HISTSIZE=1000000
142 HISTFILESIZE=2000000
143
144 # set the editor for subversion if it hasn't already been set.
145 if [ -z "$SVN_EDITOR" ]; then
146 #hmmm: not sure what original reason for having these different was...
147   if [ "$OS"  == "Windows_NT" ]; then
148     export SVN_EDITOR=$(which gvim)
149   else
150     export SVN_EDITOR=$(which vi)
151   fi
152 fi
153
154 # include variables needed for compiling hoople and using its scripts.
155 if [ -z "$FEISTY_MEOW_DIR" ]; then
156   if [ -d "$HOME/feisty_meow" ]; then
157     export FEISTY_MEOW_DIR="$HOME/feisty_meow"
158   fi
159 fi
160
161 # initialize the build variables, if possible.
162 found_build_vars=0
163 if [ ! -z "$FEISTY_MEOW_DIR" ]; then
164   # first guess at using the old school bin directory.
165   bv="$FEISTY_MEOW_DIR/bin/build_variables.sh"
166   if [ -f "$bv" ]; then
167     # the old bin directory is present, so let's use its build vars.
168     source "$bv" "$bv"
169     found_build_vars=1
170   else
171     # try again with the new school location for the file.
172     bv="$FEISTY_MEOW_DIR/scripts/generator/build_variables.sh"
173     if [ -f "$bv" ]; then
174       # yep, that one looks good, so pull in the build defs.
175       source "$bv" "$bv"
176       found_build_vars=1
177     else
178       # try once more with new school and assume we're deep.
179       bv="$FEISTY_MEOW_DIR/../../scripts/generator/build_variables.sh"
180       if [ -f "$bv" ]; then
181         # sweet, there is something there.
182         source "$bv" "$bv"
183         found_build_vars=1
184       fi
185     fi
186   fi
187 fi
188
189 # augment the configuration if we found our build variables.
190 if [ $found_build_vars == 1 ]; then
191
192   # the binary directory contains handy programs we use a lot in yeti.  we set up the path to it
193   # here based on the operating system.
194   # note that yeti has recently become more dependent on hoople.  hoople was always the source of
195   # the binaries, but now we don't ship them with yeti any more as pre-built items.  this reduces
196   # the size of the code package a lot and shortens up our possible exposure to compromised
197   # binaries.  people can bootstrap up their own set from hoople now instead.
198   export BINDIR=$FEISTY_MEOW_DIR/production/binaries
199
200   # add binaries created within build to the path.
201   export PATH="$(dos_to_msys_path $BUILD_TOP/build/bin):$PATH"
202
203   # Shared libraries are located via this variable.
204   export LD_LIBRARY_PATH="$(dos_to_msys_path $LD_LIBRARY_PATH):$(dos_to_msys_path $BINDIR)"
205 fi
206
207 # Set the path for locating applications.
208 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:."
209
210 if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization ends....; fi
211