sbin/zone-rm
changeset 131 d8fa60488868
parent 113 30bd047cd057
child 150 3db363880766
equal deleted inserted replaced
130:5578cb7933c1 131:d8fa60488868
       
     1 #!/usr/bin/perl 
       
     2 
       
     3 use v5.10;
       
     4 use warnings;
       
     5 use strict;
       
     6 use File::Path;
       
     7 use DNStools::Config qw(get_config);
       
     8 use Net::LibIDN qw(:all);
       
     9 use Pod::Usage;
       
    10 use Getopt::Long;
       
    11 
       
    12 my $CHARSET = "UTF-8";
       
    13 
       
    14 my %cf = get_config();
       
    15 
       
    16 my $opt_interactive = 0;
       
    17 
       
    18 MAIN: {
       
    19 
       
    20     GetOptions(
       
    21         "i|interactive!" => \$opt_interactive,
       
    22         "h|help"         => sub { pod2usage(-exit => 0, -verbose => 1) },
       
    23         "m|man"          => sub {
       
    24             pod2usage(
       
    25                 -exit      => 0,
       
    26                 -verbose   => 2,
       
    27                 # "system('perldoc -V &>/dev/null')" appears shorter, but may not
       
    28                 # do what you expect ( it still returns 0 on debian squeeze with
       
    29                 # dash as system shell even if cannot find the command in $PATH)
       
    30                 -noperldoc => system('perldoc -V >/dev/null 2>&1')
       
    31             );
       
    32         },
       
    33       )
       
    34       and @ARGV
       
    35       or pod2usage;
       
    36 
       
    37     for my $utf8zone (@ARGV) {
       
    38         my $zone = idn_to_ascii($utf8zone, $CHARSET);
       
    39 
       
    40         if (not(-d "$cf{master_dir}/$zone" or -f "$cf{zone_conf_dir}/$zone")) {
       
    41             say "$utf8zone ($zone): nothing found";
       
    42             next;
       
    43         }
       
    44 
       
    45         if ($opt_interactive) {
       
    46             print "Remove $utf8zone ($zone)? [y/n]: ";
       
    47             chomp($_ = <STDIN>);
       
    48             next if not /^y(?:es)?$/i;
       
    49         }
       
    50 
       
    51         rmtree("$cf{master_dir}/$zone", "$cf{zone_conf_dir}/$zone",
       
    52             { verbose => 1 });
       
    53 
       
    54     }
       
    55 }
       
    56 
       
    57 __END__
       
    58 
       
    59 =head1 NAME
       
    60 
       
    61     zone-rm - remove a zone
       
    62 
       
    63 =head1 SYNOPSIS
       
    64 
       
    65     zone-rm [-i|--interactive] zone...
       
    66 
       
    67     zone-rm [-h|--help]
       
    68     zone-rm [-m|--man]
       
    69 
       
    70 =head1 DESCRIPTION
       
    71 
       
    72 This removes the specified zone(s) from the configured directories.
       
    73 
       
    74 =head1 OPTIONS
       
    75 
       
    76 The standard B<-h>, B<--help>, B<-m>, and B<--man> options are
       
    77 understood.
       
    78 
       
    79 =over
       
    80 
       
    81 =item B<-i>|B<--interactive>
       
    82 
       
    83 Ask for confirmation. (default: off)
       
    84 
       
    85 =cut