summaryrefslogtreecommitdiffstats
path: root/bin/editdistrib
blob: 1e9203bc2739bb905230c145005e27afdd6a18a3 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
use MDV::Distribconf::Build;
use Text::ParseWords;

Getopt::Long::Configure("pass_through");

GetOptions(
);

Getopt::Long::Configure("no_pass_through");

my %commandes = (
    addmedia => \&addmedia,
    setvalue => \&setvalue,
);

my $distribpath = shift(@ARGV);

my $distrib = MDV::Distribconf::Build->new(
    $distribpath
);

if (!$distrib->load()) {
    warn "cannot load distrib\n";
    $distrib->init();
}

if (@ARGV) {
    parse_cmd(@ARGV);
} else {
    # shellwords
    die "interactive command not yet implemented\n";
}
    
exit(dwrite());

sub dwrite {
    return (!(
        $distrib->write_mediacfg() &&
        $distrib->write_hdlists() &&
        $distrib->write_version() &&
        $distrib->write_productid()
));
}

sub parse_cmd {
    my ($cmd, @oth) = @_;

    if (! exists($commandes{$cmd})) {
        return 1;
    }

    @ARGV = @oth;
    
    my %parsed_options = ();
    my %options = (
        addmedia => {
            'n|name=s' => \$parsed_options{name},
            'arch|a=s' => \$parsed_options{arch},
            'rpms=s' => \$parsed_options{rpms},
            'srpms=s' => \$parsed_options{srpms},
            'debug_for=s' => \$parsed_options{debug_for},
        },
        setvalue => {
            'm|media=s' => \$parsed_options{media},
        }
    );

    GetOptions(
        %{$options{$cmd} || {}}
    );
    
    $commandes{$cmd}(\%parsed_options, @ARGV);
}

sub addmedia {
    my ($options, @argument) = @_;
    if (!$distrib->create_media($argument[0])) {
        warn "Cannot create media\n";
        return;
    }

    foreach my $setting (qw(name arch rpms srpms debug_for)) {
        $distrib->setvalue($argument[0], $setting, $options->{$setting})
            if ($options->{$setting});
    }    
}

sub setvalue {
    my ($options, @argument) = @_;
    $distrib->setvalue(
        $options->{media},
        @argument,
    );
}