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 define_yeti_variable TEMPORARIES_PILE="$FEISTY_MEOW_GENERATED_STORE/temporaries"
136 if [ ! -d "$TEMPORARIES_PILE" ]; then
137 mkdir -p "$TEMPORARIES_PILE"
140 # similarly, make sure we have someplace to look for our generated files, if
141 # we were not handed a value.
142 if [ -z "$FEISTY_MEOW_LOADING_DOCK" ]; then
143 # The generated scripts directory is where automatically generated files live.
144 # It is separate from the main body of the shell scripts in order to keep things from
146 define_yeti_variable FEISTY_MEOW_LOADING_DOCK=$HOME/.zz_feisty_loading
151 # set up the color_add variable which is a flag that lets ls know colors work.
153 # test if we can use color in ls...
154 ls --help 2>&1 | grep -i -q color
155 if [ $? -eq 0 ]; then
156 export color_add='--color=auto'
164 # umask sets a permission mask for all file creations. we don't set this for the users any
165 # more; they should set it themselves. this is just documentation.
167 # this mask disallows writes by the "group" and disallows all permissions for "others".
169 # this mask disallows writes by "group" and "others".
171 # this mask allows writes by "group" but not by "others".
174 # ulimit sets user limits. we set the maximum allowed core dump file size
175 # to zero, because it is obnoxious to see the core dumps from crashed
176 # programs lying around everywhere.
181 # user variables, sort of... if they haven't given themselves a name yet,
182 # then we will make one up for them.
184 # define a default name, if one wasn't already set.
185 if [ -z "$NAME" ]; then
186 define_yeti_variable NAME='Unset Q. Namington, Fixley Your Name III'
191 # variables for perl.
193 if [[ $PERLLIB =~ .*$FEISTY_MEOW_SCRIPTS.* ]]; then
194 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
195 echo skipping PERLLIB since already mentions feisty meow scripts.
198 define_yeti_variable PERLLIB+="/usr/lib/perl5"
199 if [ "$OS" == "Windows_NT" ]; then
200 define_yeti_variable PERLIO=:perlio
201 # choose perl's IO over the ms-windows version so we can handle file
205 # iterate across our sub-directories and find the perl scripts.
206 # this currently only looks one level down.
207 for i in $FEISTY_MEOW_SCRIPTS/*; do
209 # check if there is a perl file present; add the folder to PERLLIB if so.
210 ls $i/*.pl &>/dev/null
211 if [ $? -eq 0 ]; then
212 PERLLIB+=":$(dos_to_unix_path $i)"
218 define_yeti_variable PERL5LIB=$PERLLIB
219 #echo PERLLIB is now $PERLLIB
223 # set this so nechung can find its data.
224 define_yeti_variable NECHUNG=$FEISTY_MEOW_APEX/infobase/fortunes.dat
226 ## # establish a pipe for less to see our beloved syntax highlighting.
227 ## define_yeti_variable LESSOPEN="| source-highlight -f esc -o STDOUT -i %s"
229 # the base checkout list is just to update feisty_meow. additional folder
230 # names can be added in your customized scripts. the space at the end of
231 # this variable is important and allows users to extend the list like:
232 # define_yeti_variable REPOSITORY_DIR+="muppets configs"
233 # see the customize/fred folder for a live example.
234 define_yeti_variable REPOSITORY_LIST="$FEISTY_MEOW_APEX "
236 # add in any active projects to the repository list.
237 #hmmm: resolve if still using this folder.
238 if [ -d "$HOME/active" ]; then
239 REPOSITORY_LIST+="$(find "$HOME/active" -maxdepth 1 -mindepth 1 -type d) "
242 # add in any folders that are under the feisty meow applications folder.
243 define_yeti_variable FEISTY_MEOW_APPS_DIR
244 if [ -z "$FEISTY_MEOW_APPS_DIR" ]; then
245 if [ -d "$HOME/apps" ]; then
246 define_yeti_variable FEISTY_MEOW_APPS_DIR="$HOME/apps"
248 # echo "No value set for FEISTY_MEOW_APPS_DIR and no default apps folder found in home."
252 if [ -d "$FEISTY_MEOW_APPS_DIR" ]; then
253 # general search for normal project folders in apps.
254 REPOSITORY_LIST+="$(find "$FEISTY_MEOW_APPS_DIR" -maxdepth 2 -mindepth 2 -iname ".git" -type d -exec dirname {} ';') "
255 REPOSITORY_LIST+="$(find "$FEISTY_MEOW_APPS_DIR" -maxdepth 2 -mindepth 2 -iname ".svn" -type d -exec dirname {} ';') "
257 # special search for site avenger directories; they have avenger5 as second level.
258 REPOSITORY_LIST+="$(find "$FEISTY_MEOW_APPS_DIR" -maxdepth 2 -mindepth 2 -iname "avenger5" -type d) "
261 # the archive list is a set of directories that are major repositories of
262 # data which can be synched to backup drives.
263 define_yeti_variable MAJOR_ARCHIVE_SOURCES=
264 # the source collections list is a set of directories that indicate they
265 # harbor a lot of source code underneath.
266 define_yeti_variable SOURCECODE_HIERARCHY_LIST=
268 # initializes the feisty meow build variables, if possible.
269 function initialize_build_variables()
271 local found_build_vars=nope
272 # we need to know the feisty meow directory, or we bail.
273 if [ -z "$FEISTY_MEOW_APEX" ]; then return; fi
274 # pick from our expected generator folder, but make sure it's there...
275 buildvars="$FEISTY_MEOW_SCRIPTS/generator/build_variables.sh"
276 if [ -f "$buildvars" ]; then
277 # yep, that one looks good, so pull in the build defs.
278 source "$buildvars" "$buildvars"
279 found_build_vars=true
281 # now augment the environment if we found our build variables.
282 if [ $found_build_vars == true ]; then
283 # the binary directory contains our collection of handy programs.
284 define_yeti_variable FEISTY_MEOW_BINARIES=$TARGETS_STORE
285 # add binaries created within build to the path.
286 define_yeti_variable PATH="$(dos_to_unix_path $FEISTY_MEOW_BINARIES):$PATH"
287 # Shared libraries are located via this variable.
288 define_yeti_variable LD_LIBRARY_PATH="$(dos_to_unix_path $LD_LIBRARY_PATH):$(dos_to_unix_path $FEISTY_MEOW_BINARIES)"
294 # windoze specific patching up missing things.
296 if [ "$OS" == "Windows_NT" ]; then
297 define_yeti_variable HOSTNAME=$(echo $HOSTNAME | tr A-Z a-z)
302 # load in the build environment.
303 initialize_build_variables
307 # add to the PATH variables used for locating applications. this step is taken after any
308 # potential overrides from the user.
309 #old: 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"
310 define_yeti_variable PATH="$PATH:$(find /usr/local/games -maxdepth 1 -type d -exec echo -n {}: ';' 2>/dev/null)/sbin"
314 # set the SHUNIT_PATH so our shunit tests can find the codebase.
315 define_yeti_variable SHUNIT_PATH="$FEISTY_MEOW_SCRIPTS/testkit/shunit"
319 define_yeti_variable CORE_VARIABLES_LOADED=true
321 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo variables initialization ends....; fi
326 # pull in the custom overrides for feisty_meow scripts. this is done almost
327 # last, because we want to set everything up as expected, then let the user
328 # override individual variables and definitions. we also don't guard this
329 # to avoid running it again, because we don't know what mix of functions and
330 # aliases they want to define in there.
331 for i in $FEISTY_MEOW_LOADING_DOCK/custom/*.sh; do
332 if [ ! -f "$i" ]; then
333 # skip it if it's not real.
336 if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
337 echo "loading customization: $(basename $(dirname $i))/$(basename $i)"
344 # a late breaking action is to set the editor, if we can.
345 # we will fallback to whatever we can find on the host.
347 # note: the editors for revision control must wait while the document is
348 # edited, so gvim and others that launch a separate x window are not
349 # going to work well unless they can be prevented from forking the process
351 if [ -z "$EDITOR" ]; then
352 EDITOR="$(whichable gvim)"
353 if [ ! -z "$EDITOR" ]; then
354 # if we found gvim, then add in the no forking flag.
358 if [ -z "$EDITOR" ]; then
359 EDITOR="$(whichable vim)"
361 if [ -z "$EDITOR" ]; then
362 EDITOR="$(whichable vi)"
364 if [ -z "$EDITOR" ]; then
365 EDITOR="$(whichable emacs)"
368 # out of ideas about editors at this point.
370 # set the VISUAL and other variables from EDITOR if we found an editor to use.
371 if [ ! -z "$EDITOR" ]; then
374 export GIT_EDITOR="$EDITOR"
375 export SVN_EDITOR="$EDITOR"