File Coverage

lib/Mail/Toaster/Darwin.pm
Criterion Covered Total %
statement 18 79 22.7
branch 0 26 0.0
condition 0 11 0.0
subroutine 6 11 54.5
pod 2 5 40.0
total 26 132 19.7


line stmt bran cond sub pod time code
1             package Mail::Toaster::Darwin;
2 1     1   829 use strict;
  1         1  
  1         25  
3 1     1   3 use warnings;
  1         2  
  1         30  
4              
5             our $VERSION = '5.50';
6              
7 1     1   3 use Carp;
  1         1  
  1         53  
8 1     1   3 use Params::Validate ':all';
  1         1  
  1         153  
9              
10 1     1   4 use lib 'lib';
  1         1  
  1         6  
11 1     1   131 use parent 'Mail::Toaster::Base';
  1         2  
  1         6  
12              
13             sub install_port {
14 0     0 1   my $self = shift;
15 0 0         my $port_name = shift or return $self->error("missing port name", fatal => 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 0         unless ( -x $port_bin ) {
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 0 0       $cmd .= " $opts" if (defined $opts && $opts);
39            
40 0           return $self->util->syscmd( $cmd, %args );
41             }
42              
43             sub ports_check_age {
44              
45 0     0 0   my ( $self, $age, $url ) = @_;
46              
47 0   0       $url ||= "http://mail-toaster.org";
48              
49 0 0         if ( -M "/usr/ports" > $age ) {
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     0 1   my $self = shift;
59 0           my $cvsbin = $self->util->find_bin( "cvs",fatal=>0, verbose=>0 );
60              
61 0 0         unless ( -x $cvsbin ) {
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 0 0       if ( !-d $portsdir && -e "/usr/dports" ) {
70 0           $portsdir = "/usr/dports";
71             }
72              
73 0 0 0       if ( !-d $portsdir && -e "/usr/ports/dports" ) {
74 0           $portsdir = "/usr/ports/dports";
75             }
76              
77 0 0         if ( -d $portsdir ) {
78 0 0         $self->update_ports_sync() and return;
79             }
80             else {
81 0           $self->update_ports_init();
82             };
83             };
84              
85             sub update_ports_init {
86 0     0 0   my $self = shift;
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 0         unless (
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 0         unless ( -d "/etc/ports" ) { mkdir( "/etc/ports", oct('0755') ) };
  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 0         unless ( -x $portindex ) {
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     0 0   my $self = shift;
147              
148 0           print "\n\nupdate_ports: You might want to update your ports tree!\n\n";
149 0 0         if ( ! $self->util->yes_or_no(
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;
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