lib/Mail/Toaster/Darwin.pm

filter: Statementstmt 24.6% 20 / 81 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 54.5% 6 / 11 Podpod 40.0% 2 / 5 totaltotal 19.8% 28 / 141 SCAR 53.2
CC
18
Cov
17%
update_ports
72.0
install_port
30.0
update_ports_init
20.0
CRAP 203.6
« blib/lib/Mail/Toaster/Setup/Maildrop.pm ↑ Summary blib/lib/Mail/Toaster/Darwin.pm »
1 package Mail::Toaster::Darwin;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '5.50';
6  
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Params::Validate ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use parent 'Mail::Toaster::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub install_port {
14 0 ▶ my $self = shift;
Subroutine install_port: not called CC=5 SCAR=34.0
Pod documented
15 0 ▶ my $port_name = shift or return $self->error("missing port name", fatal => 0);
Branch: 1 branch
BranchTrueFalseTotal
my $port_name = shift() or return $self->error("missing port name", "fatal", 0) 0 0 0
16  
17 0 my %p = validate( @_, {
18 'opts' => { type=>SCALAR, optional=>1 },
19 $self->get_std_opts,
20 },
21 );
22  
23 0 my %args = $self->get_std_args( %p );
24 0 my $opts = $p{opts};
25  
26 #$self->ports_check_age("30");
27  
28 0 print "install_port: installing $port_name...";
29  
30 0 my $port_bin = $self->util->find_bin( 'port', %args );
31  
32 0 ▶ unless ( -x $port_bin ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $port_bin) 0 0 0
33 0 print "FAILED: please install DarwinPorts!\n";
34 0 return 0;
35 }
36  
37 0 my $cmd = "$port_bin install $port_name";
38 0 ▶ $cmd .= " $opts" if (defined $opts && $opts);
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts and $opts 0 0 0
Condition0%0/3
defined $opts and $opts
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts and $opts
defined $opts $opts
Truth table0%0/3
A and B
A= defined $optsB= $opts
ABresult
0X0
100
111
39
40 0 return $self->util->syscmd( $cmd, %args );
41 }
42  
43 sub ports_check_age {
44  
45 0 ▶ my ( $self, $age, $url ) = @_;
Subroutine ports_check_age: not called CC=3 SCAR=24.8
Pod undocumented
46  
47 0 ▶ $url ||= "http://mail-toaster.org";
Condition0%0/2
$url ||= "http://mail-toaster.org"
l!l
00
MC/DC0%0/1
$url ||= "http://mail-toaster.org"
$url
Truth table0%0/2
A
A= $url
Aresult
11
00
48  
49 0 ▶ if ( -M "/usr/ports" > $age ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-M '/usr/ports' > $age) { } 0 0 0
50 0 $self->update_ports();
51 }
52 else {
53 0 print "ports_check_age: Ports file is current (enough).\n";
54 }
55 }
56  
57 sub update_ports {
58 0 ▶ my $self = shift;
Subroutine update_ports: not called CC=8 SCAR=42.8
Pod documented
59 0 my $cvsbin = $self->util->find_bin( "cvs",fatal=>0, verbose=>0 );
60  
61 0 ▶ unless ( -x $cvsbin ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $cvsbin) 0 0 0
62 0 die "FATAL: could not find cvs, please install Developer Tools!\n";
63 }
64  
65 0 print "Updating Darwin ports...\n";
66  
67 0 my $portsdir = "/usr/darwinports";
68  
69 0 ▶ if ( !-d $portsdir && -e "/usr/dports" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -d $portsdir and -e "/usr/dports") 0 0 0
Condition0%0/3
not -d $portsdir and -e "/usr/dports"
!ll&&!rl&&r
000
MC/DC0%0/2
not -d $portsdir and -e "/usr/dports"
not -d $portsdir -e "/usr/dports"
Truth table0%0/3
not(A) and B
A= not -d $portsdirB= -e "/usr/dports"
ABresult
0X0
100
111
70 0 $portsdir = "/usr/dports";
71 }
72  
73 0 ▶ if ( !-d $portsdir && -e "/usr/ports/dports" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -d $portsdir and -e "/usr/ports/dports") 0 0 0
Condition0%0/3
not -d $portsdir and -e "/usr/ports/dports"
!ll&&!rl&&r
000
MC/DC0%0/2
not -d $portsdir and -e "/usr/ports/dports"
not -d $portsdir -e "/usr/ports/dports"
Truth table0%0/3
not(A) and B
A= not -d $portsdirB= -e "/usr/ports/dports"
ABresult
0X0
100
111
74 0 $portsdir = "/usr/ports/dports";
75 }
76  
77 0 ▶ if ( -d $portsdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $portsdir) { } 0 0 0
78 0 ▶ $self->update_ports_sync() and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->update_ports_sync and return 0 0 0
79 }
80 else {
81 0 $self->update_ports_init();
82 };
83 };
84  
85 sub update_ports_init {
86 0 ▶ my $self = shift;
Subroutine update_ports_init: not called CC=4 SCAR=30.0
Pod undocumented
87  
88 0 print <<'EO_NO_PORTS';
89 WARNING! I expect to find your dports dir in /usr/ports/dports. Please install
90 it there or add a symlink there pointing to where you have your Darwin ports
91 installed.
92
93 If you need to install DarwinPorts, please visit this URL for details:
94 http://darwinports.opendarwin.org/getdp/
95  
96 or the DarwinPorts guide:
97 http://darwinports.opendarwin.org/docs/ch01s03.html.
98  
99 EO_NO_PORTS
100 ;
101  
102 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->util->yes_or_no("q", "May I try to set up darwin ports for you?")) 0 0 0
103 $self->util->yes_or_no(
104 q=>"May I try to set up darwin ports for you?")
105 )
106 {
107 0 print "ok, skipping install.\n";
108 0 return;
109 }
110  
111 0 $self->util->cwd_source_dir( "/usr", verbose=>0 );
112  
113 0 print "\n\nthe CVS password is blank, just hit return at the prompt\n\n";
114  
115 0 my $cmd =
116 'cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/Volumes/src/cvs/od login';
117 0 $self->util->syscmd( $cmd, verbose=>0 );
118
119 0 $cmd =
120 'cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/Volumes/src/cvs/od co -P darwinports';
121 0 $self->util->syscmd( $cmd, verbose=>0 );
122
123 0 chdir("/usr");
124 0 $self->util->syscmd( "mv darwinports dports", verbose=>0 );
125
126 0 ▶ unless ( -d "/etc/ports" ) { mkdir( "/etc/ports", oct('0755') ) };
Branch: 1 branch
BranchTrueFalseTotal
unless (-d "/etc/ports") 0 0 0
127
128 0 $self->util->syscmd( "cp dports/base/doc/sources.conf /etc/ports/", verbose=>0 );
129 0 $self->util->syscmd( "cp dports/base/doc/ports.conf /etc/ports/", verbose=>0 );
130
131 0 $self->util->file_write( "/etc/ports/sources.conf",
132 lines => ["file:///usr/dports/dports"],
133 append => 1,
134 verbose => 0,
135 );
136  
137 0 my $portindex = $self->util->find_bin( "portindex",verbose=>0 );
138 0 ▶ unless ( -x $portindex ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $portindex) 0 0 0
139 0 print "compiling darwin ports base.\n";
140 0 chdir("/usr/dports/base");
141 0 $self->util->syscmd( "./configure; make; make install", verbose=>0 );
142 }
143 }
144  
145 sub update_ports_sync {
146 0 ▶ my $self = shift;
Subroutine update_ports_sync: not called CC=2 SCAR=17.9
Pod undocumented
147  
148 0 print "\n\nupdate_ports: You might want to update your ports tree!\n\n";
149 0 ▶ if ( ! $self->util->yes_or_no(
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->util->yes_or_no("question", "\n\nWould you like me to do it for you?")) 0 0 0
150 question=>"\n\nWould you like me to do it for you?" ) )
151 {
152 0 print "ok then, skipping update.\n";
153 0 return;
154 }
155  
156 # the new way
157 0 my $bin = $self->util->find_bin( "port" );
158 0 return $self->util->syscmd( "$bin -d sync" );
159  
160 # the old way
161 #chdir($portsdir);
162  
163 #print "\n\nthe CVS password is blank, just hit return at the prompt)\n\n";
164  
165 #my $cmd = 'cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/Volumes/src/cvs/od login';
166 #$self->util->syscmd( $cmd );
167 #$self->util->syscmd( 'cvs -q -z3 update -dP' );
168  
169 # if ( -x "/opt/local/bin/portindex") { #
170 # $self->util->syscmd( "/opt/local/bin/portindex" ); }
171 # elsif ( -x "/usr/local/bin/portindex" ) { #
172 # $self->util->syscmd( "/usr/local/bin/portindex" );
173 # };
174 }
175  
176 1 1;
177 __END__
178  
179  
180 =head1 NAME
181  
182 Mail::Toaster::Darwin - Darwin specific Mail Toaster functions
183  
184 =head1 SYNOPSIS
185  
186 Mac OS X (Darwin) scripting functions
187  
188  
189 =head1 DESCRIPTION
190  
191 functions I've written for perl scripts running on MacOS X (Darwin) systems.
192  
193 Usage examples for each subroutine are included.
194  
195  
196 =head1 SUBROUTINES
197  
198 =over
199  
200 =item new
201  
202 use Mail::Toaster::Darwin;
203 my $darwin = Mail::Toaster::Darwin->new;
204  
205  
206 =item update_ports
207  
208 Updates the Darwin Ports tree (/usr/ports/dports/).
209  
210 $darwin->update_ports();
211  
212  
213 =item install_port
214  
215 $darwin->install_port( "openldap2" );
216  
217 That's it. Really. Honest. Nothing more.
218  
219 arguments required:
220 port - the name of the port
221  
222 arguments optional:
223 opts - port options you can pass
224  
225  
226 =back
227  
228 =head1 AUTHOR
229  
230 Matt Simerson <matt@tnpi.net>
231  
232 =head1 BUGS
233  
234 None known. Report any to author.
235  
236 Needs more documentation.
237  
238 =head1 SEE ALSO
239  
240 The following are all man/perldoc pages:
241  
242 Mail::Toaster
243 Mail::Toaster::Conf
244 toaster.conf
245 toaster-watcher.conf
246  
247 http://mail-toaster.org/
248  
249  
250 =head1 COPYRIGHT AND LICENSE
251  
252 Copyright (c) 2003-2008, The Network People, Inc. All Rights Reserved.
253  
254 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
255  
256 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
257  
258 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
259  
260 Neither the name of the The Network People, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
261  
262 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
263  
264  
265 =cut
« blib/lib/Mail/Toaster/Setup/Maildrop.pm ↑ Summary blib/lib/Mail/Toaster/Darwin.pm »