diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-03-12 15:56:09 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-03-12 15:58:14 +0000 |
commit | be97b2c34ce22a152d54bb39da1fb56e8cbaa41b (patch) | |
tree | ed513748c4fc94afcda4ca5c6c0a4bcd41d8020f /setenv.pl | |
parent | 6b0007c775df32b72cf5f0e07041d2b9a2e3cd0d (diff) |
Better setting of environment
Diffstat (limited to 'setenv.pl')
-rwxr-xr-x | setenv.pl | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/setenv.pl b/setenv.pl new file mode 100755 index 000000000..e6dd65f47 --- /dev/null +++ b/setenv.pl @@ -0,0 +1,54 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use FindBin; +use List::MoreUtils 'uniq'; + +# Set the environment for the FixMyStreet project + +# Add the lii/perl5 in perl-external so that we can load local::lib from there +use lib "$FindBin::Bin/perl-external/lib/perl5"; + +# Add the perl-external dirs properly using local::lib +use local::lib "$FindBin::Bin/perl-external"; +use local::lib "$FindBin::Bin/perl-external/local-lib"; + +# add the local perllibs too +use lib "$FindBin::Bin/commonlib/perllib"; +use lib "$FindBin::Bin/perllib"; + +# also set the path to our scripts etc +$ENV{PATH} = join ':', uniq "$FindBin::Bin/bin", split( m/:/, $ENV{PATH} ); + +# now decide what to do - if no arguments print out shell arguments to set the +# environment. If there are arguments then run those so that they run correctly +if (@ARGV) { + system @ARGV; +} +else { + + my @keys = sort 'PATH', grep { m{^PERL} } keys %ENV; + + print << "STOP"; +# $0 - set up the environment for FixMyStreet. +# +# This script can be used one of two ways: +# +# With arguments executes the arguments with the environment correctly set - +# intended for things like the cron jobs: +# +# $0 env +# +# Or if no arguments prints out the bash shell commands needed to set up the +# environment - which is useful when developing. Use this to set your current +# shell: +# +# eval `$0` + +STOP + + print "export $_='$ENV{$_}'\n" for @keys; + print 'export PS1="(fms) $PS1"' . "\n"; +} |