-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregpkg
executable file
·505 lines (415 loc) · 14.9 KB
/
regpkg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
#!/usr/bin/perl
#
# SlackPack
# Copyright (C) 2006-2023 Georgi D. Sotirov, [email protected]
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# DESCRIPTION:
# Register package into the database
#
use strict;
use FindBin qw($RealBin);
use lib ("$RealBin/..");
use SlackPack;
use SlackPack::Arch;
use SlackPack::SoftSerie;
use SlackPack::Category;
use SlackPack::License;
use SlackPack::Package;
use SlackPack::Slackver;
use SlackPack::User;
use SlackPack::Vendor;
# Possible Slackware package extensions
use constant PKG_EXTS => 'tbz|tgz|tlz|txz';
# Possible Slackware package MIME types
use constant PKG_MIME => 'application\/x\-bzip2|application\/x\-gzip|application\/x\-lzma|application\/x\-xz';
my $slackver = $ARGV[0];
my $filepath = $ARGV[1];
sub parse_description {
my $filename = shift;
my $sname = shift;
my $desc = "";
my $line = 0;
if ( ! -e $filename ) {
return "File '$filename' not found!";
}
open(DESC_FILE, $filename);
while ( <DESC_FILE> ) {
$line++;
if ( $_ =~ /^$sname:/ && $line > 1 ) {
if ( $_ !~ /^$sname:[\s\t]*$/ && # empty lines with tag
$_ !~ /^$sname:[\s\t]*Package[dr][\s\t]*(by)?/ # signatures
)
{
# suppress tag, preceding and trailing spaces and line seprators
s/^$sname:[\s\t]*//;
s/^[\s\t]*//;
s/[\s\t]*$//;
chomp;
if ( $desc ne "" ) {
# If line starts with uppercase letter and the previous one was
# terminated with dot, colon or semicolon - consider new paragraph
if ( $_ =~ /^[^A-Za-z]*[A-Z]/ && $desc =~ /[\.\:\;]$/ ) {
$desc .= "\n";
}
else {
$desc .= " ";
}
}
$desc .= $_;
}
}
}
close(DESC_FILE);
# Only one space after dot, coma or semi-colon
$desc =~ s/[\s\t]{2,}/ /g;
return $desc;
}
sub proc_file {
my $filepath = shift;
my $slackver = shift;
my $pack;
my $old_pack;
my $desc_file;
my $answer;
my $secfix;
my $PKG_EXTS = PKG_EXTS;
$filepath =~ m/\/*([^\/]+)$/;
$pack->{filename} = $1;
printf "Processing package '%s'...\n", $pack->{filename};
# 2.1 parse file name: <name>-<version>-<architecture>-<build><author>.tbz|tgz|tlz|txz
$pack->{filename} =~ m/^([\_\.\-\+\d\w]+)\-(\d[\d\w\.]+)\-([\w\d_]+)\-(\d)(\w*)\.($PKG_EXTS)$/i;
$pack->{name} = $1;
$pack->{version} = $2;
my $pkg_arch = $3;
$pack->{build} = $4;
my $pkg_author = $5;
# 2.1.1 Search whether this package is registered before
$old_pack = SlackPack::Package->get_by_name($pack->{name});
if ( $old_pack && !defined $old_pack->{'error'} ) {
printf "Info: Package '%s-%s' for '%s' found in the database (id = %d).\n",
$old_pack->{name}, $old_pack->{version},
$old_pack->{slackver}{name}, $old_pack->{id};
printf "The following information could be reused:\n";
printf " Title : %s\n", $old_pack->{title};
printf " License : %s\n", $old_pack->{license}{name};
printf " URL : %s\n", $old_pack->{url};
printf " Vendor : %d - %s\n", $old_pack->{vendor}{id}, $old_pack->{vendor}{name};
printf " Description: %s\n", $old_pack->{description};
printf " Serie : %s - %s\n", $old_pack->{serie}{id}, $old_pack->{serie}{title};
printf " Category : %d - %s\n", $old_pack->{category}{id}, $old_pack->{category}{name};
do {
printf "Do you want to keep this information? [Y/n]: ";
$answer = <STDIN>;
chomp $answer;
$answer = $answer || "y";
}
while ( $answer !~ m/[yYnN]/ );
if ( uc($answer) eq "Y" ) {
$pack->{title} = $old_pack->{title};
$pack->{license} = $old_pack->{license};
$pack->{url} = $old_pack->{url};
$pack->{vendor} = $old_pack->{vendor};
$pack->{description} = $old_pack->{description};
$pack->{serie} = $old_pack->{serie};
$pack->{category} = $old_pack->{category};
}
}
else {
printf "Info: Package '%s' NOT found in the database. Will have to provide all information.\n",
$pack->{name};
}
if ( ! $pack->{releasedate} ) {
do {
printf "Please, enter vendor release date (YYYY-MM-DD): ";
$pack->{releasedate} = <STDIN>;
}
while ( $pack->{releasedate} !~ m/\d{4}\-\d{2}\-\d{2}/ );
}
if ( ! $pack->{title} ) {
do {
printf "Please, enter title: ";
$pack->{title} = <STDIN>;
}
while ( $pack->{title} !~ m/[a-zA-Z][_ \-\+a-zA-z0-9]/ );
chomp $pack->{title};
}
# 2.2 Parse description
if ( ! $pack->{description} ) {
$filepath =~ m/(.+)\.($PKG_EXTS)$/;
$desc_file = $1.".txt";
$pack->{description} = parse_description($desc_file, $pack->{name});
}
# 2.3 Determine software's license
if ( ! $pack->{license} ) {
my $licenses = SlackPack::License->get_all;
my %valid_ids = ();
my $sof_license;
printf "Please, select software's license:\n";
printf " %-9s %s\n", "Id", "Name";
for ( my $idx = 0; $idx < @$licenses; $idx++ ) {
$valid_ids{$licenses->[$idx]->{id}} = 1;
printf " %-9s %s\n", $licenses->[$idx]->{id}, $licenses->[$idx]->{name};
}
do {
printf "License id: ";
$sof_license = <STDIN>;
chomp $sof_license;
}
while ( $sof_license !~ m/[a-zA-Z0-9]+/ || ! $valid_ids{$sof_license} );
$pack->{license} = new SlackPack::License($sof_license);
if ( ! $pack->{license} || defined $pack->{'error'} ) {
printf STDERR "$0: Error: Undefined license '%s': %s\n", $sof_license, $pack->{'error'};
exit -11;
}
}
# 2.4 Determine package's architecture
$pack->{arch} = new SlackPack::Arch($pkg_arch);
if ( ! $pack->{arch} || defined $pack->{'error'} ) {
printf STDERR "$0: Error: Undefined architecture '%s': %s\n", $pkg_arch, $pack->{'error'};
exit -11;
}
# 2.5 Determine package's format
if ( $slackver eq "" ) {
my $slack_vers = SlackPack::Slackver->get_all_active;
my @valid_ids = ();
printf "Please, select Slackware's version:\n";
printf " Id\tName\n";
for ( my $idx = 0; $idx < @$slack_vers; $idx++ ) {
$valid_ids[$slack_vers->[$idx]->{id}] = 1;
printf " %s\t%s\n", $slack_vers->[$idx]->{id}, $slack_vers->[$idx]->{name};
}
do {
printf "Version id: ";
$slackver = <STDIN>;
chomp $slackver;
}
while ( $slackver !~ m/[0-9]+/ || ! $valid_ids[$slackver] );
}
$pack->{slackver} = new SlackPack::Slackver($slackver);
if ( !$pack->{slackver} || defined $pack->{'error'} ) {
printf STDERR "$0: Error: Undefined format '%s': %s\n", $slackver, $pack->{'error'};
exit -11;
}
# 2.6 Determine software's URL
if ( $pack->{url} eq "" ) {
do {
printf "Plese, enter software's URL (official site or download location): ";
$pack->{url} = <STDIN>;
chomp $pack->{url};
}
while ( $pack->{url} !~ m/^(ht|f)tp(s?)\:\/\/([a-zA-Z0-9][\-\+_a-zA-Z0-9]+)(\.[a-zA-Z0-9][\-\+_a-zA-Z0-9]+)?\.([a-zA-Z]{3,4})/ );
chomp $pack->{url};
}
# 2.7 Determine software's vendor
if ( ! $pack->{vendor} ) {
my $vendors = SlackPack::Vendor->get_all;
my @valid_ids = ();
my $sof_vendor;
printf "Please, select software's vendor:\n";
printf " Id\tName\n";
for ( my $idx = 0; $idx < @$vendors; $idx++ ) {
$valid_ids[$vendors->[$idx]->{id}] = 1;
printf " %s\t%s\n", $vendors->[$idx]->{id}, $vendors->[$idx]->{name};
}
do {
printf "Vendor id: ";
$sof_vendor = <STDIN>;
chomp $sof_vendor;
}
while ( $sof_vendor !~ m/[0-9]+/ || ! $valid_ids[$sof_vendor] );
$pack->{vendor} = new SlackPack::Vendor($sof_vendor);
if ( ! $pack->{vendor} || defined $pack->{'error'} ) {
printf STDERR "$0: Error: Undefined vendor '%s': %s\n", $sof_vendor, $pack->{'error'};
exit -11;
}
}
# 2.8 Determine package's software serie
if ( ! $pack->{serie} ) {
my $series = SlackPack::SoftSerie->get_all;
my @valid_ids = ();
my $pkg_serie;
printf "Please, select software's serie:\n";
printf " Id\tTitle\n";
for ( my $idx = 0; $idx < @$series; $idx++ ) {
$valid_ids[$series->[$idx]->{id}] = 1;
printf " %s\t%s\n", $series->[$idx]->{id}, $series->[$idx]->{title};
}
do {
printf "Serie id: ";
$pkg_serie = <STDIN>;
chomp $pkg_serie;
}
while ( $pkg_serie !~ m/[a-z]+/ || ! $valid_ids[$pkg_serie] );
$pack->{serie} = new SlackPack::SoftSerie($pkg_serie);
if ( ! $pack->{serie} || defined $pack->{'error'} ) {
printf STDERR "$0: Error: Undefined serie '%s': %s\n", $pkg_serie, $pack->{'error'};
exit -11;
}
}
# 2.9 Determine package's category
if ( ! $pack->{category} ) {
my $categories = SlackPack::Category->get_all;
my @valid_ids = ();
my $pkg_category;
printf "Please, select software's category:\n";
printf " Id\tName\n";
for ( my $idx = 0; $idx < @$categories; $idx++ ) {
$valid_ids[$categories->[$idx]->{id}] = 1;
printf " %s\t%s\n", $categories->[$idx]->{id}, $categories->[$idx]->{name};
}
do {
printf "Category id: ";
$pkg_category = <STDIN>;
chomp $pkg_category;
}
while ( $pkg_category !~ m/[0-9]+/ || ! $valid_ids[$pkg_category] );
$pack->{category} = new SlackPack::Category($pkg_category);
if ( ! $pack->{category} || defined $pack->{'error'} ) {
printf STDERR "$0: Error: Undefined category '%s': %s\n", $pkg_category, $pack->{'error'};
exit -11;
}
}
# 2.10 List package contents
print "Listing contents... ";
$pack->{contents} = qx/tar tavf $filepath/;
print "DONE.\n";
# 2.11 Determine the presence of build script
my $sb_file = "usr\/src\/slackbuilds\/".$pack->{name}."-".$pack->{version}."\/".$pack->{name}.".SlackBuild";
$pack->{slackbuild} = grep(/$sb_file/, split(/\n/, $pack->{contents})) ? 'yes' : 'no';
# 2.12 Determination of file prameters
$pack->{filesize} = qx/stat --printf %s $filepath/;
if ( -e "${filepath}.md5" ) {
$pack->{filemd5} = qx/cat ${filepath}.md5 | awk '{ print \$1}'/;
}
else {
printf "Info: File '${filepath}.md5' does not exists. Calculating MD5 sum.\n";
$pack->{filemd5} = qx/md5sum ${filepath} | awk '{print \$1}'/;
}
chomp $pack->{filemd5};
$pack->{filesign} = qx/cat ${filepath}.asc/;
chomp $pack->{filesign};
$pack->{filedate} = qx/stat --printf %y $filepath/;
$pack->{filedate} =~ m/\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/;
$pack->{filedate} = $&;
# 2.13 Determine of the author
$pack->{author} = new SlackPack::User($pkg_author);
if ( !$pack->{author} || defined $pack->{'error'} ) {
print STDERR "$0: Error: Undefined author '%s': %s\n", $pkg_author, $pack->{'error'};
exit -12;
}
# 2.14 Security fix or not?
if ( ! $pack->{security_fix} ) {
do {
print "\nIs this package security fix (y/N)? ";
$secfix = <STDIN>;
chomp $secfix;
$secfix = $secfix || 'N';
}
while ( $secfix !~ m/[yYnN]/ );
$pack->{security_fix} = (uc($secfix) eq 'Y')?1:0;
}
# The package is put in wait status until verified
$pack->{status} = 'wait';
print "\nData gathered for the package:\n";
printf "Security fix: %s\n", ($pack->{security_fix})?"Yes":"No";
printf "Name : %s\n", $pack->{name};
printf "Title : %s\n", $pack->{title};
printf "Version : %s\n", $pack->{version};
printf "Description : %s\n", $pack->{description};
printf "Build : %s\n", $pack->{build};
printf "License : %s\n", $pack->{license}{name};
printf "Architecture: %s\n", $pack->{arch}{name};
printf "Format : %s\n", $pack->{slackver}{name};
printf "URL : %s\n", $pack->{url};
printf "Vendor : %d - %s\n", $pack->{vendor}{id}, $pack->{vendor}{name};
printf "Serie : %s - %s\n", $pack->{serie}{id}, $pack->{serie}{desc};
printf "Category : %d - %s\n", $pack->{category}{id}, $pack->{category}{name};
printf "SlackBuild : %s\n", $pack->{slackbuild};
printf "Filename : %s\n", $pack->{filename};
printf "File size : %s\n", $pack->{filesize};
printf "File MD5 : %s\n", $pack->{filemd5};
printf "File sign : %s\n", $pack->{filesign};
printf "File date : %s\n", $pack->{filedate};
printf "Author : %s, %s (%d:%s)\n", $pack->{author}->{name},
$pack->{author}->{firstname},
$pack->{author}->{id},
$pack->{author}->{pkgsid};
do {
print "\nConfirm package registration (Y/n)? ";
$answer = <STDIN>;
chomp $answer;
$answer = $answer || "y";
}
while ( $answer !~ m/[yYnN]/ );
# 3. Registration into the database
if ( uc($answer) eq "Y" )
{
$pack = SlackPack::Package->add($pack);
if ( $pack && !defined $pack->{'error'} )
{
printf "Package '%s' registered successfully with id %d.\n", $pack->{filename}, $pack->{id};
printf "Loading dependencies for package '%s' with id %d... ", $pack->{filename}, $pack->{id};
$pack->load_deps();
print "DONE.\n";
}
else {
printf "Package '%s' was not registered because of error.\n", $pack->{filename};
}
}
else {
printf "Package '%s' was not registered, because the user cancelled the operation.\n", $pack->{filename};
}
}
###########################################################################################
# Main program
#
if ( $slackver !~ /^\d+$/ ) {
$filepath = $slackver;
$slackver = "";
}
if ( $filepath eq "" ) {
print "Usage: $0 [slackware version] filename\n";
exit 0;
}
# 1. Check the file
# 1.1 Check the file extension
$filepath =~ m/\.(\w+)$/;
my $file_ext = $1;
my $PKG_EXTS = PKG_EXTS;
if ( $file_ext !~ m/($PKG_EXTS)/ ) {
print STDERR "$0: Error: The file '$filepath' does NOT seems to be a Slackware package!\n";
exit -1;
}
# 1.2 Check the file MIME type
chomp(my $file_mime = qx/file --brief --mime-type $filepath/);
my $PKG_MIME = PKG_MIME;
if ( $file_mime !~ m/($PKG_MIME)/ ) {
print STDERR "$0: Error: The file '$filepath' is NOT a bzip2, lzma, gzip or xz archive!\n";
exit -2;
}
# 2. Process the file - gather information and register package
proc_file $filepath, $slackver;
1;
__END__
=head1 NAME
SlackPack regpkg - Package registration tool
=head1 SYNOPSIS
addpkg <name>-<version>-<arch>-<build><inn>.tgz
=head1 DESCRIPTION
This utility allow for easy package registration. The only parameter
the program takes is the file name of the newly build package
=back