pf-tools commit: r683 [ccaillet-guest] - in /trunk: debian/changelog sbin/fix_hosts
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Tue Nov 25 11:59:21 UTC 2008
Author: ccaillet-guest
Date: Tue Nov 25 11:59:21 2008
New Revision: 683
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=683
Log:
Adding the tool fix_hosts for fixing /etc/hosts file due to dhcp install
which not modified the target /etc/hosts
Added:
trunk/sbin/fix_hosts (with props)
Modified:
trunk/debian/changelog
Modified: trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/trunk/debian/changelog?rev=683&op=diff
==============================================================================
--- trunk/debian/changelog (original)
+++ trunk/debian/changelog Tue Nov 25 11:59:21 2008
@@ -21,8 +21,10 @@
options defined in cmdline into private-network definitions
* Avoid a potential error returned by mk_grubopt when cmdline not defined
into private-network for the specified hostname
-
- -- Christophe Caillet <quadchris at free.fr> Tue, 18 Nov 2008 12:33:17 +0100
+ * Adding the tool fix_hosts for fixing /etc/hosts file due to dhcp install
+ which not modified the target /etc/hosts
+
+ -- Christophe Caillet <quadchris at free.fr> Tue, 25 Nov 2008 12:57:41 +0100
pf-tools (0.33.1-1) unstable; urgency=low
Added: trunk/sbin/fix_hosts
URL: http://svn.debian.org/wsvn/pf-tools/trunk/sbin/fix_hosts?rev=683&op=file
==============================================================================
--- trunk/sbin/fix_hosts (added)
+++ trunk/sbin/fix_hosts Tue Nov 25 11:59:21 2008
@@ -1,0 +1,147 @@
+#!/usr/bin/perl
+##
+## $Id$
+##
+## Copyright (C) 2007-2008 Christophe Caillet <quadchris at free.fr>
+## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
+## Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License
+## as published by the Free Software Foundation; either version 2
+## of the License, or (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+##
+
+use strict;
+use warnings;
+
+use Sys::Hostname ;
+use Digest::MD5;
+use PFTools::Conf ;
+use PFTools::Net;
+use PFTools::Update;
+use File::Compare ;
+use File::Copy ;
+use Getopt::Long qw( :config ignore_case_always bundling );
+
+my $program = $0;
+$program =~ s%.*/%%; # cheap basename
+
+my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
+
+my $HOSTS_CFG = "/etc/hosts" ;
+my $HOSTNAME = hostname ;
+my $DEST = "-" ;
+my $NET = "GLOBAL:private-network" ;
+my $HELP = 0 ;
+my $DEBUG = 0 ;
+my $VERBOSE = 0 ;
+
+sub Display_usage () {
+print STDERR << "# ENDHELP";
+ $program - version $version
+
+Usage: $0 [options]
+ -h --help: print help and exit
+ -v --verbose: be more verbose
+ -s --src source for hosts configuration (default: /etc/hosts)
+ -d --dest destination for fixed information (default: /etc/hosts)
+ --host hostname on which hosts configuration applied
+ -n --net Possiblitiy for defining an alternate PATH for private-network file (default GLOBAL:private-network)
+# ENDHELP
+}
+
+
+sub Fix_hosts ($$$) {
+ my ( $hostname, $ip_systeme, $dst ) = @_ ;
+
+ unless ( open ( HOSTS, $HOSTS_CFG ) ) {
+ warn "Unable top open ".$HOSTS_CFG."\n" ;
+ return 0 ;
+ }
+ my @tmp_hosts = <HOSTS> ;
+ foreach ( @tmp_hosts ) {
+ chomp ;
+ next if ( ! /$hostname/ ) ;
+ s/^127.0.([\d]{1,3}\.[\d]{1,3})/$ip_systeme/ ;
+ }
+
+ if ( $dst eq '-' ) {
+ foreach ( @tmp_hosts ) {
+ print $_."\n" ;
+ }
+ return 1 ;
+ }
+ else {
+ unless ( open ( TMPDST, ">/tmp/etc_hosts" ) ) {
+ warn "Unable to open temporary destination file /tmp/etc_hosts\n" ;
+ return 0 ;
+ }
+ foreach ( @tmp_hosts ) {
+ print TMPDST $_."\n" ;
+ }
+ close ( TMPDST ) ;
+ if ( compare ( '/tmp/etc_hosts', $dst ) ) {
+ return move ( '/tmp/menulst', $dst) ;
+ } else {
+ if ( $DEBUG ) {
+ warn "No need to move /tmp/etc_hosts to ".$dst." they are equals\n" ;
+ warn "Unlinking source file /tmp/etc_hosts\n" ;
+ }
+ if ( ! unlink ( '/tmp/etc_hosts' ) ) {
+ warn "Unable to unlink source file /tmp/etc_hosts\n" ;
+ warn "Please clean it manually\n" ;
+ }
+ }
+ return 1 ;
+ }
+}
+
+##### MAIN
+GetOptions(
+ 'src|s=s' => \$HOSTS_CFG,
+ 'dst|d=s' => \$DEST,
+ 'host=s' => \$HOSTNAME,
+ 'net|n=s' => \$NET,
+ 'debug' => \$DEBUG,
+ 'help|h' => \$HELP,
+ 'verbose|v' => \$VERBOSE
+) or die "GetOptions error, try --help: $!\n";
+
+if ( $HELP ) {
+ Display_usage () ;
+ exit 0 ;
+}
+elsif ( ! -e $HOSTS_CFG ) {
+ die "Unexistant hosts configuration ".$HOSTS_CFG."\n" ;
+}
+elsif ( -z $HOSTS_CFG ) {
+ die "Empty configuration file for hosts ".$HOSTS_CFG."\n" ;
+}
+
+$DEST = "-" if ( $DEBUG ) ;
+$VERBOSE = 1 if ( $DEBUG ) ;
+
+my $NETWORK = Init_lib_net ( Get_source ( $NET ) ) ;
+my ( $IF_SYS, $MAC ) = Get_Dhcp_Infos ( $NETWORK, $HOSTNAME ) ;
+my $subst = {} ;
+Init_SUBST ( $subst, $HOSTNAME, 'private' ) ;
+my $IF_LIST = $NETWORK->{'SERVERS'}->{'BY_NAME'}->{$subst->{'HOSTTYPE'}}->{'SRVLIST'}->{$HOSTNAME}->{'ifup'} ;
+my $VLAN = '' ;
+foreach my $if ( keys %{$IF_LIST} ) {
+ $VLAN = $if if ( $IF_LIST->{$if} eq $IF_SYS ) ;
+}
+my $IP_SYS = $NETWORK->{'SERVERS'}->{'BY_NAME'}->{$subst->{'HOSTTYPE'}}->{'SRVLIST'}->{$HOSTNAME}->{'zone'}->{$VLAN}->{'FIELD'} ;
+if ( ! Fix_hosts ( $HOSTNAME, $IP_SYS, $DEST ) ) {
+ die "Unable to fix file ".$HOSTS_CFG."\n" ;
+}
+
Propchange: trunk/sbin/fix_hosts
------------------------------------------------------------------------------
svn:executable = *
Propchange: trunk/sbin/fix_hosts
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Tue Nov 25 11:59:21 2008
@@ -1,0 +1,2 @@
+Id
+Revision
More information about the pf-tools-commits
mailing list