summaryrefslogtreecommitdiffabout
path: root/slackbuilder
blob: 9ad2722a23aaebca5bc0b0dfe5c29e1ccade9e78 (plain)
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
# -*- perl -*-
use strict;
use warnings;
use Data::Dumper;
use Pod::Usage;
use Pod::Man;
use Getopt::Long qw(:config gnu_getopt no_ignore_case);
use File::Basename;
use File::Spec;
use Unix::Sysexits;
use SlackBuilder;
use SlackBuild::Request;
use Net::SBo;
use JSON;
use Try::Tiny;

use constant {
    EX_FAIL => 1
};

my $progname = basename($0);
my $progdescr = "Slackware package builder";

sub abend {
    my $code = shift;
    print STDERR "$progname: " if defined($progname);
    print STDERR "@_\n";
    exit $code;
}

sub error {
    my $msg = shift;
    local %_ = @_;
    print STDERR "$progname: " if defined($progname);
    print STDERR "$_{prefix}: " if defined($_{prefix});
            print STDERR "$msg\n"
}

my %sbargs;
GetOptions("h" => sub {
               pod2usage(-message => "$progname: $progdescr",
			 -exitstatus => EX_OK);
	   },
	   "help" => sub {
	       pod2usage(-exitstatus => EX_OK, -verbose => 2);
	   },
	   "usage" => sub {
	       pod2usage(-exitstatus => EX_OK, -verbose => 0);
	   },
	   "verbose|v+" => \$sbargs{verbose},
	   "image|i=s" => \$sbargs{image},
	   "rootdir|C=s" => \$sbargs{image}
    ) or exit(EX_USAGE);

abend(EX_USAGE, "bad number of arguments") unless @ARGV == 1;
my $reqname = shift @ARGV;
my $req = try {
    new SlackBuild::Request($reqname)
} catch {
    my $err = (split /\n/)[0];
    $err =~ s{\s+at .* line \d+\.$}{};
    abend(EX_NOINPUT, "$reqname: $err")
};

my $builder = new SlackBuilder(%sbargs);
$builder->run($req);
if ($builder->is_success) {
    if ($builder->output_files == 0) {
	print STDERR "Build exited successfully, but no output files were generated\n";
	exit EX_FAIL;
    }
    print "OK. File list:\n";
    foreach my $f ($builder->output_files) {
	print "$f\n";
    }
} else {
    print STDERR "ERROR: " . $builder->errno . "\n";
    foreach my $e ($builder->errors) {
	print STDERR "$e\n";
    }
}

Return to:

Send suggestions and report system problems to the System administrator.