3ee6ed27f0119eeb21fbb0a0ba4914d699e7a0b4
[catagits/Gitalist.git] / script / bootstrap.pl
1 #!/usr/bin/env perl
2
3 # This script installs an initial local::lib into your application directory
4 # named local-lib5, which automatically turns on local::lib support by default.
5
6 # Needs to be run as script/bootstrap.pl
7
8 # Will then install Module::Install, and all of your dependencies into
9 # the local lib directory created.
10
11 use strict;
12 use warnings;
13
14 use lib;
15 use FindBin;
16 use CPAN;
17
18 # Do not take no for an answer.
19
20 $ENV{CATALYST_LOCAL_LIB}=1;
21
22 # Get the base paths and setup your %ENV
23
24 my $basedir;
25 if (-r "$FindBin::Bin/Makefile.PL") {
26     $basedir = $FindBin::Bin;
27 }
28 elsif (-r "$FindBin::Bin/../Makefile.PL") {
29     $basedir = "$FindBin::Bin/..";
30 }
31
32 $basedir ||= '';
33 my $target = "$basedir/local-lib5";
34 my $lib = "$target/lib/perl5";
35
36 # Start installing stuff in the target dir
37 $ENV{PERL_MM_OPT} = "INSTALL_BASE=$target";
38 $ENV{PERL_MM_USE_DEFAULT} = "1";
39 # And allow dependency checks to find it
40 lib->import("$target/lib/perl5");
41
42 # Deal with the weird case that cpan has never been run before and
43 # cpan wants to create a .cpan directory in /root or somewhere you
44 # can't access
45
46 local %CPAN::Config;
47 require CPAN::HandleConfig;w
48 CPAN::HandleConfig->load();
49 $CPAN::Config->{prefs_dir} = "~/.cpan/prefs";
50
51 # First just force install local::lib to get it local to $target
52 force(qw/install LWP::UserAgent/); # Need LWP for CPAN to work on Mac, as curl and
53                            # wget puke on the spaces in
54                            # ~/Library/Applicaton Support
55                            # Note - this needs to happen before File::HomeDir
56 # Need to force File::HomeDir on the Mac
57 if ($^O eq "darwin") {
58     force(qw/install Mac::Carbon/);
59 }
60 force(qw/install local::lib/);
61
62 require local::lib; # Turn local::lib on
63 local::lib->import( $target );
64
65 # Become fully self contained
66 $ENV{PERL5LIB} = ""; # If we used a local::lib to bootstrap, this kills it.
67
68 # Sorry kane ;)
69 $ENV{PERL_AUTOINSTALL_PREFER_CPAN}=1;
70 $ENV{PERL_MM_OPT} .= " INSTALLMAN1DIR=none INSTALLMAN3DIR=none";
71
72 local::lib->import( '--self-contained', $target );
73
74 # Force a re-install of local::lib here to get the dependencies for local::lib
75 # It requires things which ensure we have an unfucked toolchain :)
76 force(qw/install local::lib/);
77
78 # Install the base modules
79 install('Module::Install');
80 install('YAML');
81 install('CPAN');
82 install('Module::Install::Catalyst');
83
84 # setup distroprefs
85 {
86     # Ok, god only knows what version of CPAN we started with, so lets nuke the
87     # config and try to reload it here for safety
88     local %CPAN::Config;
89     require CPAN::HandleConfig; # not installed till we installed CPAN (5.8.x)
90     CPAN::HandleConfig->load();
91     mkdir $CPAN::Config->{prefs_dir} unless -d $CPAN::Config->{prefs_dir};
92     open(my $prefs, ">", File::Spec->catfile($CPAN::Config->{prefs_dir},
93         "catalyst_local-lib-disable-mech-live.yml")) or die "Can't open prefs_dir: $!";
94
95     print $prefs qq{---
96 comment: "WWW-Mechanize regularly fails its live tests, turn them off."
97 match:
98   distribution: "^PETDANCE/WWW-Mechanize-1.\\d+\\.tar\\.gz"
99 patches:
100   - "BOBTFISH/WWW-Mechanize-1.XX-BOBTFISH-01_notests.patch.gz"
101 };
102
103     close($prefs);
104 }
105
106 print "local::lib setup, type perl Makefile.PL && make installdeps to install dependencies";
107