2 package Module::Install::RTx;
9 use Module::Install::Base;
10 use base 'Module::Install::Base';
11 our $VERSION = '0.24';
15 use File::Basename ();
17 my @DIRS = qw(etc lib html 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";
46 $ENV{RTHOME} ? ( $ENV{RTHOME}, "$ENV{RTHOME}/lib" ) : (),
47 map { ( "$_/rt3/lib", "$_/lib/rt3", "$_/lib" ) } grep $_,
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 your RT.pm:") or exit;
54 push @INC, $_, "$_/rt3/lib", "$_/lib/rt3", "$_/lib";
58 my $lib_path = File::Basename::dirname( $INC{'RT.pm'} );
59 my $local_lib_path = "$RT::LocalPath/lib";
60 print "Using RT configuration from $INC{'RT.pm'}:\n";
61 unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath;
63 $RT::LocalVarPath ||= $RT::VarPath;
64 $RT::LocalPoPath ||= $RT::LocalLexiconPath;
65 $RT::LocalHtmlPath ||= $RT::MasonComponentRoot;
66 $RT::LocalLibPath ||= "$RT::LocalPath/lib";
68 my $with_subdirs = $ENV{WITH_SUBDIRS};
69 @ARGV = grep { /WITH_SUBDIRS=(.*)/ ? ( ( $with_subdirs = $1 ), 0 ) : 1 }
73 %subdirs = map { $_ => 1 } split( /\s*,\s*/, $with_subdirs )
74 if defined $with_subdirs;
75 unless ( keys %subdirs ) {
76 $subdirs{$_} = 1 foreach grep -d "$FindBin::Bin/$_", @DIRS;
79 # If we're running on RT 3.8 with plugin support, we really wany
80 # to install libs, mason templates and po files into plugin specific
83 if ( $RT::LocalPluginPath ) {
84 die "Because of bugs in RT 3.8.0 this extension can not be installed.\n"
85 ."Upgrade to RT 3.8.1 or newer.\n" if $RT::VERSION =~ /^3\.8\.0/;
86 $path{$_} = $RT::LocalPluginPath . "/$original_name/$_"
91 my $varname = "RT::Local" . ucfirst($_) . "Path";
92 $path{$_} = ${$varname} || "$RT::LocalPath/$_";
95 $path{$_} .= "/$name" for grep $path{$_}, qw(etc po var);
98 my %index = map { $_ => 1 } @INDEX_DIRS;
99 $self->no_index( directory => $_ ) foreach grep !$index{$_}, @DIRS;
101 my $args = join ', ', map "q($_)", map { ($_, $path{$_}) }
102 grep $subdirs{$_}, keys %path;
104 print "./$_\t=> $path{$_}\n" for sort keys %subdirs;
106 if ( my @dirs = map { ( -D => $_ ) } grep $subdirs{$_}, qw(bin html sbin) ) {
107 my @po = map { ( -o => $_ ) }
109 File::Glob::bsd_glob("po/*.po");
110 $self->postamble(<< ".") if @po;
112 \t\$(NOECHO) \$(PERL) -MLocale::Maketext::Extract::Run=xgettext -e \"xgettext(qw(@dirs @po))\"
116 my $postamble = << ".";
118 \t\$(NOECHO) \$(PERL) -MExtUtils::Install -e \"install({$args})\"
121 if ( $subdirs{var} and -d $RT::MasonDataDir ) {
122 my ( $uid, $gid ) = ( stat($RT::MasonDataDir) )[ 4, 5 ];
123 $postamble .= << ".";
124 \t\$(NOECHO) chown -R $uid:$gid $path{var}
129 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/schema.*") ) {
131 # got schema, load factory module
133 $self->load('RTxFactory');
134 $self->postamble(<< ".");
136 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name))"
139 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name drop))"
143 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/acl.*") ) {
146 if ( -e 'etc/initialdata' ) { $has_etc{initialdata}++; }
148 $self->postamble("$postamble\n");
149 unless ( $subdirs{'lib'} ) {
150 $self->makemaker_args( PM => { "" => "" }, );
152 $self->makemaker_args( INSTALLSITELIB => $path{'lib'} );
153 $self->makemaker_args( INSTALLARCHLIB => $path{'lib'} );
156 $self->makemaker_args( INSTALLSITEMAN1DIR => "$RT::LocalPath/man/man1" );
157 $self->makemaker_args( INSTALLSITEMAN3DIR => "$RT::LocalPath/man/man3" );
158 $self->makemaker_args( INSTALLSITEARCH => "$RT::LocalPath/man" );
161 $self->load('RTxInitDB');
162 print "For first-time installation, type 'make initdb'.\n";
164 $initdb .= <<"." if $has_etc{schema};
165 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(schema))"
167 $initdb .= <<"." if $has_etc{acl};
168 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(acl))"
170 $initdb .= <<"." if $has_etc{initialdata};
171 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(insert))"
173 $self->postamble("initdb ::\n$initdb\n");
174 $self->postamble("initialize-database ::\n$initdb\n");
179 unshift @INC, substr( delete( $INC{'RT.pm'} ), 0, -5 ) if $INC{'RT.pm'};
182 RT::ConnectToDatabase();
184 die "Cannot load RT" unless $RT::Handle and $RT::DatabaseType;