Changeset 575 for trunk/tiny-import.pl


Ignore:
Timestamp:
12/31/13 15:36:27 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Add -g option to tiny-import.pl to allow import of flatfile records to
different groups. Note that the final group for any given record
depends on the parent zone(s) that it's in; new zones will be place
in the specified group but records belonging to existing zones will
effectively be in whatever group their containing zone is in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tiny-import.pl

    r543 r575  
    3939        conv    => 0,
    4040        trial   => 0,
    41         legacy  => 0,
     41        legacy  => 0,
     42        group   => 1,
    4243        );
     44my $gnum = '';
    4345# Handle some command-line arguments
    4446while ($ARGV[0] =~ /^-/) {
    4547  my $arg = shift @ARGV;
    46   usage() if $arg !~ /^-[rclt]+$/;
     48  usage() if $arg !~ /^-(?:[rclt]+|g\d*)$/;
    4749  # -r  rewrite imported files to comment imported records
    4850  # -c  coerce/downconvert A+PTR = records to PTR
    4951  # -l  swallow A+PTR as-is
    5052  # -t  trial mode;  don't commit to DB or actually rewrite flatfile (disables -r)
     53  # -g  import to specified group (name or ID) instead of group 1
    5154  $arg =~ s/^-//;
    52   my @tmp = split //, $arg;
    53   foreach (@tmp) {
    54     $importcfg{rw} = 1 if $_ eq 'r';
    55     $importcfg{conv} = 1 if $_ eq 'c';
    56     $importcfg{legacy} = 1 if $_ eq 'l';
    57     $importcfg{trial} = 1 if $_ eq 't';
    58   }
     55# for Reasons (none clear), $arg is undefined yet defined, but only when number characters are involved.  Ebbeh?
     56no warnings qw(uninitialized);
     57  if ($arg =~ /^g/) {
     58    if ($arg eq 'g') {
     59      $importcfg{group} = shift @ARGV;
     60    } else {
     61      $arg =~ s/^g//;
     62      $importcfg{group} = $arg;
     63    }
     64  } else {
     65    my @tmp = split //, $arg;
     66    foreach (@tmp) {
     67      $importcfg{rw} = 1 if $_ eq 'r';
     68      $importcfg{conv} = 1 if $_ eq 'c';
     69      $importcfg{legacy} = 1 if $_ eq 'l';
     70      $importcfg{trial} = 1 if $_ eq 't';
     71    }
     72  }
     73  use warnings qw(uninitialized);
    5974}
    6075$importcfg{rw} = 0 if $importcfg{trial};
    6176
     77# allow group names
     78if ($importcfg{group} =~ /^\d+$/) {
     79  $importcfg{groupname} = $dnsdb->groupName($importcfg{group});
     80} else {
     81  $importcfg{groupname} = $importcfg{group};
     82  $importcfg{group} = $dnsdb->groupID($importcfg{groupname});
     83}
     84
     85die usage() if $importcfg{group} !~ /^\d+$/;
     86
    6287sub usage {
    63   die q(usage:  tiny-import.pl [-r] [-c] datafile1 datafile2 ... datafileN ...
     88  die q(usage:  tiny-import.pl [-rclt] [-gnn] [-g name] datafile1 datafile2 ... datafileN ...
    6489        -r  Rewrite all specified data files with a warning header indicating the
    6590            records are now managed by web, and commenting out all imported records.
     
    7297        -l  (for "legacy")  Force import of A+PTR records as-is.  Mutually exclusive
    7398            with -c.  -l takes precedence as -c is lossy.
     99        -gnnn or -g nnn or -g name
     100            Import new zones into this group (group name or ID accepted) instead of
     101            the root/default group 1
    74102        -t  Trial run mode;  spits out records that would be left unimported.
    75103            Disables -r if set.
     
    514542      if ($zone =~ /\.arpa$/) {
    515543        ($code,$msg) = DNSDB::_zone2cidr($zone);
    516         $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?,1,1,?)",
    517                 undef, ($msg, $loc));
     544        $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?,?,1,?)",
     545                undef, ($msg, $importcfg{group}, $loc));
    518546        my ($rdns) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
    519547        my $newttl;
     
    523551                $loc, $stamp, $expires, $stampactive);
    524552      } else {
    525         $dbh->do("INSERT INTO domains (domain,group_id,status,default_location) VALUES (?,1,1,?)",
    526                 undef, ($zone, $loc));
     553        $dbh->do("INSERT INTO domains (domain,group_id,status,default_location) VALUES (?,?,1,?)",
     554                undef, ($zone, $importcfg{group}, $loc));
    527555        my ($domid) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')");
    528556        my $newttl;
Note: See TracChangeset for help on using the changeset viewer.