2 package Module::Install::RTx;
9 use Module::Install::Base;
10 use base 'Module::Install::Base';
11 our $VERSION = '0.32';
15 use File::Basename ();
17 my @DIRS = qw(etc lib html static bin sbin po var);
18 my @INDEX_DIRS = qw(lib bin sbin);
21 my ( $self, $name ) = @_;
23 my $original_name = $name;
25 $RTx = $1 if $name =~ s/^(\w+)-//;
29 $self->name("$RTx-$name")
31 $self->all_from( -e "$name.pm" ? "$name.pm" : "lib/$RTx/$fname.pm" )
32 unless $self->version;
33 $self->abstract("RT $name Extension")
34 unless $self->abstract;
36 my @prefixes = (qw(/opt /usr/local /home /usr /sw ));
37 my $prefix = $ENV{PREFIX};
38 @ARGV = grep { /PREFIX=(.*)/ ? ( ( $prefix = $1 ), 0 ) : 1 } @ARGV;
41 $RT::LocalPath = $prefix;
42 $INC{'RT.pm'} = "$RT::LocalPath/lib/RT.pm";
45 $ENV{RTHOME} ? ( $ENV{RTHOME}, "$ENV{RTHOME}/lib" ) : (),
47 map { ( "$_/rt4/lib", "$_/lib/rt4", "$_/rt3/lib", "$_/lib/rt3", "$_/lib" )
50 until ( eval { require RT; $RT::LocalPath } ) {
52 "Cannot find the location of RT.pm that defines \$RT::LocalPath in: @INC\n";
53 $_ = $self->prompt("Path to directory containing your RT.pm:") or exit;
55 push @INC, $_, "$_/rt3/lib", "$_/lib/rt3", "$_/lib";
59 my $lib_path = File::Basename::dirname( $INC{'RT.pm'} );
60 my $local_lib_path = "$RT::LocalPath/lib";
61 print "Using RT configuration from $INC{'RT.pm'}:\n";
62 unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath;
63 unshift @INC, $lib_path;
65 $RT::LocalVarPath ||= $RT::VarPath;
66 $RT::LocalPoPath ||= $RT::LocalLexiconPath;
67 $RT::LocalHtmlPath ||= $RT::MasonComponentRoot;
68 $RT::LocalStaticPath ||= $RT::StaticPath;
69 $RT::LocalLibPath ||= "$RT::LocalPath/lib";
71 my $with_subdirs = $ENV{WITH_SUBDIRS};
72 @ARGV = grep { /WITH_SUBDIRS=(.*)/ ? ( ( $with_subdirs = $1 ), 0 ) : 1 }
76 %subdirs = map { $_ => 1 } split( /\s*,\s*/, $with_subdirs )
77 if defined $with_subdirs;
78 unless ( keys %subdirs ) {
79 $subdirs{$_} = 1 foreach grep -d "$FindBin::Bin/$_", @DIRS;
82 # If we're running on RT 3.8 with plugin support, we really wany
83 # to install libs, mason templates and po files into plugin specific
86 if ( $RT::LocalPluginPath ) {
87 die "Because of bugs in RT 3.8.0 this extension can not be installed.\n"
88 ."Upgrade to RT 3.8.1 or newer.\n" if $RT::VERSION =~ /^3\.8\.0/;
89 $path{$_} = $RT::LocalPluginPath . "/$original_name/$_"
94 my $varname = "RT::Local" . ucfirst($_) . "Path";
95 $path{$_} = ${$varname} || "$RT::LocalPath/$_";
98 $path{$_} .= "/$name" for grep $path{$_}, qw(etc po var);
101 my %index = map { $_ => 1 } @INDEX_DIRS;
102 $self->no_index( directory => $_ ) foreach grep !$index{$_}, @DIRS;
104 my $args = join ', ', map "q($_)", map { ($_, $path{$_}) }
105 grep $subdirs{$_}, keys %path;
107 print "./$_\t=> $path{$_}\n" for sort keys %subdirs;
109 if ( my @dirs = map { ( -D => $_ ) } grep $subdirs{$_}, qw(bin html sbin) ) {
110 my @po = map { ( -o => $_ ) }
112 File::Glob::bsd_glob("po/*.po");
113 $self->postamble(<< ".") if @po;
115 \t\$(NOECHO) \$(PERL) -MLocale::Maketext::Extract::Run=xgettext -e \"xgettext(qw(@dirs @po))\"
119 my $postamble = << ".";
121 \t\$(NOECHO) \$(PERL) -MExtUtils::Install -e \"install({$args})\"
124 if ( $subdirs{var} and -d $RT::MasonDataDir ) {
125 my ( $uid, $gid ) = ( stat($RT::MasonDataDir) )[ 4, 5 ];
126 $postamble .= << ".";
127 \t\$(NOECHO) chown -R $uid:$gid $path{var}
132 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/schema.*") ) {
135 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/acl.*") ) {
138 if ( -e 'etc/initialdata' ) { $has_etc{initialdata}++; }
139 if ( -d 'etc/upgrade/' ) { $has_etc{upgrade}++; }
141 $self->postamble("$postamble\n");
142 unless ( $subdirs{'lib'} ) {
143 $self->makemaker_args( PM => { "" => "" }, );
145 $self->makemaker_args( INSTALLSITELIB => $path{'lib'} );
146 $self->makemaker_args( INSTALLARCHLIB => $path{'lib'} );
149 $self->makemaker_args( INSTALLSITEMAN1DIR => "$RT::LocalPath/man/man1" );
150 $self->makemaker_args( INSTALLSITEMAN3DIR => "$RT::LocalPath/man/man3" );
151 $self->makemaker_args( INSTALLSITEARCH => "$RT::LocalPath/man" );
154 $self->load('RTxInitDB');
155 print "For first-time installation, type 'make initdb'.\n";
157 $initdb .= <<"." if $has_etc{schema};
158 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(schema \$(NAME) \$(VERSION)))"
160 $initdb .= <<"." if $has_etc{acl};
161 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(acl \$(NAME) \$(VERSION)))"
163 $initdb .= <<"." if $has_etc{initialdata};
164 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(insert \$(NAME) \$(VERSION)))"
166 $self->postamble("initdb ::\n$initdb\n");
167 $self->postamble("initialize-database ::\n$initdb\n");
168 if ($has_etc{upgrade}) {
169 print "To upgrade from a previous version of this extension, use 'make upgrade-database'\n";
170 my $upgradedb = qq|\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(upgrade \$(NAME) \$(VERSION)))"\n|;
171 $self->postamble("upgrade-database ::\n$upgradedb\n");
172 $self->postamble("upgradedb ::\n$upgradedb\n");
177 # stolen from RT::Handle so we work on 3.6 (cmp_versions came in with 3.8)
187 sub cmp_version($$) {
189 my @a = grep defined, map { /^[0-9]+$/? $_ : /^[a-zA-Z]+$/? $word{$_}|| -10 : undef }
190 split /([^0-9]+)/, $a;
191 my @b = grep defined, map { /^[0-9]+$/? $_ : /^[a-zA-Z]+$/? $word{$_}|| -10 : undef }
192 split /([^0-9]+)/, $b;
194 ? push @b, (0) x (@a-@b)
195 : push @a, (0) x (@b-@a);
196 for ( my $i = 0; $i < @a; $i++ ) {
197 return $a[$i] <=> $b[$i] if $a[$i] <=> $b[$i];
202 my ($self,$version) = @_;
204 # if we're exactly the same version as what we want, silently return
205 return if ($version eq $RT::VERSION);
207 my @sorted = sort cmp_version $version,$RT::VERSION;
209 if ($sorted[-1] eq $version) {
211 warn "\nWarning: prerequisite RT $version not found. Your installed version of RT ($RT::VERSION) is too old.\n\n";