forked from mysociety/fixmystreet
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
setenv.pl
executable file
·93 lines (71 loc) · 2.3 KB
/
setenv.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env perl
use strict;
use warnings;
my $root;
BEGIN {
use Cwd qw(abs_path);
use File::Basename qw(dirname basename);
$root = dirname(abs_path(__FILE__));
}
# Check there is not a later timestamped deploy, if running in such a system
if ($root =~ /fixmystreet-\d\d\d\d-\d\d-\d\dT\d\d-\d\d-\d\d$/) {
my @deploys = sort map { basename $_ } glob("$root/../fixmystreet-*");
if (basename($root) ne $deploys[-1] && !$ENV{OLD_DEPLOY_ACKNOWLEDGED}) {
require Term::ANSIColor;
print Term::ANSIColor::colored("NOT THE LATEST DEPLOY; ABORTING\n", 'red');
exit 1;
}
}
# Set the environment for the FixMyStreet project
# Add the lib/perl5 in local so that we can load local::lib from there
use lib "$root/local/lib/perl5";
# Now add the local dir properly using local::lib
use local::lib "$root/local";
use lib "$root/commonlib/perllib";
use lib "$root/perllib";
for ( "$root/commonlib/perllib", "$root/perllib" ) {
$ENV{PERL5LIB} = "$_:$ENV{PERL5LIB}";
}
# also set the path to our scripts etc
my %seen;
$ENV{PATH} = join ':', grep { not $seen{$_}++ } "$root/bin", split( m/:/, $ENV{PATH} );
# we might want to require this file to configure something like a CGI script
if ( $0 eq __FILE__ ) {
my @keys = sort 'PATH', grep { m{^PERL} } keys %ENV;
print "export $_='$ENV{$_}'\n" for @keys;
print 'export PS1="(fms) $PS1"' . "\n";
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
}
else {
# we were just required - unload some modules to prevent old code
# getting in the way of loading newer code from the newly set directories.
# use an eval to prevent needing Class::Unload before perl-external properly
# setup
eval "use Class::Unload";
die $@ if $@;
my @modules =
sort
grep { m/Cwd|File::(?!Glob)/ }
map { s{\.pm$}{}; s{/}{::}g; $_ }
grep { m{\.pm$} }
keys %INC;
for (@modules) {
Class::Unload->unload($_);
}
}
1;