summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/editdistrib99
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/editdistrib b/bin/editdistrib
new file mode 100755
index 0000000..1e9203b
--- /dev/null
+++ b/bin/editdistrib
@@ -0,0 +1,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,
+ );
+}