Skip to content

Commit

Permalink
tw: default install method is now packages (pkgng)
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Sep 10, 2014
1 parent a42d056 commit 6cf6fd7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 82 deletions.
81 changes: 18 additions & 63 deletions lib/Mail/Toaster/FreeBSD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package Mail::Toaster::FreeBSD;
use strict;
use warnings;

our $VERSION = '5.44';
our $VERSION = '5.47';

use Carp;
use File::Copy;
Expand Down Expand Up @@ -50,13 +50,6 @@ sub get_defines {
return $make_defines;
};

sub get_pkg {
my $self = shift;
return 'pkg' if ! -x '/usr/sbin/pkg';
return 'pkg' if ! `/usr/sbin/pkg info pkg`;
return 'pkgng';
};

sub get_port_category {
my $self = shift;
my $port = shift or die "missing port in request\n";
Expand Down Expand Up @@ -145,28 +138,28 @@ sub install_port {

sub is_port_installed {
my $self = shift;
my $port = shift or return $self->error("missing port/package name", fatal=>0);
my $port = shift or return $self->error("missing port name", fatal=>0);
my %p = validate( @_,
{ 'alt' => { type => SCALAR | UNDEF, optional => 1 },
$self->get_std_opts,
},
);

my $alt = $p{'alt'} || $port;
my $alt = $p{alt} || $port;

my ( $r, @args );

$self->util->audit( " checking for port $port", verbose=>0);

return $p{'test_ok'} if defined $p{'test_ok'};
return $p{test_ok} if defined $p{test_ok};

my @packages;
if ( $self->get_pkg eq 'pkgng' ) {
if ( -x '/usr/sbin/pkg' ) {
@packages = `/usr/sbin/pkg info`; chomp @packages;
}
else {
my $pkg_info = $self->util->find_bin( 'pkg_info', verbose => 0 );
@packages = `pkg_info`; chomp @packages;
@packages = `$pkg_info`; chomp @packages;
}

my @matches = grep {/^$port\-/} @packages;
Expand Down Expand Up @@ -227,10 +220,6 @@ sub install_package {
my ( $alt, $pkg_url ) = ( $p{'alt'}, $p{'url'} );
my %args = $self->toaster->get_std_args( %p );

my $pkg_method = $self->conf->{'use_pkgng'} || 0;

return $self->util->error("sorry, but I really need a package name!") if !$package;

$self->util->audit("install_package: checking if $package is installed");

return $p{'test_ok'} if defined $p{'test_ok'};
Expand All @@ -240,60 +229,26 @@ sub install_package {
print "install_package: installing $package....\n";
$ENV{"PACKAGESITE"} = $pkg_url if $pkg_url;

my $pkg_add;
if ( $pkg_method == 0) {
$pkg_add = $self->util->find_bin( "pkg_add", %args );
} else {
$pkg_add = $self->util->find_bin( "pkg", %args );
my ($pkg_add, $r2);
if ( -x '/usr/sbin/pkg' ) {
$pkg_add = '/usr/sbin/pkg';
$r2 = $self->util->syscmd( "$pkg_add install -y $package", verbose => 0 );
}

return $self->error( "couldn't find pkg_add, giving up.",fatal=>0)
if ( !$pkg_add || !-x $pkg_add );

my $r2;
if ( $pkg_method == 0) {
if (! -x $pkg_add) {
$pkg_add = $self->util->find_bin( "pkg_add", %args );
if ( !$pkg_add || !-x $pkg_add ) {
return $self->error( "couldn't find pkg_add",fatal=>0)
};
$r2 = $self->util->syscmd( "$pkg_add -r $package", verbose => 0 );
} else {
$r2 = $self->util->syscmd( "$pkg_add add -r $package", verbose => 0 );
}

if ( !$r2 ) { print "\t pkg_add failed\t "; }
else { print "\t pkg_add success\t " };

unless ( $self->is_port_installed( $package, alt => $alt, %args )) {
print "Failure #1, trying alternate package site.\n";
$ENV{"PACKAGEROOT"} = "ftp://ftp2.freebsd.org";
if ( $pkg_method == 0) {
$self->util->syscmd( "$pkg_add -r $package", verbose => 0 );
} else {
$self->util->syscmd( "$pkg_add add -r $package", verbose => 0 );
}


unless ( $self->is_port_installed( $package, alt => $alt, %args,)) {
print "Failure #2, trying alternate package site.\n";
$ENV{"PACKAGEROOT"} = "ftp://ftp3.freebsd.org";
if ( $pkg_method == 0) {
$self->util->syscmd( "$pkg_add -r $package", verbose => 0 );
} else {
$self->util->syscmd( "$pkg_add add -r $package", verbose => 0 );
}

unless ( $self->is_port_installed( $package, alt => $alt, %args,)) {
print "Failure #3, trying alternate package site.\n";
$ENV{"PACKAGEROOT"} = "ftp://ftp4.freebsd.org";
if ( $pkg_method == 0) {
$self->util->syscmd( "$pkg_add -r $package", verbose => 0 );
} else {
$self->util->syscmd( "$pkg_add add -r $package", verbose => 0 );
}
}
}
}
if ( !$r2 ) { print "\t $pkg_add failed\t "; }
else { print "\t $pkg_add success\t " };

my $r = $self->is_port_installed( $package, alt => $alt, %args );
if ( ! $r ) {
carp " : Failed again! Sorry, I can't install the package $package!\n";
carp " : Sorry, I couldn't install $package!\n";
return;
}

Expand Down
49 changes: 33 additions & 16 deletions lib/Mail/Toaster/Setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ sub cronolog {

sub cronolog_freebsd {
my $self = shift;
$self->freebsd->install_package('cronolog');
return 1 if $self->freebsd->is_port_installed('cronolog');
return $self->freebsd->install_port( "cronolog",
fatal => 0,
options => "# This file generated by mail-toaster
Expand Down Expand Up @@ -833,16 +835,11 @@ sub dependencies {

if ( $OSNAME eq "freebsd" ) {
$self->dependencies_freebsd();
$self->freebsd->install_port( "p5-Net-DNS",
options => "#\n# This file was generated by mail-toaster
# Options for p5-Net-DNS-0.58\n_OPTIONS_READ=p5-Net-DNS-0.58\nWITHOUT_IPV6=true",
);
}
elsif ( $OSNAME eq "darwin" ) {
my @dports =
qw/ cronolog gdbm gmake ucspi-tcp daemontools DarwinPortsStartup /;

push @dports, qw/aspell aspell-dict-en/ if $self->conf->{install_aspell};
push @dports, "maildrop" if $self->conf->{install_maildrop};
push @dports, "openldap" if $self->conf->{install_openldap_client};
push @dports, "gnupg" if $self->conf->{install_gnupg};
Expand Down Expand Up @@ -884,9 +881,11 @@ sub dependencies_freebsd {
$self->ucspi_tcp_freebsd;
$self->cronolog_freebsd;

my @to_install = { port => "p5-Params-Validate" };
my @to_install = (
{ port => "p5-Params-Validate" },
{ port => "p5-Net-DNS" },
);
push @to_install, { port => "setquota" } if $self->conf->{install_quota_tools};
push @to_install, { port => "portaudit" } if $self->conf->{install_portaudit};
push @to_install, {
port => 'gdbm',
options => "# This file generated by Mail::Toaster
Expand Down Expand Up @@ -1469,7 +1468,6 @@ OPTIONS_FILE_SET+=VPOPMAIL
}

sub dovecot_start {

my $self = shift;

unless ( $OSNAME eq "freebsd" ) {
Expand Down Expand Up @@ -1818,22 +1816,37 @@ sub gmake_freebsd {
my $self = shift;

# iconv to suppress a prompt, and because gettext requires it
$self->freebsd->install_port( 'libiconv',
options => "#\n# This file was generated by mail-toaster
if (!$self->freebsd->is_port_installed('libiconv')) {
$self->freebsd->install_package('libiconv');
if (!$self->freebsd->is_port_installed('libiconv')) {
$self->freebsd->install_port( 'libiconv',
options => "#\n# This file was generated by mail-toaster
# Options for libiconv-1.13.1_1
_OPTIONS_READ=libiconv-1.13.1_1
WITH_EXTRA_ENCODINGS=true
WITHOUT_EXTRA_PATCHES=true\n",
);
);
}
}

# required by gmake
$self->freebsd->install_port( "gettext",
options => "#\n# This file was generated by mail-toaster
if (!$self->freebsd->is_port_installed('gettext')) {
$self->freebsd->install_package('gettext');
if (!$self->freebsd->is_port_installed('gettext')) {
$self->freebsd->install_port( "gettext",
options => "#\n# This file was generated by mail-toaster
# Options for gettext-0.14.5_2
_OPTIONS_READ=gettext-0.14.5_2\n",
);
);
}
}

$self->freebsd->install_port( 'gmake' );
if (!$self->freebsd->is_port_installed('gmake')) {
$self->freebsd->install_package('gmake');
if (!$self->freebsd->is_port_installed('gmake')) {
$self->freebsd->install_port( 'gmake' );
}
}
};

sub gnupg_install {
Expand Down Expand Up @@ -2625,7 +2638,7 @@ sub openssl_cert {
$self->util->mkdir_system(dir=>$dir, verbose=>0) if ! -d $dir;

my $openssl = $self->util->find_bin('openssl', verbose=>0);
system "$openssl genrsa 1024 > $key" if ! -e $key;
system "$openssl genrsa 2048 > $key" if ! -e $key;
$self->error( "ssl cert key generation failed!") if ! -e $key;

system "$openssl req -new -key $key -out $csr" if ! -e $csr;
Expand Down Expand Up @@ -2791,6 +2804,10 @@ sub openssl_install {
sub openssl_install_freebsd {
my $self = shift;

if ($self->freebsd->install_package('openssl')) {
return 1;
}

return $self->freebsd->install_port( 'openssl',
category=> 'security',
options => "# Options for openssl-1.0.1_8
Expand Down
4 changes: 3 additions & 1 deletion lib/Mail/Toaster/Setup/Maildrop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sub install {
if ( $ver eq "port" || $ver eq "1" ) {
if ( $OSNAME eq "freebsd" ) {
# pre-installing pcre supresses a dialog
$self->freebsd->install_package( "pcre" );
$self->freebsd->install_port( "pcre",
options => '# written by Mail::Toaster
# Options for pcre-8.33
Expand All @@ -32,12 +33,13 @@ _FILE_COMPLETE_OPTIONS_LIST=STACK_RECURSION
OPTIONS_FILE_SET+=STACK_RECURSION
',
);
$self->freebsd->install_package( "maildrop" );
$self->freebsd->install_port( "maildrop", flags => "WITH_MAILDIRQUOTA=1",);
}
elsif ( $OSNAME eq "darwin" ) {
$self->darwin->install_port( "maildrop" );
}
$ver = "2.5.0";
$ver = "2.7.1";
}

$self->util->find_bin( "maildrop", fatal => 0 )
Expand Down
1 change: 1 addition & 0 deletions lib/Mail/Toaster/Utility.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,7 @@ sub install_module_freebsd {
};

return 1 if $self->freebsd->is_port_installed( $portname );
return 1 if $self->freebsd->install_package( $portname );

my $portdir = glob("/usr/ports/*/$portname");
return if ! $portdir;
Expand Down
3 changes: 1 addition & 2 deletions toaster-watcher.conf-dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ toaster_dl_url = /internet/mail/toaster
preserve_cgifiles = 0
toaster_apache_vhost = 1

package_install_method = ports # packages | ports
package_install_method = packages # packages | ports
# if both options are supported, the setup
# script will prefer the one you choose.

Expand All @@ -61,7 +61,6 @@ cvsup_supfile_ports = portsnap # portsnap or path to file
# ex: /etc/cvsup-ports
cvsup_supfile_sources = cvsup-sources
toaster_pkg_site = ftp://ftp.freebsd.org
use_pkgng = 1 # Use the new package format pkgng see https://wiki.freebsd.org/pkgng


######################################
Expand Down

0 comments on commit 6cf6fd7

Please sign in to comment.