pf-tools commit: r800 [ccaillet-guest] - in /branches/next-gen: lib/PFTools/Conf.pm lib/PFTools/Logger.pm lib/PFTools/Parser.pm lib/PFTools/Update.pm lib/PFTools/Utils.pm sbin/mk_grubopt sbin/mk_pxelinuxcfg sbin/update-links
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Aug 4 15:29:40 UTC 2010
Author: ccaillet-guest
Date: Wed Aug 4 15:29:33 2010
New Revision: 800
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=800
Log:
partial commit
Removed:
branches/next-gen/sbin/update-links
Modified:
branches/next-gen/lib/PFTools/Conf.pm
branches/next-gen/lib/PFTools/Logger.pm
branches/next-gen/lib/PFTools/Parser.pm
branches/next-gen/lib/PFTools/Update.pm
branches/next-gen/lib/PFTools/Utils.pm
branches/next-gen/sbin/mk_grubopt
branches/next-gen/sbin/mk_pxelinuxcfg
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=800&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Wed Aug 4 15:29:33 2010
@@ -37,24 +37,6 @@
our @ISA = ('Exporter');
our @EXPORT = qw(
- %SUBST
- $PF_STATUS_DIR
- $PFTOOLSCONF
- $PF_CONFIG
- $CVS_WORKING_DIR
- $CVS_TMP_DIR
- $CVS_OLD_DIR
- $GLOBAL_CONF
- $TEMPLATES
- $CVS_USER
- $CVS_RSH
- $CVS_SERVER
- $CVS_ROOT
- $CVS_REPOSITORY
- $CVS_CONFIG
- $CVS_COMMAND
- $CVS_BRANCHE
-
Init_SUBST
Init_PF_CONFIG
Init_GLOBAL_NETCONFIG
@@ -128,6 +110,7 @@
)
\z
}xms;
+my $DEPLOY_CONFIG_REGEX = '((?:\w{3}\d-r)?deploy|(\w{3}\d-)?spawn)';
my $DEF_SECTIONS = {};
$DEF_SECTIONS->{'host'}->{'interface'} = {
@@ -331,7 +314,8 @@
};
$PF_CONFIG->{'features'} = {
'ipv4' => 1,
- 'ipv6' => 0
+ 'ipv6' => 0,
+ 'update' => 1
};
$PF_CONFIG->{'vcs'} = {
'type' => 'cvs',
@@ -340,6 +324,7 @@
'server' => 'cvs.private',
'cvsroot' => '/var/lib/cvs/repository',
'module' => 'config',
+ 'umask' => '',
'command' => '',
'branche' => ''
};
@@ -362,7 +347,8 @@
$PF_CONFIG->{'regex'} = {
'hostname_model' => $MODEL_CONFIG_REGEX,
'hostname' => $HOST_CONFIG_REGEX,
- 'hosttype' => $HOSTTYPE_CONFIG_REGEX
+ 'hosttype' => $HOSTTYPE_CONFIG_REGEX,
+ 'deploy_hosts' => $DEPLOY_CONFIG_REGEX
};
$PF_CONFIG->{'location'} = {
'site' => '',
Modified: branches/next-gen/lib/PFTools/Logger.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Logger.pm?rev=800&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Logger.pm (original)
+++ branches/next-gen/lib/PFTools/Logger.pm Wed Aug 4 15:29:33 2010
@@ -66,8 +66,6 @@
$CODE->{'UNDEF_KEY'} = 20;
$CODE->{'DUPLICATE_VALUE'} = 21;
-our $DEFERREDLOG = 0;
-
# Vars needed by pf-launch
my $sortie;
my $tmpfile = "/tmp/update-config.log";
@@ -137,12 +135,13 @@
# Returns undef on error
sub deferredlogpipe {
+ my ( $pipe_cmd, $deferredlog ) = @_;
my $ret = '';
- DeferOutput() if $DEFERREDLOG;
-
- unless ( open DEFERREDLOGPIPE, '-|', @_ ) {
- Warn( $ERR_OPEN, "Unable to open pipe @_: $!" );
+ DeferOutput() if $deferredlog;
+
+ unless ( open DEFERREDLOGPIPE, '-|', $pipe_cmd ) {
+ Warn( $ERR_OPEN, "Unable to open pipe $pipe_cmd : $!" );
return;
}
@@ -152,33 +151,34 @@
}
close DEFERREDLOGPIPE;
- UndeferOutput() if $DEFERREDLOG;
+ UndeferOutput() if $deferredlog;
if ($deferbuffer) {
$deferredlogbuffer .= $deferbuffer;
$deferbuffer = undef;
}
- RotateCursor() if $DEFERREDLOG;
+ RotateCursor() if $deferredlog;
return $ret;
}
-sub deferredlogsystem {
+sub deferredlogsystem ($;$){
+ my ( $system_cmd, $deferredlog ) = @_;
my $ret;
- DeferOutput() if ($DEFERREDLOG);
-
- $ret = system(@_);
-
- UndeferOutput() if ($DEFERREDLOG);
+ DeferOutput() if ( $deferredlog );
+
+ $ret = system ( $system_cmd );
+
+ UndeferOutput() if ( $deferredlog );
if ( defined $deferbuffer && $deferbuffer ne '' ) {
$deferredlogbuffer .= $deferbuffer;
$deferbuffer = undef;
}
- RotateCursor() if ($DEFERREDLOG);
+ RotateCursor() if ( $deferredlog );
return $ret;
}
@@ -194,41 +194,42 @@
# Log
-sub Log {
- my @words = split( /\s+/, join( '', @_ ) );
- my $col = 0;
- my $sup = "";
- my $word;
-
- foreach $word (@words) {
- my $len = length($word);
- if ( defined($word) && $len > 0 ) {
- if ( $col != 0 ) {
- $sup = " ";
- }
-
- if ( $word eq "\n" || $word eq "\r" ) {
- $deferredlogbuffer .= "\n";
- $col = 0;
- }
- elsif ( $col + $len + length($sup) < 80 ) {
- $deferredlogbuffer .= $sup . $word;
- $col = $col + length($sup) + $len;
- }
- else {
- $deferredlogbuffer .= "\n... " . $word;
- $col = 4 + $len;
- }
- }
+sub Log ($;$) {
+ my ( $msg, $deferredlog ) = @_;
+
+ my @words = split( /\s+/, $msg );
+ my $col = 0;
+ my $sup = "";
+ my $word;
+
+ foreach $word (@words) {
+ my $len = length($word);
+ if ( defined($word) && $len > 0 ) {
+ if ( $col != 0 ) {
+ $sup = " ";
+ }
+ if ( $word eq "\n" || $word eq "\r" ) {
+ $deferredlogbuffer .= "\n";
+ $col = 0;
+ }
+ elsif ( $col + $len + length($sup) < 80 ) {
+ $deferredlogbuffer .= $sup . $word;
+ $col = $col + length($sup) + $len;
+ }
+ else {
+ $deferredlogbuffer .= "\n... " . $word;
+ $col = 4 + $len;
+ }
+ }
}
$deferredlogbuffer .= "\n";
- if ( !$DEFERREDLOG ) {
- FlushLog();
+ if ( !$deferredlog ) {
+ FlushLog();
}
else {
- RotateCursor();
+ RotateCursor();
}
}
Modified: branches/next-gen/lib/PFTools/Parser.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Parser.pm?rev=800&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Parser.pm (original)
+++ branches/next-gen/lib/PFTools/Parser.pm Wed Aug 4 15:29:33 2010
@@ -27,8 +27,6 @@
our @ISA = ('Exporter');
our @EXPORT = qw(
- $PFTOOLS_VARS
-
Subst_vars
Parser_pftools
Parser_ini
@@ -41,10 +39,6 @@
######################
### Constants
-# PFTools variables define in configuration files
-our $PFTOOLS_VARS = {} ;
-$PFTOOLS_VARS->{'VMWARE'} = 0 ;
-$PFTOOLS_VARS->{'UML'} = 0 ;
######################
### Prototypes
Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=800&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Wed Aug 4 15:29:33 2010
@@ -31,16 +31,18 @@
our @ISA = ('Exporter');
our @EXPORT = qw(
- CVS_update
+ Get_depends_for_action
+ Exec_action
+ Trie_dependances
dirname
- Do_update
);
our @EXPORT_OK = qw();
-use PFTools::Conf;
-use PFTools::Net;
+use File::Compare;
+use File::Copy;
use PFTools::Logger;
+use PFTools::Parser;
use PFTools::Packages;
use Fcntl ':mode';
@@ -50,19 +52,16 @@
use Debconf::Template;
use Debconf::ConfModule;
+###########################################
+### Environement vars
$ENV{'PATH'} = $ENV{'PATH'} . ":/usr/local/sbin:/usr/local/bin";
$ENV{'DEBIAN_FRONTEND'} = "noninteractive";
$ENV{'DEBIAN_PRIORITY'} = "critical";
my $STARTTIME = time();
-$DEFERREDLOG = 0;
-
-# Constantes
-my $CVS_CHECKOUT = "/var/lib/cvsguest";
-my $HOSTNAME = $SUBST{'HOSTNAME'};
-my $HOSTTYPE = $SUBST{'HOSTTYPE'};
-my $CVS_UMASK = 0077;
-my $COMMON = "update-common";
+
+###########################################
+### Constants
my $DEFAULT_MODE = '0640';
my $DEFAULT_DIRMODE = '0750';
my $DEFAULT_OWNER = 'root';
@@ -75,120 +74,73 @@
my $APT_UPDATE = 1;
my $DPKG = 'LANG=C LC_ALL=C /usr/bin/dpkg';
-#$PKGLIST = "/var/lib/apt/lists";
-
-
# Fonctions utilisees dans les fichiers de conf
-sub isipaddr {
- my ($ip) = @_;
-
- my @sub = split( '\.', $ip );
-
- if ( $#sub != 3 ) {
- return 0;
- }
-
- my $i;
-
- foreach $i ( 0 .. 3 ) {
- if ( $sub[$i] < 0 || $sub[$i] > 255 ) {
- return 0;
- }
- }
-
- return -1;
-}
-
-sub fullchown {
- my ( $owner, $group, $dest, $options ) = @_;
- my $newuid;
- my $newgid;
- my $dev;
- my $ino;
- my $mode;
- my $nlink;
- my $uid;
- my $gid;
- my $rdev;
- my $size;
- my $atime;
- my $mtime;
- my $ctime;
- my $blksize;
- my $blocks;
-
- $newuid = getpwnam($owner);
- $newgid = getgrnam($group);
-
- if ( !defined($newuid) || !defined($newgid) ) {
- return 1;
- }
-
- ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
- $size, $atime, $mtime, $ctime, $blksize, $blocks
- ) = stat($dest);
-
- if ( ( defined($uid) && $uid == $newuid )
- && ( defined($gid) && $gid == $newgid ) )
- {
- return 0;
- }
-
- if ( $options->{'verbose'} || $options->{'simul'} ) {
- Log("(chown needed)");
- }
-
- if ( $options->{'simul'} ) {
- return 0;
- }
-
- return !chown( $newuid, $newgid, $dest );
-}
-
-sub fullchmod {
- my ( $newmode, $dest, $options ) = @_;
- my $newuid;
- my $newgid;
- my $dev;
- my $ino;
- my $mode;
- my $nlink;
- my $uid;
- my $gid;
- my $rdev;
- my $size;
- my $atime;
- my $mtime;
- my $ctime;
- my $blksize;
- my $blocks;
-
- ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
- $size, $atime, $mtime, $ctime, $blksize, $blocks
- ) = stat($dest);
-
- if ( defined($mode) && ( $mode & 07777 ) == $newmode ) {
- return 0;
- }
-
- if ( $options->{'verbose'} || $options->{'simul'} ) {
- Log("(chmod needed)");
- }
-
- if ( $options->{'simul'} ) {
- return 0;
- }
-
- return !chmod( $newmode, $dest );
-}
-
-sub ln_sfn {
+##############################################
+###
+
+sub isipaddr ($) {
+ my ($ip) = @_;
+
+ my @sub = split( '\.', $ip );
+ return 0 if ( $#sub != 3 );
+
+ foreach my $octet ( 0 .. 3 ) {
+ return 0 if ( $sub[$octet] < 0 || $sub[$octet] > 255 );
+ }
+ return 1;
+}
+
+sub __full_rights ($$$$;$) {
+ my ( $type, $dest, $options, $right1, $right2 ) = @_;
+
+ if ( $options->{'verbose'} || $options->{'simul'} ) {
+ Log ( "(chown needed)" );
+ }
+ if ( $options->{'simul'} ) {
+ return 0;
+ }
+ my ( $dev, $ino, $mode, $nlink, $uid, $gid, @others ) = stat($dest);
+ if ( $type eq 'chown' ) {
+ my $newuid = getpwnam ($owner);
+ my $newgid = getgrnam ($group);
+ if (
+ ( defined($uid) && $uid == $newuid )
+ && ( defined($gid) && $gid == $newgid )
+ ) {
+ return 0;
+ }
+ return ! chown ( $newuid, $newgid, $dest );
+ }
+ elsif ( $type eq 'chmod' ) {
+ if ( defined($mode) && ( $mode & 07777 ) == $newmode ) {
+ return 0;
+ }
+ return ! chmod ( $newmode, $dest );
+ }
+ else {
+ return 1
+ }
+}
+
+sub fullchown ($$$$) {
+ my ( $owner, $group, $dest, $options ) = @_;
+
+ return __full_rights ( 'chown', $dest, $options, $owner, $group );
+}
+
+sub fullchmod ($$$) {
+ my ( $newmode, $dest, $options ) = @_;
+
+ return __full_rights ( 'chmod', $dest, $options, $newmode );
+}
+
+sub ln_sfn ($$) {
my ( $source, $dest ) = @_;
- unlink($dest);
- rmdir($dest);
- return !symlink( $source, $dest );
+ unlink ( $dest );
+ rmdir ( $dest );
+ return ! symlink ( $source, $dest ) ;
}
sub dirname {
@@ -197,579 +149,400 @@
$file =~ s://:/:g;
if ( $file =~ m|/| ) {
- $file =~ s|^(.*)/[^/]+/?$|$1|;
+ $file =~ s|^(.*)/[^/]+/?$|$1|;
}
else {
- $file = '.';
+ $file = '.';
}
return $file;
}
-sub Do_moveold {
+sub Do_moveold ($$) {
my ( $dest, $options ) = @_;
- if ( -e $dest ) {
- my $old = $CVS_OLD_DIR . "/" . $dest . "." . $STARTTIME;
-
- if ( $options->{'verbose'} ) {
- Log( "(moving old to " . $old . ")" );
- }
-
- if ( !$options->{'simul'} ) {
- Mk_dest_dir($old);
- deferredlogsystem( "/bin/mv '" . $dest . "' '" . $old . "'" );
- }
- }
-}
-
-sub Do_chownmod {
- my ( $S, $dest, $options ) = @_;
-
- my $owner;
- my $group;
- my $mode;
-
- $owner = defined( $S->{'owner'} ) ? $S->{'owner'} : $DEFAULT_OWNER;
- $group = defined( $S->{'group'} ) ? $S->{'group'} : $DEFAULT_GROUP;
-
- if ( fullchown( $owner, $group, $dest, $options ) ) {
- Warn( $CODE->{'OPEN'},
- "Impossible d'attribuer "
- . $dest . " a "
- . $owner . "."
- . $group );
- return 1;
- }
-
- $mode
- = defined( $S->{'mode'} )
- ? $S->{'mode'}
- : ( ( -d $dest ) ? $DEFAULT_DIRMODE : $DEFAULT_MODE );
- $mode =~ s/^[^0]/0$&/;
-
- if ( fullchmod( eval($mode), $dest, $options ) ) {
- Warn( $CODE->{'OPEN'},
- "Impossible d'attribuer les droits " . $mode . " a " . $dest );
- return 1;
- }
+ if ( -e $dest ) {
+ my $old = $CVS_OLD_DIR . "/" . $dest . "." . $STARTTIME;
+ if ( $options->{'verbose'} ) {
+ Log( "(moving old to " . $old . ")" );
+ }
+ if ( ! $options->{'simul'} ) {
+ Mk_dest_dir ( $old );
+ return ! move ( $old, $dest )
+ }
+ }
+}
+
+sub Do_chownmod ($$$) {
+ my ( $ref_section, $dest, $options ) = @_;
+
+ $owner = defined( $ref_section->{'owner'} ) ? $ref_section->{'owner'} : $DEFAULT_OWNER;
+ $group = defined( $ref_section->{'group'} ) ? $ref_section->{'group'} : $DEFAULT_GROUP;
+
+ if ( fullchown( $owner, $group, $dest, $options ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to change owner and/or group to ".$owner." and ".$group
+ ." for file ".$dest);
+ return 1;
+ }
+
+ $mode = defined( $ref_section->{'mode'} )
+ ? $ref_section->{'mode'}
+ : ( ( -d $dest ) ? $DEFAULT_DIRMODE : $DEFAULT_MODE );
+ $mode =~ s/^[^0]/0$&/;
+
+ if ( fullchmod( eval($mode), $dest, $options ) ) {
+ Warn( $CODE->{'OPEN'},
+ "unable to change rights to ".$mode." for file ".$dest );
+ return 1;
+ }
+ return 0;
}
sub Exec_cmd ($) {
my ( $cmd ) = @_;
- if ( deferredlogsystem($cmd) ) {
- Warn( $CODE->{'OPEN'}, "Impossible d'executer [" . $cmd . "]" );
+ if ( deferredlogsystem ( $cmd ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to execute [".$cmd."]" );
return 1;
}
return 0;
}
-sub Do_on_config {
- my ( $S, $options ) = @_;
-
- if ( !$options->{'simul'} && defined( $S->{'on_config'} ) )
- {
- return Exec_cmd ( Subst_vars ( $S->{'on_config'} ) );
- }
-}
-
-sub Do_before_change {
- my ( $S, $options ) = @_;
-
- if ( !$options->{'simul'}
- && defined( $S->{'before_change'} )
- && !$options->{'noaction'} )
- {
- return Exec_cmd ( Subst_vars ( $S->{'before_change'} ) );
- }
-}
-
-sub Do_after_change {
- my ( $S, $options ) = @_;
-
- if ( !$options->{'simul'}
- && defined( $S->{'after_change'} )
- && !$options->{'noaction'} )
- {
- return Exec_cmd ( Subst_vars ( $S->{'after_change'} ) );
+sub Do_on_config ($$$) {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ if ( ! $options->{'simul'}
+ && defined ( $ref_section->{'on_config'} )
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'on_config'}, $hash_subst ) );
+ }
+}
+
+sub Do_before_change ($$$) {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ if ( ! $options->{'simul'}
+ && ! $options->{'noaction'}
+ && defined ( $ref_section->{'before_change'} )
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'before_change'}, $hash_subst ) );
+ }
+}
+
+sub Do_after_change ($$$) {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ if ( !$options->{'simul'}
+ && defined ( $ref_section->{'after_change'} )
+ && !$options->{'noaction'}
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'after_change'}, $hash_subst ) );
}
}
sub Do_on_noaction {
- my ( $S, $options ) = @_;
-
- if ( !$options->{'simul'}
- && defined( $S->{'on_noaction'} )
- && $options->{'noaction'} )
- {
- return Exec_cmd ( Subst_vars ( $S->{'on_noaction'} ) );
+ my ( $ref_section, $options ) = @_;
+
+ if ( ! $options->{'simul'}
+ && defined ( $ref_section->{'on_noaction'} )
+ && $options->{'noaction'}
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'on_noaction'}, $hash_subst ) );
}
}
my %DEPENDS;
my %FUNCTIONS;
-$DEPENDS{'addfile'} = sub {
- my ( $S, $dest, $options ) = @_;
-
- while ( $dest ne '/' && $dest ne '.' ) {
- $S->{'depends'} .= " " . dirname($dest);
- $dest = dirname($dest);
- }
-};
-
-$FUNCTIONS{'addfile'} = sub {
- my ( $S, $dest, $options ) = @_;
-
- my $source;
- my $tmp;
- my $cmp;
-
- if ( !defined( $S->{'source'} ) ) {
- Abort( $CODE->{'SYNTAX'}, "Source non definie pour " . $dest );
- }
- $SUBST{'SECTIONNAME'} = $dest;
- if ( $S->{'source'} =~ /\s/ ) {
- $source = Get_tmp_dest($dest) . ".merged";
- unlink($source);
-
- my $splitsource;
- foreach $splitsource ( split( ' ', $S->{'source'} ) ) {
- $splitsource = Get_source( Subst_vars($splitsource) );
- if ( !-f $splitsource ) {
- Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $splitsource );
- return 1;
- }
- if (deferredlogsystem(
- "cat '" . $splitsource . "' >> " . $source
- )
- )
- {
- Warn( $CODE->{'OPEN'},
- "Impossible de concatener "
- . $splitsource
- . " dans "
- . $tmp );
- return 1;
- }
- }
- }
- else {
- $source = Get_source( Subst_vars( $S->{'source'} ) );
- }
-
- $SUBST{'SOURCE'} = $source;
- $tmp = Get_tmp_dest($dest);
- $SUBST{'DESTINATION'} = $tmp;
-
- if ( defined( $S->{'filter'} ) ) {
- my $filter = Subst_vars( $S->{'filter'} );
- if ( deferredlogsystem($filter) ) {
- Warn( $CODE->{'OPEN'}, "Impossible d'appliquer " . $filter );
- return 1;
- }
- }
- else {
-
- if (deferredlogsystem(
- "/bin/cp -a '" . $source . "' '" . $tmp . "'"
- )
- )
- {
- Warn( $CODE->{'OPEN'},
- "Impossible de copier " . $source . " vers " . $tmp );
- return 1;
- }
- }
-
- if ( !-f $tmp ) {
- Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $tmp );
- return 1;
- }
-
- $cmp = 0;
- if ( deferredlogsystem( "/usr/bin/cmp -s '" . $tmp . "' '" . $dest . "'" )
- )
- {
-
- $cmp = 1;
-
- if ( $options->{'verbose'} || $options->{'simul'} ) {
- Log("(action needed)");
- }
-
- if ( $options->{'diff'} ) {
- deferredlogsystem(
- "/usr/bin/diff -uN '" . $dest . "' '" . $tmp . "'" );
- }
-
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
-
- if ( !$options->{'simul'} ) {
-
- # Fuck dpkg conffiles
- if ( $options->{'noaction'}
- && -e $dest
- && !-e $dest . ".dpkg-dist" )
- {
- deferredlogsystem(
- "/bin/cp -a '" . $dest . "' '" . $dest . ".dpkg-dist'" );
- }
-
- Do_moveold( $dest, $options );
-
- if (Mk_dest_dir($dest)
- || deferredlogsystem(
- "/bin/cp -a '" . $tmp . "' '" . $dest . "'"
- )
- )
- {
- Warn( $CODE->{'OPEN'},
- "Impossible de copier " . $tmp . " vers " . $dest );
- return 1;
- }
- }
- }
-
- Do_chownmod( $S, $dest, $options );
-
- if ($cmp) {
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
- }
-
+$DEPENDS{'addfile'} = sub ($$$) {
+ my ( $ref_section, $dest, $options ) = @_;
+
+ while ( $dest ne "/" && $dest ne "." ) {
+ $ref_section->{'depends'} .= " " . dirname($dest);
+ $dest = dirname($dest);
+ }
+};
+
+$FUNCTIONS{'addfile'} = sub ($$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst ) = @_;
+ my ( $source, $tmp, $cmp );
+
+ $hash_subst->{'SECTIONNAME'} = $dest;
+ if ( $ref_section->{'source'} =~ /\s/ ) {
+ $source = Get_tmp_dest ($dest).".merged";
+ unlink ($source);
+ my $splitsource;
+ foreach $splitsource ( split( ' ', $ref_section->{'source'} ) ) {
+ $splitsource = Get_source( Subst_vars ( $splitsource, $hash_subst ) );
+ if ( ! -f $splitsource ) {
+ Warn( $CODE->{'OPEN'}, "Unable to open ".$splitsource );
+ return 1;
+ }
+ if ( deferredlogsystem( "cat '".$splitsource."' >> ".$source ) ) {
+ Warn( $CODE->{'EXEC'},
+ "Unable to append file ".$splitsource." to ".$tmp );
+ return 1;
+ }
+ }
+ }
+ else {
+ $source = Get_source( Subst_vars( $ref_section->{'source'} ), $hash_subst );
+ }
+
+ $hash_subst->{'SOURCE'} = $source;
+ $tmp = Get_tmp_dest($dest);
+ $hash_subst->{'DESTINATION'} = $tmp;
+ if ( defined( $ref_section->{'filter'} ) ) {
+ my $filter = Subst_vars( $ref_section->{'filter'}, $hash_subst );
+ if ( deferredlogsystem ($filter) ) {
+ Warn( $CODE->{'OPEN'}, "Unable to apply filter " . $filter );
+ return 1;
+ }
+ }
+ else {
+ if ( ! copy ( $source, $tmp ) ) {
+ Warn( $CODE->{'COPY'},
+ "Unable to copy ".$source." to ".$tmp );
+ return 1;
+ }
+ }
+
+ if ( ! -f $tmp ) {
+ Warn( $CODE->{'OPEN'}, "unable to open " . $tmp );
+ return 1;
+ }
+ elsif ( compare ( $tmp, $dest ) ) {
+ $diff = 1;
+ if ( $options->{'verbose'} || $options->{'simul'} ) {
+ Log("(action needed)");
+ }
+ if ( $options->{'diff'} ) {
+ deferredlogsystem( "/usr/bin/diff -uN '".$dest."' '".$tmp."'" );
+ }
+ Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+ Do_before_change ( $ref_section, $options, $hash_subst ) && return 1;
+ if ( !$options->{'simul'} ) {
+ # Fuck dpkg conffiles
+ if ( $options->{'noaction'}
+ && -e $dest
+ && ! -e $dest.'.dpkg-dist'
+ ) {
+ copy ( $dest, $dest.'.dpkg-dist' );
+ Do_moveold( $dest, $options );
+ if ( Mk_dest_dir($dest)
+ || ! copy ( $tmp, $dest )
+ ) {
+ Warn( $CODE->{'OPEN'},
+ "Impossible de copier " . $tmp . " vers " . $dest );
+ return 1;
+ }
+ }
+ }
+ }
+ Do_chownmod( $ref_section, $dest, $options );
+ if ( $diff ) {
+ Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+ Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+ }
return 0;
};
-$FUNCTIONS{'dpkg-purge'} = sub {
- my ( $S, $dest, $options, $pkg_type ) = @_;
-
- $pkg_type = 'deb' if ( ! defined $pkg_type ) ;
-
- my $name_filter = $S->{'name_filter'};
- if ($name_filter) {
- $SUBST{'SECTIONNAME'} = $dest;
- my $newdest = deferredlogpipe( Subst_vars($name_filter) );
- unless ( defined $newdest ) {
- Warn( $CODE->{'OPEN'},
- "Impossible d'appliquer name_filter $name_filter" );
- return 1;
- }
- unless ($newdest) {
- Warn( $CODE->{'OPEN'}, "Resultat vide pour name_filter $name_filter" );
- return 1;
- }
- $dest = $newdest;
- }
-
-# my $installed_version;
-#
-# open( DPKG, $DPKG . ' -s ' . $dest . ' 2>/dev/null |' );
-# while (<DPKG>) {
-# if (/^Status:\s+/) {
-# if ( !/^Status:\s+install\s+ok\s+installed\s*$/ ) {
-# $installed_version = 0;
-# last;
-# }
-# }
-#
-# if (/^Version:\s+(.+)\s*$/) {
-# $installed_version = $1;
-# last;
-# }
-# }
-# close(DPKG);
-
- my $status = Get_pkg_status ( $pkg_type, $dest ) ;
- if ( ! defined $status ) {
- Warn ( $CODE->{'OPEN'}, "Impossible d'obtenir le statut du paquet ".$dest ) ;
- return 1;
+$FUNCTIONS{'dpkg-purge'} = sub ($$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst ) = @_;
+
+ $options->{'pkg_type'} = 'deb' if ( ! defined $options->{'pkg_type'} ) ;
+
+ my $name_filter = $ref_section->{'name_filter'};
+ if ( $name_filter ) {
+ $hash_subst->{'SECTIONNAME'} = $dest;
+ my $newdest = deferredlogpipe ( Subst_vars ( $name_filter, $hash_subst ) );
+ unless ( defined $newdest ) {
+ Warn( $CODE->{'OPEN'}, "Unable to apply name_filter".$name_filter );
+ return 1;
+ }
+ unless ($newdest) {
+ Warn( $CODE->{'OPEN'}, "Empty result for name_filter ".$name_filter );
+ return 1;
+ }
+ $dest = $newdest;
+ }
+
+ my $status = Get_pkg_status ( $pkg_type, $dest ) ;
+ if ( ! defined $status ) {
+ Warn ( $CODE->{'OPEN'}, "Unable to retrieve status for package ".$dest ) ;
+ return 1;
}
if ( $status->{'installed'} ) {
-
- if ( $options->{'verbose'} || $options->{'simul'} ) {
- Log("(action needed)");
- }
-
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
-
- if ( !$options->{'simul'} ) {
-# if ( deferredlogsystem( $DPKG . " -P '" . $dest . "'" ) ) {
-# Warn( $CODE->{'OPEN'},
-# "Purge du package " . $dest . " impossible" );
-# return 1;
-# }
- if ( ! Purge_pkg ( $pkg_type, $dest ) ) {
- Warn ( $CODE->{'OPEN'}, "Une erreur est survenue lors de la purge du paquet ".$dest ) ;
- return 1 ;
- }
- }
-
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
- }
-
- return 0;
+ if ( $options->{'verbose'} || $options->{'simul'} ) {
+ Log("(action needed)");
+ }
+ Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+ Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+ if ( !$options->{'simul'} ) {
+ if ( ! Purge_pkg ( $pkg_type, $dest ) ) {
+ Warn ( $CODE->{'OPEN'}, "Une erreur est survenue lors de la purge du paquet ".$dest ) ;
+ return 1 ;
+ }
+ }
+ Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+ Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+ }
+ return 0;
};
sub aptupdate ($){
- my ( $pkg_type ) = @_ ;
-
- if ($APT_UPDATE) {
- if ( ! Update_pkg_repository ( $pkg_type ) ) {
- return 1;
- }
- $APT_UPDATE = 0;
- }
- return 0;
+ my ( $pkg_type ) = @_;
+
+ if ( $APT_UPDATE ) {
+ if ( ! Update_pkg_repository ( $pkg_type ) ) {
+ return 1;
+ }
+ $APT_UPDATE = 0;
+ }
+ return 0;
}
$DEPENDS{'apt-get'} = sub {
- my ( $S, $dest, $options, $pkg_type ) = @_;
-
- $pkg_type = 'deb' if ( ! defined $pkg_type ) ;
+ my ( $ref_section, $dest, $options ) = @_;
+
+ $options->{'pkg_type'} = 'deb' if ( ! defined $options->{'pkg_type'} ) ;
if ( aptupdate( $pkg_type ) ) {
- return 1;
- }
-
-
-# open( APTDEP, $APT_GET_DEPENDS . ' install ' . $dest . ' 2>/dev/null |' );
-# while (<APTDEP>) {
-# if (m/^ (.*)$/) {
-# my $pkg;
-# foreach $pkg ( split( ' ', $1 ) ) {
-# if ( $pkg ne $dest ) {
-# $S->{'depends'} .= " " . $pkg;
-# }
-# }
-# }
-# }
-# close(APTDEP);
- my $deps = Get_pkg_depends ( $pkg_type, $dest ) ;
- if ( ! defined $deps ) {
- Warn ( $CODE->{'OPEN'}, "Impossible de recuperer les dependances du paquet ".$dest ) ;
- return 1;
- }
- else {
- $S->{'depends'} = $dest ;
- }
-};
-
-$FUNCTIONS{'apt-get'} = sub {
- my ( $S, $dest, $options, $pkg_type ) = @_;
-
- $pkg_type = 'deb' if ( ! defined $pkg_type ) ;
- my $installed_version;
- my $available_version;
- my $specified_version = 0;
- my $install;
-
- my $name_filter = $S->{'name_filter'};
- if ($name_filter) {
- $SUBST{'SECTIONNAME'} = $dest;
- my $newdest = deferredlogpipe( Subst_vars($name_filter) );
- unless ( defined $newdest ) {
- Warn( $CODE->{'OPEN'},
- "Impossible d'appliquer name_filter $name_filter" );
- return 1;
- }
- unless ($newdest) {
- Warn( $CODE->{'OPEN'}, "Resultat vide pour name_filter $name_filter" );
- return 1;
- }
- $dest = $newdest;
- }
-
- aptupdate( $pkg_type );
-
-# open( APTPOLICY, $APT_POLICY . ' ' . $dest . ' 2>/dev/null |' );
-# while (<APTPOLICY>) {
-# if (m/^ Installed: (.*)$/) {
-# $installed_version = $1;
-# if ( $installed_version eq '' || $installed_version eq '(none)' )
-# {
-# undef $installed_version;
-# }
-# }
-# elsif (m/^ Candidate: (.*)$/) {
-# $available_version = $1;
-# }
-# }
-# close(APTPOLICY);
-
- ( $installed_version, $available_version, $specified_version ) = Get_pkg_policy ( $pkg_type, $dest, $S->{'version'} ) ;
-
-# if ( !defined($available_version) ) {
-# Warn( $CODE->{'OPEN'}, "Package " . $dest . " indisponible" );
-# return 1;
-# }
-
- if ( !defined ( $available_version ) ) {
- Warn( $CODE->{'OPEN'}, "Package " . $dest . " indisponible" );
- return 1;
- }
- if ( defined ( $S->{'version'} ) && ! $specified_version ) {
- Warn( $CODE->{'OPEN'}, "Package " . $dest . " en version " . $S->{'version'} . " indisponible" );
- return 1;
- }
-
-# if (!defined($installed_version)
-# || !deferredlogsystem(
-# $DPKG
-# . ' --compare-versions '
-# . $installed_version . ' lt '
-# . $available_version
-# )
-# )
-# {
-# $install++;
-# }
-
- if ( defined $installed_version ) {
- my $compare = Cmp_pkg_version ( $pkg_type, $dest, $installed_version, $available_version ) ;
- if ( defined $compare && $compare < 0 ) {
- $install++ ;
- }
- }
-
- if ($install) {
-
- if ( $options->{'verbose'} || $options->{'simul'} ) {
- Log("(action needed)");
- }
-
- if ( $options->{'diff'} ) {
- Log("(inst = "
- . (
- defined($installed_version) ? $installed_version : '?'
- )
- . ", avail = "
- . (
- defined($available_version) ? $available_version : '?'
- )
- . ")"
- );
- }
-
- if ( defined( $S->{'delay'} ) && !$options->{'noaction'} ) {
- $HOSTNAME =~ /\d+$/;
- if ( $& ne "" ) {
- sleep( 120 * $& );
- }
- }
-
- if ( !$options->{'simul'} && defined( $S->{'debconf'} ) ) {
-
- my $DEB;
- my $conf;
- my $pkg;
-
- Debconf::Db->load;
- foreach $conf ( keys %{ $S->{'debconf'} } ) {
-
- ($pkg) = split( m:/:, $conf );
-
- if ( !$DEB->{$pkg} ) {
- $DEB->{$pkg} = 1;
- Debconf::Template->load( $TEMPLATES . "/" . $pkg, $pkg );
- }
-
- Debconf::ConfModule->command_set( $conf,
- $S->{'debconf'}->{$conf} );
- Debconf::ConfModule->command_fset( $conf, "seen", "true" );
- }
- Debconf::Db->save;
- }
-
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
-
- if ( defined( $S->{'reply'} ) ) {
- $install = $S->{'reply'};
- eval "\$install = sprintf (\"echo '$install' |\")";
+ return 1;
+ }
+ my $deps = Get_pkg_depends ( $pkg_type, $dest ) ;
+ if ( ! defined $deps ) {
+ Warn ( $CODE->{'OPEN'}, "Unable to get depends for package ".$dest ) ;
+ return 1;
}
else {
- $install = '';
- }
-
- if ( !$options->{'simul'} ) {
-# if (deferredlogsystem(
-# $install . " " . $APT_GET . " install '" . $dest . "'"
-# )
-# )
-# {
-# Warn( $CODE->{'OPEN'}, "Installation de " . $dest . " impossible" );
-# return 1;
-# }
- if ( ! Install_pkg ( $pkg_type, $dest, $S->{'version'} ) ) {
- Warn( $CODE->{'OPEN'}, "Installation de ".$dest." impossible" ) ;
- return 1;
- }
- }
-
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
- }
-
- return 0;
-};
-
-$DEPENDS{'addmount'} = sub {
- my ( $S, $dest, $options ) = @_;
-
- while ( $dest ne '/' && $dest ne '.' ) {
- $S->{'depends'} .= " " . dirname($dest);
- $dest = dirname($dest);
- }
-};
-
-$FUNCTIONS{'addmount'} = sub {
- my ( $S, $dest, $options ) = @_;
-
- my $addmount;
- my $source;
- my $fstype;
- my $opts;
- my $sortedopts;
-
- my $oldsource;
- my $olddest;
- my $oldfstype;
- my $oldopts;
- my $oldresolvedopts;
-
- my $oldmsource;
- my $oldmresolvedsource;
- my $oldmdest;
- my $oldmfstype;
- my $oldmopts;
-
- my $addmountfstab = 0;
- my $addmountmounts = 0;
+ $ref_section->{'depends'} = $dest ;
+ }
+};
+
+$FUNCTIONS{'apt-get'} = sub ($$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst ) = @_;
+
+ $options->{'pkg_type'} = 'deb' if ( ! defined $options->{'pkg_type'} ) ;
+ my $installed_version;
+ my $available_version;
+ my $specified_version = 0;
+ my $install = 0;
+
+ my $name_filter = $ref_section->{'name_filter'};
+ if ( $name_filter ) {
+ $hash_subst->{'SECTIONNAME'} = $dest;
+ my $newdest = deferredlogpipe ( Subst_vars ( $name_filter, $hash_subst ) );
+ unless ( defined $newdest ) {
+ Warn( $CODE->{'OPEN'}, "Unable to apply name_filter".$name_filter );
+ return 1;
+ }
+ unless ( $newdest ) {
+ Warn( $CODE->{'OPEN'}, "Empty result for name_filter".$name_filter );
+ return 1;
+ }
+ $dest = $newdest;
+ }
+ aptupdate( $pkg_type );
+ ( $installed_version, $available_version, $specified_version ) = Get_pkg_policy ( $pkg_type, $dest, $ref_section->{'version'} ) ;
+ if ( ! defined ( $available_version ) ) {
+ Warn( $CODE->{'OPEN'}, "Package ".$dest." is unavailable" );
+ return 1;
+ }
+ if ( defined ( $ref_section->{'version'} ) && ! $specified_version ) {
+ Warn( $CODE->{'OPEN'}, "Package ".$dest." in version ".$ref_section->{'version'}." is unavailable" );
+ return 1;
+ }
+ if ( defined $installed_version ) {
+ my $compare = Cmp_pkg_version ( $pkg_type, $dest, $installed_version, $available_version ) ;
+ $install++ if ( defined $compare && $compare < 0 );
+ }
+
+ if ($install) {
+ if ( $options->{'verbose'} || $options->{'simul'} ) {
+ Log("(action needed)");
+ }
+ if ( $options->{'diff'} ) {
+ Log (
+ "(inst = ".( defined($installed_version) ? $installed_version : '?' )
+ .", avail = ".( defined($available_version) ? $available_version : '?' )
+ .")"
+ );
+ }
+ if ( defined( $ref_section->{'delay'} ) && ! $options->{'noaction'} ) {
+ $HOSTNAME =~ /\d+$/;
+ if ( $& ne "" ) {
+ sleep( 120 * $& );
+ }
+ }
+ if ( !$options->{'simul'} && defined( $ref_section->{'debconf'} ) ) {
+ my $DEB;
+ my $conf;
+ my $pkg;
+ Debconf::Db->load;
+ foreach $conf ( keys %{ $ref_section->{'debconf'} } ) {
+ ($pkg) = split( m:/:, $conf );
+ if ( !$DEB->{$pkg} ) {
+ $DEB->{$pkg} = 1;
+ Debconf::Template->load( $TEMPLATES . "/" . $pkg, $pkg );
+ }
+ Debconf::ConfModule->command_set( $conf,
+ $ref_section->{'debconf'}->{$conf} );
+ Debconf::ConfModule->command_fset( $conf, "seen", "true" );
+ }
+ Debconf::Db->save;
+ }
+ Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+ Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+ if ( defined( $ref_section->{'reply'} ) ) {
+ $install = $ref_section->{'reply'};
+ eval "\$install = sprintf (\"echo '$install' |\")";
+ }
+ else {
+ $install = '';
+ }
+ if ( !$options->{'simul'} ) {
+ if ( ! Install_pkg ( $pkg_type, $dest, $ref_section->{'version'} ) ) {
+ Warn( $CODE->{'OPEN'}, "Installation de ".$dest." impossible" ) ;
+ return 1;
+ }
+ }
+ Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+ Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+ }
+ return 0;
+};
+
+$DEPENDS{'addmount'} = sub ($$$) {
+ my ( $ref_section, $dest, $options ) = @_;
+
+ while ( $dest ne "/" && $dest ne "." ) {
+ $ref_section->{'depends'} .= " " . dirname ( $dest );
+ $dest = dirname ( $dest );
+ }
+};
+
+$FUNCTIONS{'addmount'} = sub ($$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst ) = @_;
+
+ my ( $addmount, $source, $fstype, $opts, $sortedopts );
+ my ( $oldsource, $olddest, $oldfstype, $oldopts, $oldresolvedopts );
+ my ( $oldmsource, $oldmresolvedsource, $oldmdest, $oldmfstype, $oldmopts );
+ my $addmountfstab = 0;
+ my $addmountmounts = 0;
my $Z;
- if ( !defined( $S->{'source'} ) ) {
- Abort( $CODE->{'SYNTAX'}, "Source non definie pour " . $dest );
- }
- $SUBST{'SECTIONNAME'} = $dest;
- $source = Subst_vars( $S->{'source'} );
-
- my $sourceaddr = $source;
+ $hash->{'SECTIONNAME'} = $dest;
+ $source = Subst_vars( $ref_section->{'source'}, $hash_subst );
+ my $sourceaddr = $source;
$sourceaddr =~ s/^([^:]+):(.+)$/$1/; # NFS
- if ( defined($sourceaddr) && !isipaddr($sourceaddr) ) {
- if ( !defined($Z) ) {
- $Z = Init_lib_net( Get_source("GLOBAL:private-network") );
+ if ( defined ( $sourceaddr ) && ! isipaddr ( $sourceaddr ) ) {
+ if ( ! defined($Z) ) {
+ $Z = Init_lib_net( Get_source("GLOBAL:private-network") );
+ }
}
my $sourceip = Resolv( $sourceaddr, $Z );
if ( defined($sourceip) && $sourceip ne "" ) {
@@ -779,7 +552,7 @@
$SUBST{'SOURCE'} = $source;
- $opts = defined( $S->{'options'} ) ? $S->{'options'} : $DEFAULT_OPTIONS;
+ $opts = defined( $ref_section->{'options'} ) ? $ref_section->{'options'} : $DEFAULT_OPTIONS;
my $optsaddr = $opts;
$optsaddr =~ s/^(.*,)?ip=([^,]+)(,.*)?$/$2/;
@@ -796,7 +569,7 @@
$SUBST{'OPTIONS'} = $opts;
$sortedopts = join( ',', sort split( ',', $opts ) );
- $fstype = defined( $S->{'fstype'} ) ? $S->{'fstype'} : $DEFAULT_FSTYPE;
+ $fstype = defined( $ref_section->{'fstype'} ) ? $ref_section->{'fstype'} : $DEFAULT_FSTYPE;
$SUBST{'FSTYPE'} = $fstype;
if ( !open( FSTAB, "< /etc/fstab" ) ) {
@@ -943,16 +716,16 @@
Log("(action needed)");
}
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
+ Do_on_config( $ref_section, $options ) && return 1;
+
+ Do_before_change( $ref_section, $options ) && return 1;
if ( !-d $dest && $dest ne 'none' ) {
if ( !defined( $FUNCTIONS{'mkdir'} ) ) {
Warn( $CODE->{'OPEN'}, "Fonction mkdir necessaire pour addmount" );
return 1;
}
- $FUNCTIONS{'mkdir'}->( $S, $dest, $options );
+ $FUNCTIONS{'mkdir'}->( $ref_section, $dest, $options );
}
if ($addmountfstab) {
@@ -1161,44 +934,44 @@
}
}
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
+ Do_after_change( $ref_section, $options ) && return 1;
+
+ Do_on_noaction( $ref_section, $options ) && return 1;
}
return 0;
};
$FUNCTIONS{'ignore'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
return 0;
};
$DEPENDS{'addlink'} = sub {
- my ( $S, $dest, $options ) = @_;
- my $source = Subst_vars( $S->{'source'} );
+ my ( $ref_section, $dest, $options ) = @_;
+ my $source = Subst_vars( $ref_section->{'source'} );
while ( $source ne '/' && $source ne '.' ) {
- $S->{'depends'} .= " " . dirname($source);
+ $ref_section->{'depends'} .= " " . dirname($source);
$source = dirname($source);
}
while ( $dest ne '/' && $dest ne '.' ) {
- $S->{'depends'} .= " " . dirname($dest);
+ $ref_section->{'depends'} .= " " . dirname($dest);
$dest = dirname($dest);
}
};
$FUNCTIONS{'addlink'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
my $cmp = 0;
$SUBST{'SECTIONNAME'} = $dest;
- if ( !defined( $S->{'source'} ) ) {
+ if ( !defined( $ref_section->{'source'} ) ) {
Abort( $CODE->{'SYNTAX'}, "Source non definie pour " . $dest );
}
- my $source = Subst_vars( $S->{'source'} );
+ my $source = Subst_vars( $ref_section->{'source'} );
if ( !-l $dest || ( -l $dest && readlink($dest) ne $source ) ) {
$cmp = 1;
@@ -1216,9 +989,9 @@
}
}
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
+ Do_on_config( $ref_section, $options ) && return 1;
+
+ Do_before_change( $ref_section, $options ) && return 1;
if ( !$options->{'simul'} ) {
Do_moveold( $dest, $options );
@@ -1230,30 +1003,30 @@
}
}
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
+ Do_after_change( $ref_section, $options ) && return 1;
+
+ Do_on_noaction( $ref_section, $options ) && return 1;
}
return 0;
};
$DEPENDS{'createfile'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
while ( $dest ne '/' && $dest ne '.' ) {
- $S->{'depends'} .= " " . dirname($dest);
+ $ref_section->{'depends'} .= " " . dirname($dest);
$dest = dirname($dest);
}
};
$FUNCTIONS{'createfile'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
my $cmp = 0;
$SUBST{'SECTIONNAME'} = $dest;
- if ( !defined $S->{'source'} ) {
+ if ( !defined $ref_section->{'source'} ) {
if ( !-f $dest ) {
$cmp = 1;
@@ -1261,9 +1034,9 @@
Log("(action needed)");
}
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
+ Do_on_config( $ref_section, $options ) && return 1;
+
+ Do_before_change( $ref_section, $options ) && return 1;
if ( !$options->{'simul'} ) {
@@ -1285,7 +1058,7 @@
my $source;
my $tmp;
- $source = Get_source( Subst_vars( $S->{'source'} ) );
+ $source = Get_source( Subst_vars( $ref_section->{'source'} ) );
$SUBST{'SOURCE'} = $source;
$tmp = Get_tmp_dest($dest);
@@ -1296,8 +1069,8 @@
return 1;
}
- if ( defined( $S->{'filter'} ) ) {
- my $filter = Subst_vars( $S->{'filter'} );
+ if ( defined( $ref_section->{'filter'} ) ) {
+ my $filter = Subst_vars( $ref_section->{'filter'} );
if ( deferredlogsystem($filter) ) {
Warn( $CODE->{'OPEN'}, "Impossible d'appliquer " . $filter );
return 1;
@@ -1328,9 +1101,9 @@
Log("(action needed)");
}
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
+ Do_on_config( $ref_section, $options ) && return 1;
+
+ Do_before_change( $ref_section, $options ) && return 1;
if ( !$options->{'simul'} ) {
@@ -1349,28 +1122,28 @@
}
}
- Do_chownmod( $S, $dest, $options );
+ Do_chownmod( $ref_section, $dest, $options );
if ($cmp) {
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
+ Do_after_change( $ref_section, $options ) && return 1;
+
+ Do_on_noaction( $ref_section, $options ) && return 1;
}
return 0;
};
$DEPENDS{'mkdir'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
while ( $dest ne '/' && $dest ne '.' ) {
- $S->{'depends'} .= " " . dirname($dest);
+ $ref_section->{'depends'} .= " " . dirname($dest);
$dest = dirname($dest);
}
};
$FUNCTIONS{'mkdir'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
my $cmp = 0;
@@ -1382,9 +1155,9 @@
Log("(action needed)");
}
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
+ Do_on_config( $ref_section, $options ) && return 1;
+
+ Do_before_change( $ref_section, $options ) && return 1;
if ( !$options->{'simul'} ) {
Do_moveold( $dest, $options );
@@ -1397,19 +1170,19 @@
}
}
- Do_chownmod( $S, $dest, $options );
+ Do_chownmod( $ref_section, $dest, $options );
if ($cmp) {
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
+ Do_after_change( $ref_section, $options ) && return 1;
+
+ Do_on_noaction( $ref_section, $options ) && return 1;
}
return 0;
};
$FUNCTIONS{'removefile'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
my $cmp = 0;
if ( -d $dest ) {
@@ -1424,9 +1197,9 @@
Log("(action needed)");
}
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
+ Do_on_config( $ref_section, $options ) && return 1;
+
+ Do_before_change( $ref_section, $options ) && return 1;
if ( !$options->{'simul'} ) {
@@ -1443,19 +1216,19 @@
}
# Mais bien sur
- #Do_chownmod( $S, $dest, $options );
+ #Do_chownmod( $ref_section, $dest, $options );
if ($cmp) {
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
+ Do_after_change( $ref_section, $options ) && return 1;
+
+ Do_on_noaction( $ref_section, $options ) && return 1;
}
return 0;
};
$FUNCTIONS{'removedir'} = sub {
- my ( $S, $dest, $options ) = @_;
+ my ( $ref_section, $dest, $options ) = @_;
my $cmp = 0;
if ( -e $dest && !-d $dest ) {
@@ -1470,9 +1243,9 @@
Log("(action needed)");
}
- Do_on_config( $S, $options ) && return 1;
-
- Do_before_change( $S, $options ) && return 1;
+ Do_on_config( $ref_section, $options ) && return 1;
+
+ Do_before_change( $ref_section, $options ) && return 1;
if ( !$options->{'simul'} ) {
@@ -1489,12 +1262,12 @@
}
# Mais bien sur
- #Do_chownmod( $S, $dest, $options );
+ #Do_chownmod( $ref_section, $dest, $options );
if ($cmp) {
- Do_after_change( $S, $options ) && return 1;
-
- Do_on_noaction( $S, $options ) && return 1;
+ Do_after_change( $ref_section, $options ) && return 1;
+
+ Do_on_noaction( $ref_section, $options ) && return 1;
}
return 0;
@@ -1536,361 +1309,80 @@
return $tmp;
}
-sub Get_source {
- my ($source) = @_;
-
- $source =~ s!^HOST:!$CVS_WORKING_DIR/$CVS_CONFIG/$HOSTTYPE!;
- $source =~ s!^CONFIG:!$CVS_WORKING_DIR/$CVS_CONFIG/!;
- $source =~ s!^CVS:!$CVS_WORKING_DIR/!;
- $source =~ s!^GLOBAL:!$GLOBAL_CONF/!;
- return $source;
+sub Get_depends_for_action ($$$$) {
+ my ( $action, $ref_section, $dest, $options ) = @_;
+
+ if ( $DEPENDS{$action} ) {
+ $DEPENDS{$action}->( $ref_section, $dest, $options );
+ }
+}
+
+sub Exec_action ($$$$) {
+ my ( $action, $ref_section, $dest, $options ) = @_;
+
+ return $FUNCTIONS{$action}->( $ref_section, $dest, $options );
}
sub Trie_prio {
- my ( $C, $a ) = @_;
-
- my $prio = 0;
-
- if ( $a eq "/etc/passwd" ) {
- return $prio;
- }
+ my ( $host_config, $section ) = @_;
+
+ my $prio = 0;
+ my $action = $host_config->{'section'}->{'action'};
+
+ # 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 =~ m|^/etc/apt/| );
+ $prio++;
+ return $prio if ( $section eq "pf-tools" );
+ $prio++;
+ return $prio if ( $action eq 'dpkg-purge' );
$prio++;
- if ( $a eq "/etc/group" ) {
- return $prio;
- }
+ return $prio if ( $action eq 'apt-get' );
$prio++;
- if ( $a eq "/etc/shadow" ) {
- return $prio;
- }
+ # Fourth : creations and adds for files and links
+ return $prio if ( $action eq 'createfile' );
$prio++;
- if ( $a eq "/etc/gshadow" ) {
- return $prio;
- }
+ return $prio if ( $action eq 'addfile' );
$prio++;
-
- if ( $C->{$a}->{'action'} eq 'mkdir' ) {
- return $prio;
- }
+ return $prio if ( $action eq 'addlink' );
$prio++;
- if ( $C->{$a}->{'action'} eq 'addmount' ) {
- return $prio;
- }
+
+ # Fifth : removing files and dirs
+ return $prio if ( $action =~ /^remove/ );
$prio++;
-
- if ( $a =~ m|^/etc/apt/| ) {
- return $prio;
- }
- $prio++;
- if ( $a eq "pf-tools" ) {
- return $prio;
- }
- $prio++;
-
- if ( $C->{$a}->{'action'} eq 'dpkg-purge' ) {
- return $prio;
- }
- $prio++;
- if ( $C->{$a}->{'action'} eq 'apt-get' ) {
- return $prio;
- }
- $prio++;
-
- if ( $C->{$a}->{'action'} eq 'createfile' ) {
- return $prio;
- }
- $prio++;
- if ( $C->{$a}->{'action'} eq 'addfile' ) {
- return $prio;
- }
- $prio++;
-
- if ( $C->{$a}->{'action'} eq 'addlink' ) {
- return $prio;
- }
-
- if ( $C->{$a}->{'action'} eq 'removefile' ) {
- return $prio;
- }
- if ( $C->{$a}->{'action'} eq 'removedir' ) {
- return $prio;
- }
- $prio++;
+
+ # Last : other elements
return $prio;
}
sub Trie_dependances {
- my ( $C, $a, $b ) = @_;
-
- my $prioa = Trie_prio( $C, $a );
- my $priob = Trie_prio( $C, $b );
+ my ( $host_config, $a, $b ) = @_;
+
+ my $prioa = Trie_prio ( $host_config, $a );
+ my $priob = Trie_prio( $host_config, $b );
if ( $prioa != $priob ) {
- return $prioa <=> $priob;
+ return $prioa <=> $priob;
}
else {
- return $a cmp $b;
- }
-}
-
-sub Do_updateloop {
- my ( $C, $options, @sortedkeys ) = @_;
- my $s;
- my $errorcount = 0;
-
- foreach $s (@sortedkeys) {
- if ( defined( $C->{$s} )
- && !defined( $C->{$s}->{'doing'} )
- && !defined( $C->{$s}->{'done'} ) )
- {
-
- $C->{$s}->{'doing'} = 1;
-
- if ( defined( $C->{$s}->{'action'} )
- && defined( $DEPENDS{ $C->{$s}->{'action'} } ) )
- {
- $DEPENDS{ $C->{$s}->{'action'} }->( $C->{$s}, $s, $options );
- }
-
- if ( defined( $C->{$s}->{'depends'} ) ) {
- my @dependsraw;
- my @depends;
- my $d;
-
- @dependsraw = split( /[ ,]+/, $C->{$s}->{'depends'} );
-
- foreach $d (@dependsraw) {
- if ( defined($d) && $d ne "" && defined( $C->{$d} ) ) {
- if ( $d eq $s ) {
- Warn ( $CODE->{'SYNTAX'},
- "["
- . $s
- . "] circular dependancy detected, skipping this depend"
- );
- FlushLog();
- next;
- }
- push @depends, $d;
- if ( $C->{$d}->{'action'} eq 'addmount' ) {
- Warn( $CODE->{'OPEN'},
- "["
- . $s
- . "] depends on addmount ["
- . $d
- . "], it may not work during install!" );
- FlushLog();
- }
- }
- }
-
- if ( $#depends >= 0 ) {
- Log( "<" . $s . "> " . join( ' ', @depends ) );
- $errorcount += Do_updateloop( $C, $options, @depends );
- }
- }
-
- Log( "[" . $s . "]" );
-
- if ( !defined( $C->{$s}->{'action'} ) ) {
- Abort( $CODE->{'SYNTAX'}, "Action non definie" );
- }
- if ( !defined( $FUNCTIONS{ $C->{$s}->{'action'} } ) ) {
- Abort( $CODE->{'SYNTAX'},
- "Action inconnue '" . $C->{$s}->{'action'} . "'" );
- }
-
- if ($FUNCTIONS{ $C->{$s}->{'action'} }->( $C->{$s}, $s, $options )
- )
- {
- FlushLog();
- $errorcount++;
- }
- else {
- DelLog();
- }
-
- $C->{$s}->{'done'} = 1;
- }
- }
-
- return $errorcount;
-}
-
-sub Do_update {
- my ($ref_options) = @_;
-
- my $C;
- my $s;
-
- # my $options;
- my @sortedkeys;
- my $errorcount = 0;
-
- # if ( $ref_options->{'help'} ) {
- # Do_help();
- # exit;
- # }
-
- my $branchecvs;
-
- # Si le demande a ma machine une branche precise
- $branchecvs
- = ( $ref_options->{"branche-cvs"} )
- ? $ref_options->{"branche-cvs"}
- : GetBrancheFromCmdLine();
-
- # Sinon je repart sur celle d'avant
- $branchecvs = GetRunningBrancheName() unless $branchecvs;
-
- if ( CVS_update( $branchecvs, $ref_options ) || ( !( $C = Get_conf() ) ) )
- {
- Abort( $CODE->{'OPEN'}, "Impossible de charger la configuration\n" );
- }
-
- SaveRunningBrancheName($branchecvs);
-
- if ( defined( $ref_options->{'noupdate'} ) ) {
- Abort( $CODE->{'OPEN'}, "Configuration desactivee [noupdate]" );
- }
-
- @sortedkeys = sort { Trie_dependances( $C, $a, $b ) } keys %$C;
-
- $| = 1;
- $errorcount = Do_updateloop( $C, $ref_options, @sortedkeys );
-
- Log( $errorcount . " error(s) detected." );
- FlushLog();
-}
-
-sub Get_conf {
-
- my $C = {};
- my $template;
- my $conf;
-
- $HOSTNAME =~ /^(.*?)(\d*)([a-z]*)$/;
-
-#$template = "update-" . $1 . "(" . $2 . "(" . $3 . ")?)?"; FAIT PLANTER PERL5.6 XXX
- $template = "update-" . $1 . "(" . $2 . "|" . $2 . $3 . ")?";
-
- opendir( CONFIG, Get_source("GLOBAL:") );
- foreach $conf ( $COMMON, sort grep ( /^$template$/, readdir(CONFIG) ) ) {
- my $c = Load_conf( Get_source( "GLOBAL:" . $conf ), \%SUBST, 'config' );
- foreach ( keys %$c ) {
- if ( $c->{$_}->{'action'} eq 'ignore' && !defined( $C->{$_} ) ) {
- Warn( $CODE->{'OPEN'},
- "ignoring previous inexistant [" . $_ . "] in " . $conf );
- }
- $C->{$_} = $c->{$_};
- }
- }
- closedir(CONFIG);
-
- return $C;
-}
-
-# Enregsitre le nom de la branche utilise actuellement dans le dossier
-# PF_STATUS_DIR, le but de ce fichier est de permettre a update-config
-# retrouver la branche du CVS qu'il doit MAJ.
-sub SaveRunningBrancheName($) {
-
- `mkdir -p $PF_STATUS_DIR` unless ( -d $PF_STATUS_DIR );
- my $branche = shift;
- open STATUSBRANCHE, ">$PF_STATUS_DIR" . "/branche";
- print STATUSBRANCHE $branche if $branche;
- close STATUSBRANCHE;
-
-}
-
-sub GetRunningBrancheName {
-
- return unless ( -r $PF_STATUS_DIR . "/branche" );
-
- open STATUSBRANCHE, "<$PF_STATUS_DIR" . "/branche";
-
- my @STATUSBRANCHE = <STATUSBRANCHE>;
-
- close STATUSBRANCHE;
- return shift @STATUSBRANCHE;
-
-}
-
-# Si une branche a été passée en para, elle est retournée sinon undef.
-sub GetBrancheFromCmdLine {
-
- my $branche;
- open CMDLINE, "</proc/cmdline";
- $branche = $1 if ( <CMDLINE> =~ /pfbcvs=(\S+)/ );
-
- close CMDLINE;
-
- return $branche;
-
-}
-
-# MAJ le CVS, peut mettre une branche précise à jour, en passant le nom
-# de cette branche en paramètre
-sub CVS_update (;$$) {
- my ( $branche, $options ) = @_;
-
- if ($branche) {
- if ( defined $CVS_COMMAND ) {
- print
- "Attention : j'ignore la variable \$CVS_COMMAND définie dans "
- . "`$PFTOOLSCONF' car j'utilise une branche précise ($branche)\n"
- if defined $options and $options->{verbose};
- undef $CVS_COMMAND;
- }
- $CVS_BRANCHE = $branche;
- }
-
- my $ret;
- my $umask = umask($CVS_UMASK);
- my $olddeferredlog;
-
- $ENV{'CVS_RSH'} = $CVS_RSH;
-
- # CVS_COMMAND peut deja etre def dans /etc/pf-tools.conf
- unless ( defined($CVS_COMMAND) and ($CVS_COMMAND) ) {
- if ( $HOSTNAME =~ /^deploy\d+/ or -d "/vol" ) {
- $CVS_COMMAND = "/usr/bin/cvs -R -d '";
- }
- else {
- $CVS_COMMAND
- = "/usr/bin/cvs -d ':ext:"
- . $CVS_USER . "\@"
- . $CVS_SERVER . ":";
- }
-
- $CVS_COMMAND .= $CVS_REPOSITORY . "'";
-
- $CVS_COMMAND .= " checkout ";
- $CVS_COMMAND .= " -r $CVS_BRANCHE" if ($CVS_BRANCHE);
-
- $CVS_COMMAND .= " $CVS_CONFIG";
-
- }
-
- print $CVS_COMMAND. "\n" if $options->{'debug'} or $options->{'verbose'};
-
- system( "/bin/mkdir -p '" . $CVS_WORKING_DIR . "' 2>/dev/null" );
-
- $olddeferredlog = $DEFERREDLOG;
- $DEFERREDLOG = 1;
- $ret = deferredlogsystem(
- "cd '" . $CVS_WORKING_DIR . "';" . $CVS_COMMAND );
- $DEFERREDLOG = $olddeferredlog;
-
- if ($ret) {
- FlushLog();
- }
- else {
- DelLog();
- }
-
- umask($umask);
- return $ret;
+ return $a cmp $b;
+ }
}
1;
-
Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=800&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Wed Aug 4 15:29:33 2010
@@ -57,6 +57,8 @@
use PFTools::Net;
use PFTools::Conf;
use PFTools::Host;
+use PFTools::Update;
+use PFTools::VCS;
use Data::Dumper;
use Template::Tiny;
use File::Compare;
@@ -68,6 +70,7 @@
# Prototypes : needed by recursive calls
sub Resolv_hostname_from_GLOBAL ($$;$$);
+sub __Do_updateloop ($$$);
#########################################################################
# Functions
@@ -209,8 +212,8 @@
}
}
-sub Build_preseed_filename ($$$$$) {
- my ( $srv_name, $preseed_tpl, $host_props, $default_preseed, $pf_script ) = @_ ;
+sub Build_preseed_filename ($$$$$$) {
+ my ( $srv_name, $preseed_tpl, $host_props, $default_preseed, $pf_script, $pf_config ) = @_ ;
if ( ! open ( PRESEED_TPL, $preseed_tpl ) ) {
Warn ( $CODE->{'OPEN'},
@@ -237,7 +240,7 @@
print DST_PRESEED $preseed_content ;
close ( DST_PRESEED ) ;
my $src = "/tmp/tmp_preseed" ;
- my $dst = $PF_CONFIG->{'path'}->{'preseed_dir'}."/preseed_".$srv_name ;
+ my $dst = $pf_config->{'path'}->{'preseed_dir'}."/preseed_".$srv_name ;
if ( compare ( $src, $dst ) ) {
move ($src, $dst) ;
} else {
@@ -249,20 +252,20 @@
return "preseed_".$srv_name ;
}
-sub Get_MD5SUM_for_preseedfile ($) {
- my ( $filename ) = @_;
+sub Get_MD5SUM_for_preseedfile ($$) {
+ my ( $filename, $pf_config ) = @_;
my ( $md5, $hdl );
$md5 = Digest::MD5->new;
- open $hdl, $PF_CONFIG->{'path'}->{'preseed_dir'}."/".$filename || return undef;
+ open $hdl, $pf_config->{'path'}->{'preseed_dir'}."/".$filename || return undef;
$md5->addfile ( $hdl );
my $md5sum = $md5->hexdigest;
close ( $hdl );
return $md5sum;
}
-sub Mk_PXE_bootfile ($$$$$$) {
- my ( $hostname, $host_props, $pxe_tpl, $preseed_tpl, $default_preseed, $pf_script ) = @_;
+sub Mk_PXE_bootfile ($$$$$$$) {
+ my ( $hostname, $host_props, $pxe_tpl, $preseed_tpl, $default_preseed, $pf_script, $pf_config ) = @_;
my $iface = Get_iface_vlan_from_hostname ( $host_props->{'deployment'}->{'dhcpvlan'}, $host_props );
my $mac = $host_props->{'interfaces'}->{$iface}->{'mac'};
@@ -279,8 +282,8 @@
}
my $content_pxe = join ( "", <PXETPL> );
close ( PXETPL );
- my $preseed = Build_preseed_filename ( $hostname, $preseed_tpl, $host_props, $default_preseed, $pf_script );
- my $preseed_md5 = Get_MD5SUM_for_preseedfile ( $preseed );
+ my $preseed = Build_preseed_filename ( $hostname, $preseed_tpl, $host_props, $default_preseed, $pf_script, $pf_config );
+ my $preseed_md5 = Get_MD5SUM_for_preseedfile ( $preseed, $pf_config );
my $tpl = Template::Tiny->new ( TRIM => 1 );
my $pxe_subst = {
'iface' => $iface,
@@ -299,7 +302,7 @@
$pxe_subst->{'initrd'} = $host_props->{'boot'}->{'initrd'};
}
else {
- $content_pxe =~ s/initrd=(([^\/]+\/)+)?\[% initrd %\]//gs ;
+ $content_pxe =~ s/initrd=(([^\/]+\/)+)?\[%\s*initrd\s*%\]//gs ;
}
$content_pxe = $tpl->process ( \$content_pxe, $pxe_subst );
if ( ! open ( PXETMP, ">/tmp/tmp_pxe" ) ) {
@@ -310,7 +313,7 @@
print PXETMP $content_pxe;
close ( PXETMP );
my $src = "/tmp/tmp_pxe" ;
- my $dst = $PF_CONFIG->{'path'}->{'pxefiles_dir'}."/".$pxe_boot_file ;
+ my $dst = $pf_config->{'path'}->{'pxefiles_dir'}."/".$pxe_boot_file ;
if ( compare ( $src, $dst ) ) {
move ($src, $dst) ;
} else {
@@ -772,8 +775,8 @@
return 0 ;
}
-sub Change_kopt_for_hostname ($$$$$$) {
- my ( $hostname, $site, $grub_src, $dst, $grub_version, $global_config ) = @_;
+sub Change_kopt_for_hostname ($$$$$$$) {
+ my ( $hostname, $site, $grub_src, $dst, $grub_version, $global_config, $pf_config ) = @_;
my $tmp_grub = [];
my ( $cmd_line );
@@ -786,7 +789,7 @@
my ( $cmdline, $bond_cmdline ) = Get_cmdline_from_hostprops ( $host_props );
$grub_version = "" if ( $grub_version == 1 );
- $grub_src = $PF_CONFIG->{$mode}->{'grub'.$grub_version} if ( $grub_src eq '' );
+ $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" );
@@ -924,4 +927,83 @@
return $interfaces;
}
+sub __Do_updateloop ($$$$) {
+ my ( $host_config, $options, $hash_subst, @sortedkeys ) = @_;
+ my $errorcount = 0;
+
+ foreach $section (@sortedkeys) {
+ if ( defined( $host_config->{$section} )
+ && ! defined( $host_config->{$section}->{'doing'} )
+ && ! defined( $host_config->{$section}->{'done'} )
+ ) {
+ $host_config->{$section}->{'doing'} = 1;
+ Get_depends_for action ( $host_config->{$section}->{'action'}, $host_config->{$section}, $section, $options );
+ if ( defined( $host_config->{$section}->{'depends'} ) ) {
+ my @dependsraw;
+ my @depends;
+ my $d;
+ @dependsraw = split( /[ ,]+/, $host_config->{$section}->{'depends'} );
+ foreach $depend (@dependsraw) {
+ if ( defined($depend) && $depend ne "" && defined( $host_config->{$depend} ) ) {
+ if ( $depend eq $section ) {
+ Warn ( $CODE->{'SYNTAX'},
+ "[".$section."] circular dependancy detected, skipping this depend" );
+ FlushLog();
+ next;
+ }
+ push @depends, $depend;
+ if ( $host_config->{$depend}->{'action'} eq 'addmount' ) {
+ Warn( $CODE->{'OPEN'},
+ "[".$section."] depends on addmount [".$d."], it may not work during install!" );
+ FlushLog();
+ }
+ }
+ }
+ if ( $#depends >= 0 ) {
+ Log ( "<".$section."> ".join( ' ', @depends ) );
+ $errorcount += __Do_updateloop( $host_config, $options, $hash_subst, @depends );
+ }
+ }
+ Log( "[".$section."]" );
+ if ( Exec_action ( $host_config->{$section}->{'action'}, $host_config->{$section}, $section, $options, $hash_subst ) ) {
+ FlushLog();
+ $errorcount++;
+ }
+ else {
+ DelLog();
+ }
+ $host_config->{$section}->{'done'} = 1;
+ }
+ }
+ return $errorcount;
+}
+
+sub Do_update_from_GLOBAL ($$$$$$) {
+ my ( $hostname, $site, $options, $hash_subst, $global_config, $pf_config ) = @_;
+
+ if ( ! VCS_Update ( $hostname, $pf_config, $options, $options->{'branche'} ) ) {
+ Abort ( $CODE->{'EXEC'},
+ "Unable to checkout configuration from VCS system" );
+ }
+
+ my $host_config = Get_config_for_hostname_on_site ( $hostname, $site, $hash_subst, $global_config, $pf_config );
+ if ( ! defined $host_config ) {
+ Abort( $CODE->{'OPEN'},
+ "Unable to parse configuration for hostname ".$hostname." in site ".$site );
+ }
+
+ if ( ! $pf_config->{'features'}->{'update'} ) {
+ Abort( $CODE->{'OPEN'},
+ "Unable to update configuration : update feature is deactivated in pf-tools configuration file" );
+ }
+
+ @sortedkeys = sort { Trie_dependances( $host_config, $a, $b ) } $host_config->{'__sections_order'} ;
+
+ $| = 1;
+ $errorcount = __Do_updateloop ( $host_config, $options, $hash_subst, @sortedkeys );
+
+ Log( $errorcount . " error(s) detected." );
+ FlushLog();
+}
+
1;
Modified: branches/next-gen/sbin/mk_grubopt
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_grubopt?rev=800&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_grubopt (original)
+++ branches/next-gen/sbin/mk_grubopt Wed Aug 4 15:29:33 2010
@@ -125,7 +125,7 @@
"Site ".$SITE." is not defined into global configuration" );
}
-if ( ! Change_kopt_for_hostname ( $HOSTNAME, $SITE, $MENU_GRUB, $OUTPUT, $GRUB_VERSION, $GLOBAL_STRUCT ) ) {
+if ( ! Change_kopt_for_hostname ( $HOSTNAME, $SITE, $MENU_GRUB, $OUTPUT, $GRUB_VERSION, $GLOBAL_STRUCT, $PF_CONFIG ) ) {
Abort ( $CODE->{'EXEC'},
"Unable to change kernel options(s) into file ".$MENU_GRUB );
}
Modified: branches/next-gen/sbin/mk_pxelinuxcfg
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_pxelinuxcfg?rev=800&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_pxelinuxcfg (original)
+++ branches/next-gen/sbin/mk_pxelinuxcfg Wed Aug 4 15:29:33 2010
@@ -110,7 +110,7 @@
my $mode = $host_part->{$hostclass}->{$host}->{'deployment'}->{'mode'};
my $pxe_template = $PF_CONFIG->{'path'}->{'templates_dir'}.'/'.$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 );
+ my $pxe_file = Mk_PXE_bootfile ( $host, $host_part->{$hostclass}->{$host}, $pxe_template, $preseed_tpl, $DEFAULT_PRESEED, $PF_SCRIPT, $PF_CONFIG );
}
}
More information about the pf-tools-commits
mailing list