2 package Module::Install::RTx;
9 use Module::Install::Base;
10 use base 'Module::Install::Base';
11 our $VERSION = '0.25';
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 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;
64 $RT::LocalVarPath ||= $RT::VarPath;
65 $RT::LocalPoPath ||= $RT::LocalLexiconPath;
66 $RT::LocalHtmlPath ||= $RT::MasonComponentRoot;
67 $RT::LocalLibPath ||= "$RT::LocalPath/lib";
69 my $with_subdirs = $ENV{WITH_SUBDIRS};
70 @ARGV = grep { /WITH_SUBDIRS=(.*)/ ? ( ( $with_subdirs = $1 ), 0 ) : 1 }
74 %subdirs = map { $_ => 1 } split( /\s*,\s*/, $with_subdirs )
75 if defined $with_subdirs;
76 unless ( keys %subdirs ) {
77 $subdirs{$_} = 1 foreach grep -d "$FindBin::Bin/$_", @DIRS;
80 # If we're running on RT 3.8 with plugin support, we really wany
81 # to install libs, mason templates and po files into plugin specific
84 if ( $RT::LocalPluginPath ) {
85 die "Because of bugs in RT 3.8.0 this extension can not be installed.\n"
86 ."Upgrade to RT 3.8.1 or newer.\n" if $RT::VERSION =~ /^3\.8\.0/;
87 $path{$_} = $RT::LocalPluginPath . "/$original_name/$_"
92 my $varname = "RT::Local" . ucfirst($_) . "Path";
93 $path{$_} = ${$varname} || "$RT::LocalPath/$_";
96 $path{$_} .= "/$name" for grep $path{$_}, qw(etc po var);
99 my %index = map { $_ => 1 } @INDEX_DIRS;
100 $self->no_index( directory => $_ ) foreach grep !$index{$_}, @DIRS;
102 my $args = join ', ', map "q($_)", map { ($_, $path{$_}) }
103 grep $subdirs{$_}, keys %path;
105 print "./$_\t=> $path{$_}\n" for sort keys %subdirs;
107 if ( my @dirs = map { ( -D => $_ ) } grep $subdirs{$_}, qw(bin html sbin) ) {
108 my @po = map { ( -o => $_ ) }
110 File::Glob::bsd_glob("po/*.po");
111 $self->postamble(<< ".") if @po;
113 \t\$(NOECHO) \$(PERL) -MLocale::Maketext::Extract::Run=xgettext -e \"xgettext(qw(@dirs @po))\"
117 my $postamble = << ".";
119 \t\$(NOECHO) \$(PERL) -MExtUtils::Install -e \"install({$args})\"
122 if ( $subdirs{var} and -d $RT::MasonDataDir ) {
123 my ( $uid, $gid ) = ( stat($RT::MasonDataDir) )[ 4, 5 ];
124 $postamble .= << ".";
125 \t\$(NOECHO) chown -R $uid:$gid $path{var}
130 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/schema.*") ) {
132 # got schema, load factory module
134 $self->load('RTxFactory');
135 $self->postamble(<< ".");
137 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name))"
140 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name drop))"
144 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/acl.*") ) {
147 if ( -e 'etc/initialdata' ) { $has_etc{initialdata}++; }
149 $self->postamble("$postamble\n");
150 unless ( $subdirs{'lib'} ) {
151 $self->makemaker_args( PM => { "" => "" }, );
153 $self->makemaker_args( INSTALLSITELIB => $path{'lib'} );
154 $self->makemaker_args( INSTALLARCHLIB => $path{'lib'} );
157 $self->makemaker_args( INSTALLSITEMAN1DIR => "$RT::LocalPath/man/man1" );
158 $self->makemaker_args( INSTALLSITEMAN3DIR => "$RT::LocalPath/man/man3" );
159 $self->makemaker_args( INSTALLSITEARCH => "$RT::LocalPath/man" );
162 $self->load('RTxInitDB');
163 print "For first-time installation, type 'make initdb'.\n";
165 $initdb .= <<"." if $has_etc{schema};
166 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(schema))"
168 $initdb .= <<"." if $has_etc{acl};
169 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(acl))"
171 $initdb .= <<"." if $has_etc{initialdata};
172 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(insert))"
174 $self->postamble("initdb ::\n$initdb\n");
175 $self->postamble("initialize-database ::\n$initdb\n");
180 unshift @INC, substr( delete( $INC{'RT.pm'} ), 0, -5 ) if $INC{'RT.pm'};
183 RT::ConnectToDatabase();
185 die "Cannot load RT" unless $RT::Handle and $RT::DatabaseType;