Debian Codegraph @

bin/mcpani

raw
1 #!/usr/bin/perl
2 use v5.16;
3
4 use strict;
5 use Pod::Usage 1.12;
6 use Getopt::Long;
7 use YAML qw( Load );
8 use CPAN::Mini::Inject;
9 use Env;
10 use File::Slurp 'write_file';
11 use File::Temp;
12
13 our $VERSION = '0.38';
14 our %options = ();
15
16 sub print_version {
17 printf( "mcpani v%s, using CPAN::Mini::Inject v%s and Perl v%vd\n",
18 $VERSION, $CPAN::Mini::Inject::VERSION, $^V );
19 }
20
21 sub chkactions {
22 for my $action ( qw(add update mirror inject) ) {
23 return 1 if ( $options{actionname} eq $action );
24 }
25 return 0;
26 }
27
28 sub setsub {
29 $options{actionname} = shift;
30 $options{action} = shift;
31 }
32
33 sub add {
34 my $mcpi = shift;
35
36 $mcpi->readlist;
37
38 $mcpi->add(
39 module => $options{module},
40 authorid => $options{authorid},
41 version => $options{version},
42 file => $options{file}
43 );
44
45 if ( $options{verbose} ) {
46 my @added = $mcpi->added_modules;
47 foreach my $added ( @added ){
48 print "\nAdding File: $added->{file}\n";
49 print "Author ID: $added->{authorid}\n";
50 my $modules = $added->{modules};
51 foreach my $mod ( sort keys %$modules ){
52 print "Module: $mod\n";
53 print "Version: $modules->{$mod}\n";
54 }
55 print "To repository: $mcpi->{config}{repository}\n\n";
56 }
57 }
58 $mcpi->writelist;
59
60 }
61
62 sub update {
63 my $mcpi = shift;
64
65 mirror( $mcpi );
66 inject( $mcpi );
67 }
68
69 sub mirror {
70 my $mcpi = shift;
71
72 # these come from the command line
73 my %mirroropts =
74 map { $_ => $options{$_} }
75 grep { defined $options{$_} }
76 qw(remote local verbose);
77
78 $mcpi->update_mirror( %mirroropts );
79 }
80
81 sub inject {
82 my $mcpi = shift;
83
84 print "Injecting modules from $mcpi->{config}{repository}\n"
85 if ( $options{verbose} );
86 $mcpi->inject( $options{verbose} );
87 }
88
89 # MAIN
90 Getopt::Long::Configure( 'no_ignore_case' );
91 Getopt::Long::Configure( 'bundling' );
92
93 GetOptions(
94 'h|help|?' =>
95 sub { pod2usage( { -verbose => 1, -input => \*DATA } ); exit },
96 'H|man' =>
97 sub { pod2usage( { -verbose => 2, -input => \*DATA } ); exit },
98 'V|version' => sub { print_version(); exit; },
99 'v|verbose' => \$options{verbose},
100 'l|local=s' => \$options{local},
101 'r|remote=s' => \$options{remote},
102 'p|passive' => \$ENV{FTP_PASSIVE},
103 'add' => sub { setsub( 'add', \&add ) },
104 'update' => sub { setsub( 'update', \&update ) },
105 'mirror' => sub { setsub( 'mirror', \&mirror ) },
106 'inject' => sub { setsub( 'inject', \&inject ) },
107 'module=s' => \$options{module},
108 'authorid=s' => \$options{authorid},
109 'modversion=s' => \$options{version},
110 'file=s' => \$options{file},
111 'all-in-meta' => \$options{'all-in-meta'},
112 'signing-key=s' => \$options{'signing_key'},
113 'discover-packages' => \$options{'discover-packages'},
114 ) or exit 1;
115
116 unless ( defined( $options{action} ) && chkactions() ) {
117 pod2usage( { -verbose => 1, -input => \*DATA } );
118 exit;
119 }
120
121 my $mcpi = CPAN::Mini::Inject->new->loadcfg( $options{cfg} )->parsecfg;
122
123 $CPAN::Checksums::SIGNING_KEY = $options{'signing_key'}
124 if ($options{'signing_key'});
125
126 &{ $options{action} }( $mcpi );
127
128 __END__
129
130 =head1 NAME
131
132 mcpani -- A command line tool to manage a CPAN Mini Mirror.
133
134 =head1 SYNOPSIS
135
136 mcpani [options] < --add | --update | --mirror | --inject >
137
138 Commands:
139
140 --add Add a new package to the repository
141 --module Name of the module to add
142 --authorid Author ID of the module
143 --modversion Version number of the module
144 --file distribution module
145
146 --update Update local CPAN mirror and inject modules
147 --mirror Update local CPAN mirror from remote
148 --inject Add modules from repository to CPAN mirror
149
150 Options:
151
152 -h, --help This synopsis
153 -H, --man Detailed description
154
155 -l, --local local location for CPAN::Mini Mirror
156 -r, --remote CPAN mirror to mirror from
157 -p, --passive Enable passive ftp for mirroring.
158 -v, --verbose verbose output
159 -V, --version Version information.
160 --signing-key See CPAN::Checksums $SIGNING_KEY
161
162 =head1 DESCRIPTION
163
164 B<mcpani> uses L<CPAN::Mini> to build or update a local CPAN mirror from a
165 remote one, while also adding private or third-party distributions.
166
167 =head2 Configuration file
168
169 B<mcpani> will search the following four places in order:
170
171 =over 4
172
173 =item * file pointed to by the environment variable MCPANI_CONFIG
174
175 =item * $HOME/.mcpani/config
176
177 =item * /usr/local/etc/mcpani
178
179 =item * /etc/mcpani
180
181 =back
182
183 By default, B<mcpani> uses a simple configuration file in the following format:
184
185 local: /www/CPAN
186 remote: ftp://ftp.cpan.org/pub/CPAN ftp://ftp.kernel.org/pub/CPAN
187 repository: /work/mymodules
188 passive: yes
189 dirmode: 0755
190
191 =head2 Configuration options
192
193 =over 4
194
195 =item C<dirmode>
196
197 Set the permissions of created directories to the specified mode
198 (octal value). The default value is based on the umask (if supported).
199
200 =item C<force>
201
202 Update modules even if the module list is out of data. This is from
203 L<CPAN::Mini>.
204
205 =item C<local> (required)
206
207 Location to store local CPAN::Mini mirror
208
209 =item C<log_level>
210
211 The logging level for L<CPAN::Mini>.
212
213 =item C<passive>
214
215 Enable passive FTP.
216
217 =item C<remote> (required)
218
219 CPAN site(s) to mirror from. Multiple sites can be listed, with spaces
220 between them.
221
222 =item C<repository>
223
224 Location to store modules to add to the local CPAN::Mini mirror.
225
226 =item C<skip_cleanup>
227
228 Do not remove old files in the local directory. this is from L<CPAN::Mini>.
229
230 =item C<skip_perl>
231
232 Do not mirror B<perl> distributions. This is from L<CPAN::Mini>.
233
234 =item C<trace>
235
236 Enable trace logging. This is from L<CPAN::Mini>
237
238 =back
239
240 =head2 Command-line options
241
242 =over 4
243
244 =item C<--add>
245
246 =over 4
247
248 =item C<--authorid> the CPAN ID
249
250 =item C<--file> the distribution file
251
252 =item C<--module> the package name of the main module
253
254 =item C<-v>, C<--verbose>
255
256 =item C<--version> the version of the distribution
257
258 =back
259
260 =item C<-h>, C<-H>, C<--help>, C<--man>, C<-?>
261
262 Output a help message and exit.
263
264 =item C<--inject>
265
266 Inject the local distributions into the local repository.
267
268 =over 4
269
270 =item C<-v>, C<--verbose>
271
272 =back
273
274 =item C<--mirror>
275
276 Update the local MiniCPAN by downloading the latest modules from the
277 public CPAN (or the CPAN-like repo specified in the C<remote> config.
278 C<--mirror> uses
279
280 =over 4
281
282 =item C<-l>, C<--local>
283
284 =item C<-r>, C<--remote>
285
286 =item C<-v>, C<--verbose>
287
288 =back
289
290 =item C<--update>
291
292 This runs C<--mirror> then C<--inject>.
293
294 =item C<-V>, C<--version>
295
296 Output the version of B<mcpani> and exit.
297
298 =back
299
300 =head1 AUTHOR
301
302 Shawn Sorichetti C<< <[email protected]> >>
303
304 =head1 SOURCE AVAILABILITY
305
306 The main repository is on GitHub:
307
308 https://github.com/briandfoy/cpan-mini-inject
309
310 There are also backup repositories on several other services:
311
312 https://bitbucket.org/briandfoy/cpan-mini-inject
313 https://codeberg.org/briandfoy/cpan-mini-inject
314 https://gitlab.com/briandfoy/cpan-mini-inject
315
316 =head1 COPYRIGHT & LICENSE
317
318 Copyright 2004 Shawn Sorichetti, All Rights Reserved.
319
320 This program is free software; you can redistribute it and/or modify it
321 under the same terms as Perl itself.
322
323 =cut