rumblings of change; got custom scripts sorted, improved approach to
[feisty_meow.git] / scripts / core / variables.sh
1 #!/bin/bash
2
3 ##############################################################################
4 # variables script:
5 #   Defines the environment variables used by the personalized unix
6 #   environment.
7 ##############################################################################
8
9 if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization begins...; fi
10
11 ##############################################################################
12 # System variables.
13 ##############################################################################
14 # OS stands for the operating system that we think is running.
15 if [ -z "$OS" ]; then
16   export OS=UNIX
17 fi
18 export IS_DARWIN=$(echo $OSTYPE | grep -i darwin)
19
20 if [ -z "$HOME" ]; then
21   if [ "$OS" == "Windows_NT" ]; then
22     export HOME=/c/home
23     if [ ! -d $HOME ]; then
24       mkdir $HOME
25     fi
26   fi
27 fi
28
29 # patch home to undo cygwin style of drive letter.
30 export HOME=$(echo $HOME | sed -e 's/\/cygdrive\//\//g')
31 #echo HOME is now $HOME
32
33 if [ "$OS" == "Windows_NT" ]; then
34   export HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
35 fi
36
37 ##############################################################################
38 # Directory variables.
39 ##############################################################################
40 # The yeti library directory holds useful shell scripts, public databases,
41 # configuration examples, javascript code, and other stuff.
42 export SCRIPT_SYSTEM=feisty_meow
43
44 #if [ -z "$YETI_DIR" ]; then export YETI_DIR="$HOME/$SCRIPT_SYSTEM"; fi
45 #if [ -z "$YETI_SCRIPTS" ]; then export YETI_SCRIPTS="$YETI_DIR/scripts"; fi
46 #if [ -z "$SHELLDIR" ]; then export SHELLDIR="$YETI_SCRIPTS"; fi
47
48 # include helpful functions.
49 source "$YETI_SCRIPTS/core/functions.sh"
50
51 # LIBDIR is an older variable that points at the root of the yeti code.
52 export LIBDIR=$YETI_DIR
53
54 if [ -z "$GENERADIR" ]; then
55   # The generated scripts directory is where automatically generated files live.
56   # It is separate from the main body of the shell scripts in order to keep things from
57   # exploding.
58   export GENERADIR=$HOME/.zz_auto_gen
59 fi
60
61 ##############################################################################
62 # other variables...
63 ##############################################################################
64
65 # pull in the custom overrides for feisty_meow scripts.
66 for i in $YETI_SCRIPTS/custom/*.sh; do
67   echo "Sourcing custom file: $i"
68   source $i
69 done
70
71 # sets the prompts to what we (i.e., i) like...
72 # there are four different prompts.  the first one, PS1, is the one that users
73 # see the most often. 
74 export PS1='\u@\h $ ';
75 ### export PS2='> '; export PS3='#? '; export PS4='+ '
76
77 # variables for perl.
78 export PERLLIB
79 if [ "$OS" != "Windows_NT" ]; then
80   PERLLIB+="/usr/lib/perl5"
81 else
82 #echo "the scripts dir is $YETI_SCRIPTS"
83   YETI_SCRIPTS="$(echo $YETI_SCRIPTS | sed -e 's/\\/\//g')"
84   SHELLDIR="$YETI_SCRIPTS"
85 #echo "the scripts dir is now $SHELLDIR"
86   export PERLIO=:perlio
87     # choose perl's IO over the system's so we can handle file bytes exactly.
88 fi
89
90 #make this automatic!
91 PERLLIB+=":$YETI_SCRIPTS/core:$YETI_SCRIPTS/text:$YETI_SCRIPTS/files:$YETI_SCRIPTS/archival"
92
93 # set this so nechung can find its data.
94 export NECHUNG=$LIBDIR/database/fortunes.dat
95
96 # ensure we use the right kind of rsh for security.
97 export CVS_RSH=ssh
98
99 # sets the history length and max file size so we can get some long history around here.
100 HISTSIZE=1000000
101 HISTFILESIZE=2000000
102
103 # set the editor for subversion if it hasn't already been set.
104 if [ -z "$SVN_EDITOR" ]; then
105 #hmmm: not sure what original reason for having these different was...
106   if [ "$OS"  == "Windows_NT" ]; then
107     export SVN_EDITOR=$(which gvim)
108   else
109     export SVN_EDITOR=$(which vi)
110   fi
111 fi
112
113 # include variables needed for compiling hoople and using its scripts.
114 if [ -z "$REPOSITORY_DIR" ]; then
115   if [ -d "$HOME/feisty_meow" ]; then
116     export REPOSITORY_DIR="$HOME/feisty_meow"
117   fi
118 fi
119
120 # initialize the build variables, if possible.
121 found_build_vars=0
122 if [ ! -z "$REPOSITORY_DIR" ]; then
123   # first guess at using the old school bin directory.
124   bv="$REPOSITORY_DIR/bin/build_variables.sh"
125   if [ -f "$bv" ]; then
126     # the old bin directory is present, so let's use its build vars.
127     source "$bv" "$bv"
128     found_build_vars=1
129   else
130     # try again with the new school location for the file.
131     bv="$REPOSITORY_DIR/scripts/generator/build_variables.sh"
132     if [ -f "$bv" ]; then
133       # yep, that one looks good, so pull in the build defs.
134       source "$bv" "$bv"
135       found_build_vars=1
136     else
137       # try once more with new school and assume we're deep.
138       bv="$REPOSITORY_DIR/../../scripts/generator/build_variables.sh"
139       if [ -f "$bv" ]; then
140         # sweet, there is something there.
141         source "$bv" "$bv"
142         found_build_vars=1
143       fi
144     fi
145   fi
146 fi
147
148 # augment the configuration if we found our build variables.
149 if [ $found_build_vars == 1 ]; then
150
151   # the binary directory contains handy programs we use a lot in yeti.  we set up the path to it
152   # here based on the operating system.
153   # note that yeti has recently become more dependent on hoople.  hoople was always the source of
154   # the binaries, but now we don't ship them with yeti any more as pre-built items.  this reduces
155   # the size of the code package a lot and shortens up our possible exposure to compromised
156   # binaries.  people can bootstrap up their own set from hoople now instead.
157   export BINDIR=$REPOSITORY_DIR/production/binaries
158
159   # add binaries created within build to the path.
160   export PATH="$(dos_to_msys_path $BUILD_TOP/build/bin):$PATH"
161
162   # Shared libraries are located via this variable.
163   export LD_LIBRARY_PATH="$(dos_to_msys_path $LD_LIBRARY_PATH):$(dos_to_msys_path $BINDIR)"
164 fi
165
166 # Set the path for locating applications.
167 export PATH="$(dos_to_msys_path $BINDIR):$(dos_to_msys_path $GENERADIR):$PATH:/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/lib:/usr/games:/usr/bin:."
168
169 if [ ! -z "$SHELL_DEBUG" ]; then echo variables initialization ends....; fi
170