Really work around https://github.com/travis-ci/travis-ci/issues/1477
[dbsrgits/DBIx-Class.git] / maint / travis-ci_scripts / 20_install.bash
1 #!/bin/bash
2
3 source maint/travis-ci_scripts/common.bash
4 if [[ -n "$SHORT_CIRCUIT_SMOKE" ]] ; then return ; fi
5
6 CPAN_MIRROR=$(echo "$PERL_CPANM_OPT" | grep -oP -- '--mirror\s+\S+' | head -n 1 | cut -d ' ' -f 2)
7 if ! [[ "$CPAN_MIRROR" =~ "http://" ]] ; then
8   echo_err "Unable to extract primary cpan mirror from PERL_CPANM_OPT - something is wrong"
9   echo_err "PERL_CPANM_OPT: $PERL_CPANM_OPT"
10   CPAN_MIRROR="http://cpan.metacpan.org/"
11   PERL_CPANM_OPT="$PERL_CPANM_OPT --mirror $CPAN_MIRROR"
12   echo_err "Using $CPAN_MIRROR for the time being"
13 fi
14
15 export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 PERL_AUTOINSTALL_PREFER_CPAN=1 PERLBREW_CPAN_MIRROR="$CPAN_MIRROR"
16
17 # try CPAN's latest offering if requested
18 if [[ "$DEVREL_DEPS" == "true" ]] ; then
19
20   if [[ "$CLEANTEST" == "true" ]] ; then
21     echo_err "DEVREL_DEPS combined with CLEANTEST makes no sense - it is only possible with cpanm"
22     exit 1
23   fi
24
25   PERL_CPANM_OPT="$PERL_CPANM_OPT --dev"
26
27   # FIXME inline-upgrade cpanm, work around https://github.com/travis-ci/travis-ci/issues/1477
28   cpanm_loc="$(which cpanm)"
29   run_or_err "Upgrading cpanm ($cpanm_loc) to latest stable" \
30     "wget -q -O $cpanm_loc cpanmin.us && chmod a+x $cpanm_loc"
31 fi
32
33 # Fixup CPANM_OPT to behave more like a traditional cpan client
34 export PERL_CPANM_OPT="--verbose --no-interactive --no-man-pages $( echo $PERL_CPANM_OPT | sed 's/--skip-satisfied//' )"
35
36 if [[ -n "$BREWVER" ]] ; then
37   run_or_err "Compiling/installing Perl $BREWVER (without testing, may take up to 5 minutes)" \
38     "perlbrew install --as $BREWVER --notest --noman --verbose $BREWOPTS -j 2  $BREWVER"
39
40   # can not do 'perlbrew uss' in the run_or_err subshell above, or a $()
41   # furthermore `perlbrew use` returns 0 regardless of whether the perl is
42   # found (won't be there unless compilation suceeded, wich *ALSO* returns 0)
43   perlbrew use $BREWVER
44
45   if [[ "$( perlbrew use | grep -oP '(?<=Currently using ).+' )" != "$BREWVER" ]] ; then
46     echo_err "Unable to switch to $BREWVER - compilation failed...?"
47     echo_err "$LASTOUT"
48     exit 1
49   fi
50
51 fi
52
53 # configure CPAN.pm - older versions go into an endless loop
54 # when trying to autoconf themselves
55 CPAN_CFG_SCRIPT="
56   require CPAN;
57   require CPAN::FirstTime;
58   *CPAN::FirstTime::conf_sites = sub {};
59   CPAN::Config->load;
60   \$CPAN::Config->{urllist} = [qw{ $CPAN_MIRROR }];
61   \$CPAN::Config->{halt_on_failure} = 1;
62   CPAN::Config->commit;
63 "
64 run_or_err "Configuring CPAN.pm" "perl -e '$CPAN_CFG_SCRIPT'"