[Fai-commit] r5992 - in branches/stable/3.4: bin debian

Michael Prokop mika at alioth.debian.org
Tue Aug 17 12:54:47 UTC 2010


Author: mika
Date: 2010-08-17 12:54:42 +0000 (Tue, 17 Aug 2010)
New Revision: 5992

Modified:
   branches/stable/3.4/bin/dhcp-edit
   branches/stable/3.4/debian/changelog
Log:
add $modified, add more messages, fix code for adding a host


Conflicts:

	debian/changelog

Signed-off-by: Michael Prokop <mika at grml.org>

Modified: branches/stable/3.4/bin/dhcp-edit
===================================================================
--- branches/stable/3.4/bin/dhcp-edit	2010-08-17 12:54:38 UTC (rev 5991)
+++ branches/stable/3.4/bin/dhcp-edit	2010-08-17 12:54:42 UTC (rev 5992)
@@ -19,9 +19,10 @@
 # TODO
 # -q quiet: do not print error if host/mac entry not found, exit code 0
 
-$version="Version 1.1, 24-june-2010";
+$version="Version 1.2, 6-july-2010";
 $dhcpdconf="/etc/dhcp3/dhcpd.conf";
 
+$modified=0; # 1 if dhcpd.conf was modified
 our ($opt_p,$opt_d,$opt_h,$opt_n,$opt_r);
 
 use Pod::Usage;
@@ -38,17 +39,16 @@
 if ($opt_r) {
 
   $mac=$hostname;
-  # create emty entry, remove entry
-  $found=0;
+  # create empty entry, remove entry
 
   # set flag if an entry was found. print warning if entry not found
   foreach (@dhcpd) {
     next if /^\s*#/;  # do not change comments
-    do {$_="XXX ENTRY DELETED XXX\n";$found++} if m/host\s+$hostname\b.+hardware\s+ethernet.+;/;
-    do {$_="XXX ENTRY DELETED XXX\n";$found++} if m/host\s+.+hardware\s+ethernet\s+$mac[\s+;]/i;
+    do {$_="XXX ENTRY DELETED XXX\n";$modified++} if m/host\s+$hostname\b.+hardware\s+ethernet.+;/;
+    do {$_="XXX ENTRY DELETED XXX\n";$modified++} if m/host\s+.+hardware\s+ethernet\s+$mac[\s+;]/i;
   }
-  merror(6,"Entry $hostname can not be removed. Not found.\n") unless $found;
-  print "$found entry/entries removed.\n" if $found;
+  merror(6,"Entry $hostname can not be removed. Not found.\n") unless $modified;
+  print "$modified entry/entries removed.\n" if $modified;
 
 } else {
 
@@ -67,13 +67,7 @@
 merror(3,"Terminated. $0 can only be run as root.") unless ($< == 0);
 add_entry($hostname,$ip) unless $opt_r;
 write_dhcpd();
-do {
-  if ($opt_d) {
-    print "DRY RUN. Did not restart dhcp daemon.";
-    exit 0;
-  }
-  print qx#/etc/init.d/dhcp3-server restart#
-} unless $opt_n;
+restart_dhcpd();
 
 exit 0;
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -99,11 +93,21 @@
   my ($hostname,$ip) = @_;
   $ip=$hostname unless $ip;
 
-  # add new entry before line matching $opt_n
+  # if -p was not given
+  unless (defined $opt_p) {
+    $modified=1;
+    push @dhcpd, "host $hostname {hardware ethernet $mac;fixed-address $ip;}\n";
+    print "Entry added: host $hostname {hardware ethernet $mac;fixed-address $ip;}\n" if $modified;
+    return;
+  }
+
+  # add new entry before line matching $opt_p
+  # if $opt_p matches multiple times, also the new entry is added multiple times
   foreach (@dhcpd) {
     if ($_ =~ /$opt_p/o) {
       push @new, "host $hostname {hardware ethernet $mac;fixed-address $ip;}\n";
       print "Entry added: host $hostname {hardware ethernet $mac;fixed-address $ip;}\n";
+      $modified=1;
     }
     push @new,$_;
   }
@@ -117,6 +121,11 @@
     return;
   }
 
+  unless ($modified) {
+    print "Nothing changed.";
+    return;
+  }
+
   @dhcpd = grep(!/^XXX ENTRY DELETED XXX\n$/, @dhcpd);
 #  print @dhcpd;
   open(DHCP," >$dhcpdconf") || die "Can't write $dhcpdconf. $!\n";
@@ -124,7 +133,27 @@
   close(DHCP);
 }
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+sub restart_dhcpd {
 
+  if ($opt_d) {
+    print "DRY RUN. Did not restart dhcp daemon.\n";
+  }
+  if ($opt_n) {
+    print "Did not restart dhcp daemon.\n";
+  }
+  unless ($modified) {
+    print "No modifications.\n";
+  }
+
+  if ($opt_d || $opt_n || $modified==0) {
+    print "Did not restart dhcp daemon.\n";
+    return;
+  }
+
+  print qx#/etc/init.d/dhcp3-server restart#
+}
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
 __END__
 
 =head1 NAME

Modified: branches/stable/3.4/debian/changelog
===================================================================
--- branches/stable/3.4/debian/changelog	2010-08-17 12:54:38 UTC (rev 5991)
+++ branches/stable/3.4/debian/changelog	2010-08-17 12:54:42 UTC (rev 5992)
@@ -2,6 +2,8 @@
 
   [ Thomas Lange ]
   * dhcp-edit: new command that adds or removes entries to/from dhcpd.conf
+    add $modified, add more messages, fix code for adding a host
+  * make-fai-nfsroot.conf: set NFSROOT_HOOKS by default
   * make-fai-nfsroot: fix typo
   * mkramdisk: use exit in main routine (closes: #583289)
   * ainsl: exit with 0 if line already exists in the file




More information about the Fai-commit mailing list