Execute commands in modified environment

I'm working on different projects, and every project has its own requirements: jvm, eclipse version (with specific plugins), tomcat version, ant version, etc... Initially I was modifying manually the ~/.bashrc or ~/.profile settings, commenting and uncommenting sections. But this process doesn't scale: it's error prone, your shell profile settings quickly becomes unmaintainable, etc. etc.

So I come out with a simple solution copying the sudo pattern. Sudo is meant to execute commands as a different user. What I needed is a way to execute command in a different environment.

I created a list of scripts, one per project/team where I store environment settings and macros to ease my job. For example, recently I was developing in a team that has been called "monstersinc" (not my fault: I'm ugly but not so ugly); so I created a little bash script to run my IDE and tools with the settings required by the team, and I called "modo" (monstersinc do). Here's it:

#! /bin/bash

# environment settings
JAVA5_HOME=/usr/lib/jvm/java-1.5.0-sun
JAVA6_HOME=/usr/lib/jvm/java-6-sun
export JAVA_HOME=$JAVA5_HOME
export JETTY_HOME=/home/luigi/opt/jetty-6.1.14
export PATH=$JAVA_HOME/bin:$PATH
export ANT_HOME=/usr/share/ant

# specific functions to ease monstersinc development

# specific eclipse installation for monstersinc
function eclipse() {
    # use java6 to start eclipse
    export JAVA_HOME=$JAVA6_HOME
    PATH_BAK=$PATH
    export PATH=$JAVA_HOME/bin:$PATH
    export LD_LIBRARY_PATH=/usr/lib/jni
    ~/monstersinc/eclipse/eclipse ${*} &
    export PATH=$PATH_BAK
}

# execute the command line
if [ -n "${*}" ]; then
    ${*}
fi

So, when I want to start eclipse for monstersinc team work, or I want to compile using ant I execute:

$ modo eclipse
$ modo ant 

I keep a list of environments *do in my ~/bin directory which is in my unix shell PATH. For example I have also a "j5do" and "j6do" for running applications and jdk tools of a specific version of Java with a proper environment (JAVAHOME/PATH/etc)

That's an example of an IT problem that can be solved with an additional level of indirection.

All problems in computer science can be solved by another level of indirection
--David Wheeler

...except for the problem of too many layers of indirection.
--Kevlin Henney

... which are in the most common problems.


No Responses to “Execute commands in modified environment”  

  1. No Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



Calendar

February 2009
M T W T F S S
« Jan   Mar »
 1
2345678
9101112131415
16171819202122
232425262728  

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:

Archives


Categories

Tag Cloud


Listening