pf-tools/pf-tools: 7 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Sep 15 13:22:26 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/d97d2eedf98f
changeset: 763:d97d2eedf98f
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 12:21:31 2010 +0200
description:
Adding Config module for handling correctly updatefile directives
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/fe8ce4e342f5
changeset: 764:fe8ce4e342f5
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 17:27:47 2010 +0200
description:
Commit due to merging with central repository
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/68e57ba00916
changeset: 765:68e57ba00916
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 18:44:54 2010 +0200
description:
Coding style for sbin/mk_resolvconf
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/cf85ec5275ee
changeset: 766:cf85ec5275ee
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 18:55:09 2010 +0200
description:
Coding style for sbin/mk_sitezone
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/2f36bb1c1075
changeset: 767:2f36bb1c1075
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 19:01:39 2010 +0200
description:
Cosmetic on sbin/update-config
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/787bf5038f48
changeset: 768:787bf5038f48
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 19:13:24 2010 +0200
description:
Coding style options for sbin/mk_sourceslist
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/746c549ca865
changeset: 769:746c549ca865
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 19:37:06 2010 +0200
description:
Coding style and cosmetics
diffstat:
8 files changed, 118 insertions(+), 15 deletions(-)
filters/filter_privateresolve | 8 +-
lib/PFTools/Conf/Config.pm | 114 +++++++++++++++++++++++++++++++++++++++++
sbin/mk_interfaces | 1
sbin/mk_pxelinuxcfg | 2
sbin/mk_resolvconf | 1
sbin/mk_sitezone | 2
sbin/mk_sourceslist | 3 -
sbin/update-config | 2
diffs (1400 lines):
diff -r f0075a070f36 -r 746c549ca865 filters/filter_privateresolve
--- a/filters/filter_privateresolve Tue Sep 14 10:33:15 2010 +0200
+++ b/filters/filter_privateresolve Tue Sep 14 19:37:06 2010 +0200
@@ -108,22 +108,20 @@
unless ( $options->{'site'} ) {
my $site = $PF_CONFIG->{'location'}->{'site'};
unless ($site) {
- my $site_list = Get_site_from_hostname( $options->{'hostname'},
- $GLOBAL_STRUCT );
+ my $site_list = Get_site_from_hostname(
+ $options->{'hostname'},
+ $GLOBAL_STRUCT
+ );
unless ($site_list) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname $options->{'hostname'}: hostname not defined"
- );
+ "Unknown hostname $options->{'hostname'}" );
}
if ( scalar @{$site_list} > 1 ) {
Abort( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname $options->{'hostname'}: hostname appeared in multiple sites: "
- . join( ',', @{$site_list} )
- . ".\nPlease relaunch this command with the right site" );
+ "Multiple sites for hostname $options->{'hostname'}" );
}
($site) = @{$site_list};
}
-
$options->{'site'} = $site;
}
diff -r f0075a070f36 -r 746c549ca865 lib/PFTools/Conf/Config.pm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/PFTools/Conf/Config.pm Tue Sep 14 19:37:06 2010 +0200
@@ -0,0 +1,228 @@
+package PFTools::Conf::Config;
+##
+## Copyright (C) 2010 Christophe Caillet <quadchris at free.fr>
+##
+## 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 English qw( -no_match_vars ); # Avoids regex performance penalty
+use Exporter;
+
+use PFTools::Logger;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+ Init_CONFIG_STRUCT
+ Add_config
+ Sort_actiongroup_prio
+);
+
+our @EXPORT_OK = qw();
+
+##########################
+# Constants
+
+my $CONFIG_STRUCT = {
+ '__sections_order' => [],
+ 'ACTIONGROUP' => {
+ '__actiongroups_order' => [
+ 'NONE'
+ ],
+ 'NONE' => {
+ 'priority' => 100,
+ },
+ },
+ 'DEPENDS' => {},
+};
+
+##########################
+# Vars
+
+##########################
+# Functions
+
+sub Init_CONFIG_STRUCT {
+ my ( $param ) = @_;
+
+ my $struct = $CONFIG_STRUCT;
+ $struct->{'__sections_order'} = $param->{'parsed'}->{'__sections_order'};
+ $struct->{'__hash_subst'} = $param->{'hash_subst'};
+ return $struct;
+}
+
+sub __Exists_deps {
+ my ( $dep, $parsed ) = @_;
+
+ return unless $dep or $parsed;
+ print "checking if dep exists\n";
+
+ return $parsed->{$dep};
+}
+
+sub __Same_actiongroup {
+ my ( $section1, $section2, $parsed ) = @_;
+
+ return unless $section1 or $section2 or $parsed;
+ my $actiongrp1 = $parsed->{$section1}->{'actiongroup'} || 'NONE';
+ my $actiongrp2 = $parsed->{$section2}->{'actiongroup'} || 'NONE';
+ my $same = 0;
+ $same++ if ( $actiongrp1 eq $actiongrp2 );
+ $same++ if (
+ ( $parsed->{$section1}->{'action'} eq 'actiongroup'
+ && $actiongrp2 eq 'NONE'
+ )
+ || ( $parsed->{$section2}->{'action'} eq 'actiongroup'
+ && $parsed->{$section1}->{'action'} eq 'actiongroup'
+ )
+ || ( $parsed->{$section2}->{'action'} eq 'actiongroup'
+ && $actiongrp1 eq 'NONE'
+ )
+ );
+
+# $same++ if ( $parsed->{$section}->{'actiongroup'})
+ return $same;
+}
+
+sub Sort_actiongroup_prio {
+ my ( $glob_cnf, $a, $b ) = @_;
+
+ my $prioa = $glob_cnf->{'ACTIONGROUP'}->{$a}->{'priority'};
+ my $priob = $glob_cnf->{'ACTIONGROUP'}->{$b}->{'priority'};
+ return $prioa <=> $priob;
+}
+
+sub Add_config {
+ my ( $param ) = @_;
+
+ # Checking mandatory parameter
+ foreach my $par ('config','sect_name','ref_sect', 'parsed') {
+ return unless $param->{$par};
+ }
+
+ my $glob_cnf = $param->{'config'};
+ my $name = $param->{'sect_name'};
+
+ my $actiongrp = $param->{'ref_sect'}->{'actiongroup'} || 'NONE';
+ $glob_cnf->{'ACTIONGROUP'}->{$actiongrp} = {}
+ if ( ! defined $glob_cnf->{'ACTIONGROUP'}->{$actiongrp} );
+ my $action_entry = $glob_cnf->{'ACTIONGROUP'}->{$actiongrp};
+ if ( $param->{'ref_sect'}->{'depends'} ) {
+ foreach my $dep ( split (/\s/, $param->{'ref_sect'}->{'depends'})) {
+ Abort ( $CODE->{'INVALID_VALUE'},
+ "Undefined depends $dep in section $name ",
+ Dumper $param->{'parsed'}
+ ) if( ! __Exists_deps ($dep, $param->{'parsed'}) );
+ Abort ( $CODE->{'INVALID_VALUE'},
+ "$dep and $name($actiongrp) are not on the same actiongroup"
+ ) if( ! __Same_actiongroup( $actiongrp, $dep, $param->{'parsed'}) );
+
+ }
+ }
+ if ($param->{'ref_sect'}->{'action'} eq 'actiongroup') {
+ if (
+ ! grep(
+ /^$name/,
+ @{$glob_cnf->{'ACTIONGROUP'}->{'__actiongroups_order'}}
+ )
+ ) {
+ push (
+ @{$glob_cnf->{'ACTIONGROUP'}->{'__actiongroups_order'}},
+ $name
+ );
+ }
+ $glob_cnf->{'ACTIONGROUP'}->{$name}->{'priority'} =
+ $param->{'ref_sect'}->{'priority'} || 200;
+ $glob_cnf->{'ACTIONGROUP'}->{$name}->{'__config'} =
+ $param->{'ref_sect'};
+ }
+ else {
+ push ( @{$action_entry->{'__order'}}, $name );
+ $action_entry->{$name} = $param->{'ref_sect'};
+ $action_entry->{$name}->{'__subst'}->{'DESTINATION'} = $name;
+ }
+
+ return $glob_cnf;
+}
+
+sub __Sort_depends_prio ($$) {
+ my ( $action, $section ) = @_;
+
+ my $prio = 0;
+
+ # First : authentication parts
+ return $prio if ( $section eq "/etc/passwd" );
+ $prio++;
+ return $prio if ( $section eq "/etc/group" );
+ $prio++;
+ return $prio if ( $section eq "/etc/shadow" );
+ $prio++;
+ return $prio if ( $section eq "/etc/gshadow" );
+ $prio++;
+
+ # Second : directory and mount points
+ return $prio if ( $action eq 'mkdir' );
+ $prio++;
+ return $prio if ( $action eq 'addmount' );
+ $prio++;
+
+ # Third : Packaging infra and packages
+ return $prio if ( $section =~ /^\/etc\/apt\// );
+ $prio++;
+ return $prio if ( $section eq "pf-tools" );
+ $prio++;
+ return $prio if ( $action eq "dpkg-purge" || $action eq "purgepkg" );
+ $prio++;
+ return $prio if ( $action eq "apt-get" || $action eq "installpkg" );
+ $prio++;
+
+ # Fourth : creations and adds for files and links
+ return $prio if ( $action eq 'createfile' );
+ $prio++;
+ return $prio if ( $action eq 'addfile' );
+ $prio++;
+ return $prio if ( $action eq 'addlink' );
+ $prio++;
+
+ # Fifth : removing files and dirs
+ return $prio if ( $action =~ /^remove/ );
+ $prio++;
+
+ # Last : other elements
+ return $prio;
+}
+
+sub Sort_config_sections ($$$) {
+ my ( $host_config, $a, $b ) = @_;
+
+ my $prioa = $host_config->{$a}->{'priority'} ||
+ __Sort_depends_prio( $host_config->{$a}->{'action'}, $a );
+ my $priob = $host_config->{$a}->{'priority'} ||
+ __Sort_depends_prio( $host_config->{$b}->{'action'}, $b );
+
+ if ( $prioa != $priob ) {
+ return $prioa <=> $priob;
+ }
+
+ # else {
+ # return $a cmp $b;
+ # }
+}
+
+1;
diff -r f0075a070f36 -r 746c549ca865 lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Tue Sep 14 10:33:15 2010 +0200
+++ b/lib/PFTools/Utils.pm Tue Sep 14 19:37:06 2010 +0200
@@ -25,6 +25,7 @@
use Exporter;
use File::Compare;
use File::Copy;
+use IO::File;
use Template::Tiny;
use PFTools::Conf;
@@ -229,6 +230,8 @@
);
my $preseed_md5 = Get_MD5SUM_for_preseedfile( $preseed, $pf_config );
my $tpl = Template::Tiny->new( TRIM => 1 );
+ my $cmdline = join( " ", Get_cmdline_from_hostprops($host_props) );
+ $cmdline =~ s/^\s*//;
my $pxe_subst = {
'iface' => $iface,
'mode' => $host_props->{'deployment'}->{'mode'} . '-installer',
@@ -239,7 +242,7 @@
'preseed_md5' => $preseed_md5,
'console' => $host_props->{'boot'}->{'console'},
'install_cmdline' => $host_props->{'boot'}->{'cmdline'},
- 'cmdline' => join( " ", Get_cmdline_from_hostprops($host_props) ),
+ 'cmdline' => $cmdline,
'kernel' => $host_props->{'boot'}->{'kernel'}
};
if ( $host_props->{'boot'}->{'initrd'} ) {
@@ -792,56 +795,48 @@
$pf_config )
= @_;
my $tmp_grub = [];
- my ($cmd_line);
my $host_props
= Get_host_config_from_CONFIG( $hostname, $global_config, $site );
- if ( !defined $host_props ) {
+ unless( $host_props ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to find hostname "
- . $hostname
- . " on site "
- . $site
- . " : no such host definition" );
+ "Unknown hostname $hostname on site $site" );
}
my $mode = $host_props->{'deployment'}->{'mode'};
- my ( $cmdline, $bond_cmdline ) = Get_cmdline_from_hostprops($host_props);
+ my $cmdline = join( " ", Get_cmdline_from_hostprops($host_props) );
+ $cmdline =~ s/^\s*//; # Removing trailing space
$grub_version = "" if ( $grub_version == 1 );
$grub_src = $pf_config->{$mode}->{ 'grub' . $grub_version }
if ( $grub_src eq '' );
- if ( !-e $grub_src ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unable to modify GRUB option(s) on file "
- . $grub_src
- . " : no such file or directory" );
+ my $src_hdl = IO::File->new( $grub_src );
+ unless( $src_hdl ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to open GRUB source $grub_src : $OS_ERROR" );
+ return;
}
-
- unless ( open( MENU, $grub_src ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable to open current file "
- . $grub_src
- . " for modifying GRUB option(s)" );
- return 0;
- }
- @{$tmp_grub} = <MENU>;
- close(MENU);
+ @{$tmp_grub} = <$src_hdl>;
+ $src_hdl->close();
foreach ( @{$tmp_grub} ) {
chomp;
next
if ( $grub_version == 2 && !/^GRUB_CMDLINE_LINUX_DEFAULT=".*"$/ );
next if ( $grub_version == 1 && !/^\# kopt=.*$/ );
- s/\"$/ $cmd_line\"/ if ( defined $cmd_line && !/\Q$cmd_line\E\"$/ );
+ s/\"$/ $cmdline\"/ if ( $cmdline && !/\Q$cmdline\E\"$/ );
}
my $tmp_dst = ( $dst eq "-" ) ? $dst : "/tmp/menulst";
- unless ( open( TMPDST, ">" . $tmp_dst ) ) {
+ my $dst_hdl = IO::File->new( ">$tmp_dst" );
+ unless( $dst_hdl ) {
Warn( $CODE->{'OPEN'},
- "Unable to open temporary destination file /tmp/menulst" );
- return 0;
+ "Unable to open tmp destination $tmp_dst : $OS_ERROR" );
+ return;
}
- print TMPDST join( "\n", @{$tmp_grub} );
- close(TMPDST);
+ unless( $dst_hdl->print( join( "\n", @{$tmp_grub} ) ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to write on tmp destination $tmp_dst : $OS_ERROR" );
+ }
+ $dst_hdl->close();
if ( $tmp_dst ne "-" ) {
if ( compare( $tmp_dst, $dst ) ) {
return move( $tmp_dst, $dst );
@@ -849,11 +844,11 @@
else {
if ( !unlink($tmp_dst) ) {
Warn( $CODE->{'UNLINK'},
- "Unable to unlink source file " . $tmp_dst );
+ "Unable to unlink tmp destination $tmp_dst : $OS_ERROR" );
}
- return 1;
}
}
+ return 1;
}
#
diff -r f0075a070f36 -r 746c549ca865 sbin/fix_hosts
--- a/sbin/fix_hosts Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/fix_hosts Tue Sep 14 19:37:06 2010 +0200
@@ -21,7 +21,6 @@
use strict;
use warnings;
-use Data::Dumper;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw( :config ignore_case_always bundling );
use IO::File;
@@ -60,8 +59,6 @@
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-#my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
-
###################################
# Funtions
@@ -84,10 +81,8 @@
##################################
### MAIN
-GetOptions(
- $options,
- @options_specs
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
if ($options->{'help'}) {
Do_help();
@@ -101,47 +96,36 @@
);
if ( !$PF_CONFIG->{'features'}->{$options->{'type'}} ) {
- print Dumper $PF_CONFIG;
Abort( $CODE->{'UNDEF_KEY'},
"Aborting because $options->{'type'} is not activated in PF-Tools" );
}
-if ( $options->{'site'} eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
my $site_list = Get_site_from_hostname(
$options->{'host'},
$GLOBAL_STRUCT
);
- if ( !defined $site_list ) {
+ unless( $site_list ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for undefined hostname "
- . $options->{'host'}
- );
+ "Unknown hostname $options->{'host'}" );
}
- elsif ( scalar @{$site_list} > 1 ) {
+ if ( scalar @{$site_list} > 1 ) {
Abort( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname "
- . $options->{'host'}
- . " : hostname appeared in multiple sites : "
- . join( ",", @{$site_list} ) . ".\n"
- . "Please relaunch this command with the right site" );
+ "Multiple sites for hostname $options->{'host'}" );
}
- else {
- ($options->{'site'}) = @{$site_list};
- }
+ ($options->{'site'}) = @{$site_list};
}
- else {
- $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
- }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
my $fixed_input = Fix_hosts(
$options->{'host'}, $options->{'input'},
$options->{'site'}, $options->{'type'}, $GLOBAL_STRUCT,
$PF_CONFIG );
-if ( !defined $fixed_input ) {
+unless( $fixed_input ) {
Abort( $CODE->{'EXEC'},
- "An error occured during fixing file " . $options->{'output'} );
+ "An error occured during fixing file $options->{'output'}" );
}
my $output_fh = IO::File->new(">$options->{'output'}")
diff -r f0075a070f36 -r 746c549ca865 sbin/mk_dhcp
--- a/sbin/mk_dhcp Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_dhcp Tue Sep 14 19:37:06 2010 +0200
@@ -26,7 +26,6 @@
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw( :config ignore_case_always bundling );
use IO::File;
-use Data::Dumper;
use PFTools::Logger;
use PFTools::Utils;
@@ -90,22 +89,22 @@
exit 0;
}
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( "", $options->{'config'}, $options->{'store'} );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ "",
+ $options->{'config'},
+ $options->{'store'}
+);
-if ( $options->{'site'} eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
Abort( $CODE->{'UNDEF_KEY'},
"A site MUST BE defined for building DNS zone forward" );
}
- else {
- $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
- }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
-if ( !defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Site $options->{'site'} is not defined into global configuration" );
+unless( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
+ Abort( $CODE->{'UNDEF_KEY'}, "Unknown site $options->{'site'}" );
}
my $DHCP = Mk_dhcp(
diff -r f0075a070f36 -r 746c549ca865 sbin/mk_interfaces
--- a/sbin/mk_interfaces Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_interfaces Tue Sep 14 19:37:06 2010 +0200
@@ -1,7 +1,6 @@
#!/usr/bin/perl
##
-## $Id$
-##
+## Copyright (C) 2007-2010 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>
##
@@ -17,7 +16,8 @@
##
## 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
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA
##
use strict;
@@ -34,13 +34,24 @@
#################################
# VARS
-my $HELP = 0;
-my $HOSTNAME = hostname;
-my $SITE = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
+
+my @options_specs = (
+ 'help',
+ 'host|h=s',
+ 'site|s=s',
+ 'config|c=s',
+ 'store=s',
+ 'output|o=s',
+);
+
+# Default options values
+my $options = {
+ 'help' => 0,
+ 'host' => hostname,
+ 'output' => '-',
+};
+
my $PF_CONFIG = {};
-my $OUTPUT_FILE = '/etc/network/interfaces';
my $GLOBAL_STRUCT = {};
my @HEADER_DEST = (
"#################################################",
@@ -51,14 +62,11 @@
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
-
###################################
# Funtions
sub Do_help {
print STDERR << "# ENDHELP";
- $program - version $version
Usage: $program [options]
--help : print help and exit
@@ -74,68 +82,64 @@
##################################
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'host|h=s' => \$HOSTNAME,
- 'site|s=s' => \$SITE,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
- 'output|o=s' => \$OUTPUT_FILE
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( $HOSTNAME, $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ $options->{'host'},
+ $options->{'config'},
+ $options->{'store'}
+);
-if ( $SITE eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname( $HOSTNAME, $GLOBAL_STRUCT );
- if ( !defined $site_list ) {
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname(
+ $options->{'host'},
+ $GLOBAL_STRUCT
+ );
+ unless( $site_list ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname not defined" );
+ "Unknown hostname $options->{'host'}" );
}
- elsif ( scalar @{$site_list} > 1 ) {
+ if ( scalar @{$site_list} > 1 ) {
Abort( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname appeared in multiple sites : "
- . join( ",", @{$site_list} ) . ".\n"
- . "Please relaunch this command with the right site" );
+ "Multiple sites for hostname $options->{'host'}" );
}
- else {
- ($SITE) = @{$site_list};
- }
+ ($options->{'site'}) = @{$site_list};
}
- else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
- }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
-my $iface = Mk_interfaces( $HOSTNAME, $GLOBAL_STRUCT, $PF_CONFIG, $SITE );
-if ( !defined $iface ) {
+my $iface = Mk_interfaces(
+ $options->{'host'},
+ $GLOBAL_STRUCT,
+ $PF_CONFIG,
+ $options->{'site'}
+);
+unless( $iface ) {
Abort( $CODE->{'EXEC'},
- "An error occured during building interfaces file " . $OUTPUT_FILE );
+ "Error occured during building interfaces file" );
}
-my $output_fh = IO::File->new( '>' . $OUTPUT_FILE )
+my $output_fh = IO::File->new( '>' . $options->{'output'} )
or Abort( $CODE->{'OPEN'},
- "Unable to open destination $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to open file $options->{'output'} : $OS_ERROR" );
$output_fh->print( join "\n", @HEADER_DEST )
or Abort( $CODE->{'OPEN'},
- "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to write on file $options->{'output'} : $OS_ERROR" );
foreach my $if ( @{ $iface->{'__order'} } ) {
- $output_fh->print( join "\n", @{ $iface->{$if} }, "\n" )
- or Abort( $CODE->{'OPEN'},
- "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
+ unless( $output_fh->print( join "\n", @{ $iface->{$if} }, "\n" ) ) {
+ Abort( $CODE->{'OPEN'},
+ "Unable to write on file $options->{'output'} : $OS_ERROR" );
+ }
}
$output_fh->close()
or Abort( $CODE->{'OPEN'},
- "Unable to close destination file $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to close file $options->{'output'} : $OS_ERROR" );
exit 0;
diff -r f0075a070f36 -r 746c549ca865 sbin/mk_pxelinuxcfg
--- a/sbin/mk_pxelinuxcfg Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_pxelinuxcfg Tue Sep 14 19:37:06 2010 +0200
@@ -1,6 +1,4 @@
#!/usr/bin/perl
-##
-## $Id$
##
## Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
@@ -18,13 +16,13 @@
##
## 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
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA
##
use strict;
use warnings;
-use Data::Dumper;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw( :config ignore_case_always bundling );
use File::Path qw( make_path );
@@ -35,14 +33,22 @@
############################################
# Vars
+my @options_specs = (
+ 'help',
+ 'script=s',
+ 'site|s=s',
+ 'config|c=s',
+ 'store=s',
+);
+
+my $options = {
+ 'help' => 0,
+ 'script' => 'pf-tools-config.sh',
+};
+
my $DEPLOY_DOCROOT = "/var/www";
-my $HELP = 0;
-my $PF_SCRIPT = 'pf-tools-config.sh';
my $PXE_TPL = '';
my $PRESEED_TPL = '';
-my $SITE = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
my $PF_CONFIG = {};
my $GLOBAL_STRUCT = {};
my $DEFAULT_PRESEED = '';
@@ -50,14 +56,12 @@
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
############################################
# Functions
sub Do_help {
print STDERR << "# ENDHELP";
- $program - version $version
Usage: $program [options]
--help : print help and exit
@@ -72,21 +76,19 @@
############################################
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'script=s' => \$PF_SCRIPT,
- 'site|s=s' => \$SITE,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( "", $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ "",
+ $options->{'config'},
+ $options->{'store'}
+);
if ( !-e $PF_CONFIG->{'path'}->{'preseed_dir'} ) {
make_path( $PF_CONFIG->{'path'}->{'preseed_dir'} );
@@ -97,22 +99,20 @@
}
$DEFAULT_PRESEED
= $PF_CONFIG->{'path'}->{'preseed_dir'} . "/default_preseed.txt";
-if ( $SITE eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
Abort( $CODE->{'UNDEF_KEY'},
"A site MUST BE defined for building DNS zone forward" );
}
- else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
- }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
-if ( !defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} ) {
+unless( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Site " . $SITE . " is not defined into global configuration" );
+ "Unknown site $options->{'site'}" );
}
-my $site_part = $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$SITE};
+my $site_part = $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$options->{'site'}};
my $host_part = $site_part->{'HOST'}->{'BY_NAME'};
foreach my $hostclass ( @{ $site_part->{'HOST'}->{'__hostclass_pxe'} } ) {
foreach my $host ( keys %{ $host_part->{$hostclass} } ) {
@@ -123,10 +123,11 @@
. $PF_CONFIG->{$mode}->{'pxe'};
my $preseed_tpl = $PF_CONFIG->{'path'}->{'templates_dir'} . '/'
. $PF_CONFIG->{$mode}->{'preseed'};
- my $pxe_file
- = Mk_PXE_bootfile( $host, $host_part->{$hostclass}->{$host},
- $pxe_template, $preseed_tpl, $DEFAULT_PRESEED, $PF_SCRIPT,
- $PF_CONFIG );
+ my $pxe_file = Mk_PXE_bootfile(
+ $host, $host_part->{$hostclass}->{$host},
+ $pxe_template, $preseed_tpl,
+ $DEFAULT_PRESEED, $options->{'script'}, $PF_CONFIG
+ );
}
}
diff -r f0075a070f36 -r 746c549ca865 sbin/mk_resolvconf
--- a/sbin/mk_resolvconf Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_resolvconf Tue Sep 14 19:37:06 2010 +0200
@@ -1,7 +1,6 @@
#!/usr/bin/perl
##
-## $Id$
-##
+## Copyright (C) 2007-2010 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>
##
@@ -33,26 +32,33 @@
#################################
# VARS
-my $HELP = 0;
-my $HOSTNAME = hostname;
-my $SITE = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
+
+my @options_specs = (
+ 'help',
+ 'host|h=s',
+ 'site|s=s',
+ 'config|c=s',
+ 'store=s',
+ 'output|o=s',
+);
+
+my $options = {
+ 'host' => hostname
+ 'help' => 0,
+ 'output' => '/etc/resolv.conf',
+};
+
my $PF_CONFIG = {};
-my $OUTPUT_FILE = '/etc/resolv.conf';
my $GLOBAL_STRUCT = {};
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
###################################
# Funtions
sub Do_help {
print STDERR << "# ENDHELP";
- $program - version $version
Usage: $program [options]
--help : print help and exit
@@ -60,7 +66,7 @@
-s --site : site on which hostname is defined (optional)
-c --config : file where pf-tools configuration is stored e.g. /etc/pf-tools.conf (optional)
--store : file where global structure datas are in storable format (optional)
- -o --output : output file default value is /etc/network/interfaces
+ -o --output : output file default value is /etc/resolv.conf
# ENDHELP
}
@@ -68,52 +74,49 @@
##################################
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'host|h=s' => \$HOSTNAME,
- 'site|s=s' => \$SITE,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
- 'output|o=s' => \$OUTPUT_FILE
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( $HOSTNAME, $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ $options->{'host'},
+ $options->{'config'},
+ $options->{'store'}
+);
-if ( $SITE eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname( $HOSTNAME, $GLOBAL_STRUCT );
- if ( !defined $site_list ) {
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname(
+ $options->{'host'},
+ $GLOBAL_STRUCT
+ );
+ unless( $site_list ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname not defined" );
+ "Unknown hostname $options->{'host'}" );
}
- elsif ( scalar @{$site_list} > 1 ) {
+ if ( scalar @{$site_list} > 1 ) {
Abort( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname appeared in multiple sites : "
- . join( ",", @{$site_list} ) . ".\n"
- . "Please relaunch this command with the right site" );
+ "$options->{'host'} hostname appeared in multiple sites" );
}
- else {
- ($SITE) = @{$site_list};
- }
+ ( $options->{'site'} ) = @{$site_list};
}
- else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
- }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
-if ( !Mk_resolvconf( $HOSTNAME, $GLOBAL_STRUCT, $SITE, $OUTPUT_FILE ) ) {
+unless(
+ Mk_resolvconf(
+ $options->{'host'},
+ $GLOBAL_STRUCT,
+ $options->{'site'},
+ $options->{'output'}
+ )
+) {
Abort( $CODE->{'EXEC'},
- "An error occured during build of file " . $OUTPUT_FILE );
+ "An error occured during build of file " . $options->{'output'} );
}
exit 0;
diff -r f0075a070f36 -r 746c549ca865 sbin/mk_sitezone
--- a/sbin/mk_sitezone Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_sitezone Tue Sep 14 19:37:06 2010 +0200
@@ -1,6 +1,4 @@
#!/usr/bin/perl
-##
-## $Id$
##
## Copyright (C) 2010 Christophe Caillet <quadchris at free.fr>
##
@@ -16,7 +14,8 @@
##
## 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
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA
##
use strict;
@@ -31,25 +30,31 @@
#################################
# VARS
-my $HELP = 0;
-my $SITE = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
+
+my @options_specs = (
+ 'help',
+ 'site|s=s',
+ 'config|c=s',
+ 'store=s',
+ 'output|o=s',
+);
+
+my $options = {
+ 'help' => 0,
+ 'output' => '-',
+};
+
my $PF_CONFIG = {};
-my $OUTPUT_FILE = '';
my $GLOBAL_STRUCT = {};
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
#################################################
# Functions
sub Do_help {
print STDERR << "# ENDHELP";
- $program - version $version
Usage: $program [options]
--help : print help and exit
@@ -64,50 +69,47 @@
##########################################################""
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'site|s=s' => \$SITE,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
- 'output|o=s' => \$OUTPUT_FILE
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( "", $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ "",
+ $options->{'config'},
+ $options->{'store'}
+);
-if ( $SITE eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
Abort( $CODE->{'UNDEF_KEY'},
"A site MUST BE defined for building DNS zone forward" );
}
- else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
- }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
-if ( !defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} ) {
+unless ( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Site " . $SITE . " is not defined into global configuration" );
+ "Site $options->{'site'} is not defined into global configuration" );
}
-my $zone
- = Mk_zone_for_site(
- $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$SITE}->{'zone'},
- $SITE, $GLOBAL_STRUCT );
+my $zone = Mk_zone_for_site(
+ $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$options->{'site'}}->{'zone'},
+ $options->{'site'},
+ $GLOBAL_STRUCT
+);
-my $output_fh = IO::File->new ( '>' . $OUTPUT_FILE )
+my $output_fh = IO::File->new ( '>' . $options->{'output'} )
or Abort( $CODE->{'OPEN'},
- "Unable to open destination file $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to open destination $options->{'output'} : $OS_ERROR" );
$output_fh->print( join "\n", @{$zone} )
or Abort( $CODE->{'OPEN'},
- "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to write on destination $options->{'output'} : $OS_ERROR" );
$output_fh->close()
or Abort( $CODE->{'OPEN'},
- "Unable to close destination file $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to close destination$options->{'output'} : $OS_ERROR" );
exit 0;
diff -r f0075a070f36 -r 746c549ca865 sbin/mk_sourceslist
--- a/sbin/mk_sourceslist Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_sourceslist Tue Sep 14 19:37:06 2010 +0200
@@ -1,10 +1,6 @@
#!/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>
+## Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
@@ -18,7 +14,8 @@
##
## 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
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA
##
use strict;
@@ -35,23 +32,32 @@
############################################
# Vars
-my $HELP = 0;
-my $HOSTNAME = hostname;
-my $OUTPUT_FILE = "";
-my $TEMPLATE = "";
-my $SITE = "";
+my @options_specs = (
+ 'help',
+ 'host|h=s',
+ 'site|s=s',
+ 'tpl|t=s',
+ 'a|add=s',
+ 'config|c=s',
+ 'store=s',
+ 'backport|b',
+ 'output|o=s',
+);
+
+my $options = {
+ 'help' => 0,
+ 'host' => hostname,
+ 'add' => '',
+ 'backport' => 0,
+ 'output' => '-',
+};
+
my $SECTIONS = "common";
-my $TO_ADD = "";
-my $BACKPORTS = 0;
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
my $PF_CONFIG = {};
my $GLOBAL_STRUCT = {};
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
############################################
# Functions
@@ -59,8 +65,6 @@
sub Do_help () {
print <<EOF
-
-$program - version $version
Synopsis : $program [--help] [-h|--host hostname <hostname>] [-s|--site <site_name>]
[-o|--output <sources.list dest>] [ -t|--tpl <sources.list template>] [-b|--backports]
@@ -105,60 +109,56 @@
#############################################################
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'host|h=s' => \$HOSTNAME,
- 'site|s=s' => \$SITE,
- 'tpl|t=s' => \$TEMPLATE,
- 'a|add=s' => \$TO_ADD,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
- 'backport|b' => \$BACKPORTS,
- 'output|o=s' => \$OUTPUT_FILE
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
-if ( $HOSTNAME eq "" ) {
+unless( $options->{'host'} ) {
Abort( $CODE->{'UNDEF_KEY'},
"Unable to build sources.list for an undefined hostname" );
}
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( $HOSTNAME, $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ $options->{'host'},
+ $options->{'config'},
+ $options->{'store'}
+);
-if ( $SITE eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname( $HOSTNAME, $GLOBAL_STRUCT );
- if ( !defined $site_list ) {
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname(
+ $options->{'host'},
+ $GLOBAL_STRUCT
+ );
+ unless( $site_list ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname not defined" );
+ "Unknown hostname $options->{'host'}" );
}
- elsif ( scalar @{$site_list} > 1 ) {
+ if ( scalar @{$site_list} > 1 ) {
Abort( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname appeared in multiple sites : "
- . join( ",", @{$site_list} ) . ".\n"
- . "Please relaunch this command with the right site" );
+ "Multiple site for $options->{'host'}" );
}
- else {
- ($SITE) = @{$site_list};
- }
+ ($options->{'site'}) = @{$site_list};
}
- else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
- }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
-$TO_ADD =~ s/,/ /g;
-$SECTIONS .= " " . $TO_ADD;
-Mk_sourceslist( $HOSTNAME, $SITE, $OUTPUT_FILE, $SECTIONS, $TEMPLATE,
- $BACKPORTS, $GLOBAL_STRUCT, $PF_CONFIG );
+$options->{'add'} =~ s/,/ /g;
+$SECTIONS .= " " . $options->{'add'};
+$SECTIONS =~ s/^\s*//; # Removing trailing space(s)
+Mk_sourceslist(
+ $options->{'host'},
+ $options->{'site'},
+ $options->{'output'},
+ $SECTIONS,
+ $options->{'tpl'},
+ $options->{'backport'},
+ $GLOBAL_STRUCT,
+ $PF_CONFIG
+);
exit 0;
diff -r f0075a070f36 -r 746c549ca865 sbin/update-config
--- a/sbin/update-config Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/update-config Tue Sep 14 19:37:06 2010 +0200
@@ -1,6 +1,4 @@
#!/usr/bin/perl
-##
-## $Id$
##
## Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
@@ -18,7 +16,8 @@
##
## 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
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA
##
use strict;
@@ -41,14 +40,12 @@
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
###################################
# Funtions
sub Do_help {
print STDERR << "# ENDHELP";
- $program - version $version
Usage: $program [options]
--help : print help and exit
@@ -88,43 +85,36 @@
}
$options->{'store'} = "" if ( !defined $options->{'store'} );
my $HOSTNAME = $options->{'host'} || hostname;
-my $SITE = $options->{'site'} || "";
+my $SITE = $options->{'site'};
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( $HOSTNAME, $options->{'config'}, $options->{'store'},
- $options->{'force-reload'} );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ $HOSTNAME,
+ $options->{'config'},
+ $options->{'store'},
+ $options->{'force-reload'}
+);
#### VERIFYING UPDATE FEATURE IN PF-TOOLS CONFIG ABORTING IF DEACTIVATED !!!
if ( !$PF_CONFIG->{'features'}->{'update'} ) {
Abort( $CODE->{'OK'},
- "update-config command has been deactivated in features section in pf-tools.conf"
+ "update-config command has been deactivated in pf-tools.conf"
);
}
-if ( $SITE eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
+unless( $SITE ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
my $site_list = Get_site_from_hostname( $HOSTNAME, $GLOBAL_STRUCT );
- if ( !defined $site_list ) {
+ unless( $site_list ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname not defined" );
+ "Unknown hostname $HOSTNAME" );
}
- elsif ( scalar @{$site_list} > 1 ) {
+ if ( scalar @{$site_list} > 1 ) {
Abort( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname appeared in multiple sites : "
- . join( ",", @{$site_list} ) . ".\n"
- . "Please relaunch this command with the right site" );
+ "Multiple site declaration for $HOSTNAME" );
}
- else {
- ($SITE) = @{$site_list};
- }
+ ($SITE) = @{$site_list};
}
- else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
- }
+ $SITE = $PF_CONFIG->{'location'}->{'site'};
}
if ( $options->{'help'} ) {
@@ -148,8 +138,13 @@
$options->{'noupdate'} = 1;
}
-Do_update_from_GLOBAL( $HOSTNAME, $SITE, $options, $GLOBAL_STRUCT,
- $PF_CONFIG );
+Do_update_from_GLOBAL(
+ $HOSTNAME,
+ $SITE,
+ $options,
+ $GLOBAL_STRUCT,
+ $PF_CONFIG
+);
Unset_deferredlog() if ( $options->{'quiet'} );
More information about the pf-tools-commits
mailing list