6 # Defines the environment variables used by the personalized unix
8 # Author: Chris Koeritz
12 # defines a variable within the feisty meow environment and remembers that
13 # this is a new or modified definition. if the feisty meow codebase is
14 # unloaded, then so are all the variables that were defined.
15 # this function always exports the variables it defines.
16 function define_yeti_variable()
18 #hmmm: simple implem just sets it up and exports the variable.
19 # i.e., this method always exports.
22 #hmmm: eventual approach-- if variable exists already, save old value for restore,
23 # otherwise save null value for restore,
24 # have to handle unsetting if there was no prior value of one
26 # add variable name to a list of feisty defined variables.
31 # switches from an X:/ form to a /cygdrive/X/path form. this is only useful
32 # for the cygwin environment currently.
33 # defined here rather than in functions.sh since we need it when setting variables
34 # and cannot count on load order during a fresh startup in some circumstances.
35 function dos_to_unix_path() {
36 # we always remove dos slashes in favor of forward slashes.
37 #old: echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\([a-zA-Z]\):\/\(.*\)/\/\1\/\2/'
38 echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\([a-zA-Z]\):\/\(.*\)/\/cygdrive\/\1\/\2/'
45 # this section should always run or bash will reset them on us.
46 # these need to be as minimal as possible.
48 # sets the main prompt to a simple default, with user@host.
49 define_yeti_variable PS1='\u@\h $ ';
50 # sets the history length and max file size so we can get some long history around here.
51 define_yeti_variable HISTSIZE=1000000
52 define_yeti_variable HISTFILESIZE=8000000
54 # make the TERM available to all sub-shells.
55 define_yeti_variable TERM
59 # we'll run this again only if we think it's needed.
60 if [ -z "$CORE_VARIABLES_LOADED" ]; then
62 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo variables initialization begins...; fi
66 # start with some simpler things.
68 #hmmm: this needs to come from some configuration item. especially for installs.
69 define_yeti_variable DEFAULT_FEISTYMEOW_ORG_DIR=/opt/feistymeow.org
71 define_yeti_variable SCRIPT_SYSTEM=feisty_meow
73 # OS variable records the operating system we think we found.
75 define_yeti_variable OS=UNIX
77 define_yeti_variable IS_DARWIN=$(echo $OSTYPE | grep -i darwin)
81 # guess the current platform.
82 IS_UNIX=$(uname | grep -i linux)
83 if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i unix); fi
84 if [ -z "$IS_UNIX" ]; then IS_UNIX=$(uname | grep -i darwin); fi
85 IS_DOS=$(uname | grep -i ming)
86 if [ -z "$IS_DOS" ]; then IS_DOS=$(uname | grep -i cygwin); fi
88 # now if we're stuck in DOS, try to determine the type of system.
89 if [ ! -z "$IS_DOS" ]; then
90 # IS_MSYS will be non-empty if this is the msys toolset. otherwise
91 # we assume that it's cygwin.
92 IS_MSYS=$(uname | grep -i ming)
94 # if not MSYS, then we'll assume cygwin and set the cygwin root var.
95 if [ -z "$IS_MSYS" ]; then
96 define_yeti_variable CYGROOT=$(cygpath -w -m /)
102 # fallbacks to set crucial variables for feisty meow...
104 # set the main root directory variable for the feisty meow codebase.
105 # this is only used for extreme failure modes, when the values were not
106 # pulled in from our auto-generated config.
107 if [ -z "$FEISTY_MEOW_APEX" ]; then
108 if [ -d "/opt/feistymeow.org/feisty_meow" ]; then
109 define_yeti_variable FEISTY_MEOW_APEX="/opt/feistymeow.org/feisty_meow"
110 define_yeti_variable FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_APEX/scripts"
111 elif [ -d "$HOME/feisty_meow" ]; then
112 define_yeti_variable FEISTY_MEOW_APEX="$HOME/feisty_meow"
113 define_yeti_variable FEISTY_MEOW_SCRIPTS="$FEISTY_MEOW_APEX/scripts"
117 # main declaration of the transients area.
118 if [ -z "$TMP" ]; then
119 define_yeti_variable TMP=$HOME/.tmp
122 # set up our event logging file for any notable situation to be recorded in.
123 if [ -z "$FEISTY_MEOW_EVENT_LOG" ]; then
124 define_yeti_variable FEISTY_MEOW_EVENT_LOG="$TMP/$USER-feisty_meow-events.log"
127 # set up the top-level for all build creations and logs and such.
128 if [ -z "$FEISTY_MEOW_GENERATED_STORE" ]; then
129 define_yeti_variable FEISTY_MEOW_GENERATED_STORE="$TMP/generated-feisty_meow"
131 if [ ! -d "$FEISTY_MEOW_GENERATED_STORE" ]; then
132 mkdir -p "$FEISTY_MEOW_GENERATED_STORE"
134 # set up our effluent outsourcing valves.
135 if [ -z "$TEMPORARIES_PILE" ]; then
136 define_yeti_variable TEMPORARIES_PILE="$FEISTY_MEOW_GENERATED_STORE/temporaries"
138 if [ ! -d "$TEMPORARIES_PILE" ]; then
139 mkdir -p "$TEMPORARIES_PILE"
142 # similarly, make sure we have someplace to look for our generated files, if
143 # we were not handed a value.
144 if [ -z "$FEISTY_MEOW_LOADING_DOCK" ]; then
145 # The generated scripts directory is where automatically generated files live.
146 # It is separate from the main body of the shell scripts in order to keep things from
148 define_yeti_variable FEISTY_MEOW_LOADING_DOCK=$HOME/.zz_feisty_loading
153 # set up the color_add variable which is a flag that lets ls know colors work.
155 # test if we can use color in ls...
156 ls --help 2>&1 | grep -i -q color
157 if [ $? -eq 0 ]; then
158 export color_add='--color=auto'
166 # umask sets a permission mask for all file creations. we don't set this for the users any
167 # more; they should set it themselves. this is just documentation.
169 # this mask disallows writes by the "group" and disallows all permissions for "others".
171 # this mask disallows writes by "group" and "others".
173 # this mask allows writes by "group" but not by "others".
176 # ulimit sets user limits. we set the maximum allowed core dump file size
177 # to zero, because it is obnoxious to see the core dumps from crashed
178 # programs lying around everywhere.
183 # user variables, sort of... if they haven't given themselves a name yet,
184 # then we will make one up for them.
186 # define a default name, if one wasn't already set.
187 if [ -z "$NAME" ]; then
188 define_yeti_variable NAME='Unset Q. Namington, Fixley Your Name III'
193 # variables for perl.
195 define_yeti_variable PERLLIB+="/usr/lib/perl5"
196 if [ "$OS" == "Windows_NT" ]; then
197 define_yeti_variable PERLIO=:perlio
198 # choose perl's IO over the ms-windows version so we can handle file
202 # iterate across our sub-directories and find the perl scripts.
203 # this currently only looks one level down.
204 for i in $FEISTY_MEOW_SCRIPTS/*; do
206 # check if there is a perl file present; add the folder to PERLLIB if so.
207 ls $i/*.pl &>/dev/null
208 if [ $? -eq 0 ]; then
209 PERLLIB+=":$(dos_to_unix_path $i)"
213 define_yeti_variable PERL5LIB=$PERLLIB
214 #echo PERLLIB is now $PERLLIB
218 # set this so nechung can find its data.
219 define_yeti_variable NECHUNG=$FEISTY_MEOW_APEX/infobase/fortunes.dat
221 ## # establish a pipe for less to see our beloved syntax highlighting.
222 ## define_yeti_variable LESSOPEN="| source-highlight -f esc -o STDOUT -i %s"
224 # the base checkout list is just to update feisty_meow. additional folder
225 # names can be added in your customized scripts. the space at the end of
226 # this variable is important and allows users to extend the list like:
227 # define_yeti_variable REPOSITORY_DIR+="muppets configs"
228 # see the customize/fred folder for a live example.
229 define_yeti_variable REPOSITORY_LIST="$FEISTY_MEOW_APEX "
231 # add in any active projects to the repository list.
232 if [ -d "$HOME/active" ]; then
233 REPOSITORY_LIST+="$(find "$HOME/active" -maxdepth 1 -mindepth 1 -type d) "
235 # add in any site avenger applications that are in the applications folder.
236 if [ -d "$HOME/apps" ]; then
237 # general search for normal project folders in apps.
238 REPOSITORY_LIST+="$(find "$HOME/apps" -maxdepth 2 -mindepth 2 -iname ".git" -type d -exec dirname {} ';') "
239 REPOSITORY_LIST+="$(find "$HOME/apps" -maxdepth 2 -mindepth 2 -iname ".svn" -type d -exec dirname {} ';') "
241 # special search for site avenger directories; they have avenger5 as second level.
242 REPOSITORY_LIST+="$(find "$HOME/apps" -maxdepth 2 -mindepth 2 -iname "avenger5" -type d) "
245 # the archive list is a set of directories that are major repositories of
246 # data which can be synched to backup drives.
247 define_yeti_variable MAJOR_ARCHIVE_SOURCES=
248 # the source collections list is a set of directories that indicate they
249 # harbor a lot of source code underneath.
250 define_yeti_variable SOURCECODE_HIERARCHY_LIST=
252 # initializes the feisty meow build variables, if possible.
253 function initialize_build_variables()
256 # we need to know the feisty meow directory, or we bail.
257 if [ -z "$FEISTY_MEOW_APEX" ]; then return; fi
258 # pick from our expected generator folder, but make sure it's there...
259 buildvars="$FEISTY_MEOW_SCRIPTS/generator/build_variables.sh"
260 if [ -f "$buildvars" ]; then
261 # yep, that one looks good, so pull in the build defs.
262 source "$buildvars" "$buildvars"
265 # now augment the environment if we found our build variables.
266 if [ $found_build_vars == 1 ]; then
267 # the binary directory contains our collection of handy programs.
268 define_yeti_variable FEISTY_MEOW_BINARIES=$TARGETS_STORE
269 # add binaries created within build to the path.
270 define_yeti_variable PATH="$(dos_to_unix_path $FEISTY_MEOW_BINARIES):$PATH"
271 # Shared libraries are located via this variable.
272 define_yeti_variable LD_LIBRARY_PATH="$(dos_to_unix_path $LD_LIBRARY_PATH):$(dos_to_unix_path $FEISTY_MEOW_BINARIES)"
278 # windoze specific patching up missing things.
280 if [ "$OS" == "Windows_NT" ]; then
281 define_yeti_variable HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
286 # load in the build environment.
287 initialize_build_variables
291 # add to the PATH variables used for locating applications. this step is taken after any
292 # potential overrides from the user.
293 define_yeti_variable PATH="$(dos_to_unix_path $FEISTY_MEOW_LOADING_DOCK):$PATH:$(find /usr/local/games -maxdepth 1 -type d -exec echo -n {}: ';' 2>/dev/null)/sbin"
297 # set the SHUNIT_PATH so our shunit tests can find the codebase.
298 define_yeti_variable SHUNIT_PATH="$FEISTY_MEOW_SCRIPTS/shunit"
302 define_yeti_variable CORE_VARIABLES_LOADED=true
304 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo variables initialization ends....; fi
309 # pull in the custom overrides for feisty_meow scripts. this is done almost
310 # last, because we want to set everything up as expected, then let the user
311 # override individual variables and definitions. we also don't guard this
312 # to avoid running it again, because we don't know what mix of functions and
313 # aliases they want to define in there.
314 for i in $FEISTY_MEOW_LOADING_DOCK/custom/*.sh; do
315 if [ ! -f "$i" ]; then
316 # skip it if it's not real.
319 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
320 echo "loading customization: $(basename $(dirname $i))/$(basename $i)"
327 # a late breaking action is to set the editor, if we can.
328 # we will fallback to whatever we can find on the host.
330 # note: the editors for revision control must wait while the document is
331 # edited, so gvim and others that launch a separate x window are not
332 # going to work well unless they can be prevented from forking the process
334 if [ -z "$EDITOR" ]; then
335 EDITOR="$(which gvim)"
336 if [ ! -z "$EDITOR" ]; then
337 # if we found gvim, then add in the no forking flag.
341 if [ -z "$EDITOR" ]; then
342 EDITOR="$(which vim)"
344 if [ -z "$EDITOR" ]; then
347 if [ -z "$EDITOR" ]; then
348 EDITOR="$(which emacs)"
351 # out of ideas about editors at this point.
353 # set the VISUAL and other variables from EDITOR if we found an editor to use.
354 if [ ! -z "$EDITOR" ]; then
357 export GIT_EDITOR="$EDITOR"
358 export SVN_EDITOR="$EDITOR"