pf-tools commit: r829 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Update.pm lib/PFTools/Update/Addmount.pm lib/PFTools/Update/Mkdir.pm lib/PFTools/Update/Purgepkg.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Aug 18 14:42:04 UTC 2010
Author: ccaillet-guest
Date: Wed Aug 18 14:42:02 2010
New Revision: 829
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=829
Log:
* lib/PFTools/Update/Purgepkg.pm
- extrating apt-get functions (action and depends) from Update.pm
* lib/PFTools/Update/Mkdir.pm
- extrating apt-get functions (action and depends) from Update.pm
* lib/PFTools/Update/Addmount.pm
- extrating apt-get functions (action and depends) from Update.pm
Added:
branches/next-gen/lib/PFTools/Update/Addmount.pm (with props)
branches/next-gen/lib/PFTools/Update/Mkdir.pm (with props)
branches/next-gen/lib/PFTools/Update/Purgepkg.pm (with props)
Modified:
branches/next-gen/debian/changelog
branches/next-gen/lib/PFTools/Update.pm
Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=829&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Wed Aug 18 14:42:02 2010
@@ -19,10 +19,16 @@
- extrating addfile functions (action and depends) from Update.pm
* lib/PFTools/Update/Installpkg.pm
- extrating apt-get functions (action and depends) from Update.pm
+ * lib/PFTools/Update/Purgepkg.pm
+ - extrating apt-get functions (action and depends) from Update.pm
+ * lib/PFTools/Update/Mkdir.pm
+ - extrating apt-get functions (action and depends) from Update.pm
+ * lib/PFTools/Update/Addmount.pm
+ - extrating apt-get functions (action and depends) from Update.pm
* debian/control
- adding libtext-diff-perl as depends for pf-tools package
- -- Christophe Caillet <quadchris at free.fr> Thu, 12 Aug 2010 23:41:45 +0200
+ -- Christophe Caillet <quadchris at free.fr> Wed, 18 Aug 2010 16:39:59 +0200
pf-tools (0.99.98-1) unstable; urgency=low
Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=829&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Wed Aug 18 14:42:02 2010
@@ -43,6 +43,9 @@
use PFTools::Update::Common;
use PFTools::Update::Addfile;
use PFTools::Update::Installpkg;
+use PFTools::Update::Purgepkg;
+use PFTools::Update::Mkdir;
+use PFTools::Update::Addmount;
use PFTools::Logger;
use PFTools::Parser;
use PFTools::Net;
@@ -66,8 +69,8 @@
###########################################
### Constants
-my $DEFAULT_FSTYPE = 'nfs';
-my $DEFAULT_OPTIONS = 'defaults,noexec,nosuid,nodev,hard,intr';
+# my $DEFAULT_FSTYPE = 'nfs';
+# my $DEFAULT_OPTIONS = 'defaults,noexec,nosuid,nodev,hard,intr';
my $APT_UPDATE = 1;
# my $APT_GET = 'LANG=C LC_ALL=C /usr/bin/apt-get -y --force-yes';
# my $APT_GET_DEPENDS = 'LANG=C LC_ALL=C /usr/bin/apt-get -y --force-yes -s -u';
@@ -78,510 +81,6 @@
my %DEPENDS;
my %FUNCTIONS;
-
-# $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, $global_config ) = @_;
-# my ( $source, $tmp, $cmp );
-#
-# my $diff = 0;
-# $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 );
-# }
-#
-# $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'},
-# "Unable to copy file " . $tmp . " to " . $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 ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
-
- $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 ( $options->{'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( $ref_section, $options, $hash_subst ) && return 1;
- Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
- if ( !$options->{'simul'} ) {
- if ( ! Purge_pkg ( $options->{'pkg_type'}, $dest ) ) {
- Warn ( $CODE->{'OPEN'}, "An error occured during purge for package ".$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;
-# }
-
-# $DEPENDS{'apt-get'} = sub ($$$) {
-# my ( $ref_section, $dest, $options ) = @_;
-#
-# $options->{'pkg_type'} = 'deb' if ( ! defined $options->{'pkg_type'} ) ;
-# if ( aptupdate( $options->{'pkg_type'} ) ) {
-# return 1;
-# }
-# my $deps = Get_pkg_depends ( $options->{'pkg_type'}, $dest ) ;
-# if ( ! defined $deps ) {
-# Warn ( $CODE->{'OPEN'}, "Unable to get depends for package ".$dest ) ;
-# return 1;
-# }
-# else {
-# $ref_section->{'depends'} = $dest ;
-# }
-# };
-#
-# $FUNCTIONS{'apt-get'} = sub ($$$$) {
-# my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
-#
-# $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( $options->{'pkg_type'} );
-# ( $installed_version, $available_version, $specified_version ) = Get_pkg_policy ( $options->{'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 ( $options->{'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'} ) {
-# $hash_subst->{'HOSTNAME'} =~ /\d+$/;
-# if ( $& ne "" ) {
-# sleep( 120 * $& );
-# }
-# }
-# if ( ! $options->{'simul'} ) {
-# my $debconf = 0;
-# my $debconf_vars = {};
-# foreach my $key ( keys %{$ref_section} ) {
-# next if ( $key !~ /^debconf/ );
-# $debconf = 1;
-# $key =~ /^debconf\.(.*)$/;
-# $debconf_vars->{$1} = $ref_section->{$key};
-# }
-# if ( $debconf ) {
-# my $DEB;
-# my $conf;
-# my $pkg;
-# my $pf_config = Init_PF_CONFIG ();
-# my $vcs_tpl_dir = $pf_config->{'path'}->{'checkout_dir'}.'/TEMPLATES';
-# Debconf::Db->load;
-# foreach $conf ( keys %{ $ref_section->{'debconf'} } ) {
-# ($pkg) = split( m:/:, $conf );
-# if ( !$DEB->{$pkg} ) {
-# $DEB->{$pkg} = 1;
-# Debconf::Template->load( $vcs_tpl_dir."/".$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 ( $options->{'pkg_type'}, $dest, $ref_section->{'version'} ) ) {
-# Warn( $CODE->{'OPEN'}, "Unable to install ".$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;
-# };
-
-$DEPENDS{'addmount'} = sub ($$$) {
- my ( $ref_section, $dest, $options ) = @_;
-
- while ( $dest ne "/" && $dest ne "." ) {
- $ref_section->{'depends'} .= " " . dirname ( $dest );
- $dest = dirname ( $dest );
- }
-};
-
-sub __Get_ip_host_from_GLOBAL ($$) {
- my ( $host, $global_config ) = @_;
-
- my $ip = $host;
- my $zone = Get_zone_from_hostname ( $host, $global_config );
- if ( ! defined $zone ) {
- Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve zone for hostname ".$host );
- return undef;
- }
- $ip =~ s/\.$zone$//;
- $host =~ /^([^.]+)(\.([^.]+))?$/;
- my ( $hostshort, $hostvlan ) = ( $1, $3 );
- my $hosttype = Get_hosttype_from_hostname ( $hostshort, $global_config );
- if ( ! defined $hosttype ) {
- Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve hosttype for hostname ".$host );
- return undef;
- }
- my $site_list = Get_site_from_hostname ( $hostshort, $global_config );
- my $site;
- if ( ! defined $site_list || scalar @{$site_list} > 1 ) {
- Warn ( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname ".$host." : unknown or multiple declaration" );
- return undef;
- }
- else {
- $site = shift @{$site_list};
- }
- if ( ! isipaddr ( $host ) ) {
- my $resolved = Resolv_hostname_from_GLOBAL ( $host, $global_config, $zone, $site, $hosttype );
- if ( ! defined $resolved ) {
- Warn ( $CODE->{'RESOLV'}, "Unknown host ".$host );
- return undef;
- }
- elsif ( scalar @{$resolved} > 1 ) {
- Warn ( $CODE->{'RESOLV'}, "Multiple response for ".$host." : unable to choose the right one" );
- return undef;
- }
- else {
- $ip = shift @{$resolved};
- }
- }
- return $ip
-}
-
-sub __Resolve_fstab_entry ($) {
- my ( $param ) = @_;
-
- my $pf_config = Init_PF_CONFIG ();
- my $fs_entry = $param->{'fs_entry'};
- if ( $fs_entry->{'fstype'} =~ /^$pf_config->{'regex'}->{'network_fstype'}$/ ) {
- foreach my $key ( 'source', 'options' ) {
- my $value = ( $key eq 'options' )
- ? $fs_entry->{$key} || $DEFAULT_OPTIONS
- : $fs_entry->{$key};
- my $val_addr = $value;
- $val_addr =~ ( $key eq 'options' )
- ? s/^(.*,)?ip=([^,]+)(,.*)?$/$2/
- : s/^([^:]+):(.+)$/$1/;
- my $val_ip = __Get_ip_host_from_GLOBAL ( $val_addr, $param->{'global_config'} ) if ( $val_addr );
- return 1 if ( ! defined $val_ip );
- $value =~ ( $key eq 'options' )
- ? s/^(.*,)?ip=([^,]+)(,.*)?$/$1ip=$val_ip$3/
- : s/^([^:]+):(.+)$/$val_ip:$2/;
- $fs_entry->{$key} = $value;
- }
- }
- return 0;
-}
-
-sub __Build_fstab_entry_from_config {
- my ( $param ) = @_;
-
- my $fs_entry = $param->{'ref_section'};
- $fs_entry->{'dest'} = $param->{'dest'};
- foreach my $key ( 'source', 'options' ) {
- $fs_entry->{$key} = Subst_vars ( $fs_entry->{$key}, $param->{'subst'} );
- }
- my $resolve_param = {
- 'fs_entry' => $fs_entry,
- 'global_config' => $param->{'global_config'}
- };
- if ( __Resolve_fstab_entry ( $resolve_param ) ) {
- return undef;
- };
- return $fs_entry;
-}
-
-$FUNCTIONS{'addmount'} = sub ($$$$$) {
- my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
-
- $hash_subst->{'SECTIONNAME'} = $dest;
- # Source
- my $add_mount = __Build_fstab_entry_from_config (
- {
- 'dest' => $dest,
- 'subst' => $hash_subst,
- 'global_config' => $global_config,
- 'ref_section' => $ref_section
- }
- );
- return 1 if ( ! defined $add_mount );
- $hash_subst->{'SOURCE'} = $add_mount->{'source'};
- $hash_subst->{'OPTIONS'} = join ( ',', sort split ( ',', $add_mount->{'options'} ) );
- $hash_subst->{'FSTYPE'} = $ref_section->{'fstype'} || $DEFAULT_FSTYPE;
-
- my $current_fstab = Build_structure_from_fstab ( "/etc/fstab" );
- if ( ! defined $current_fstab ) {
- Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /etc/fstab" );
- return undef;
- }
- my $current_proc = Build_structure_from_fstab ( "/proc/mounts" );
- if ( ! defined $current_fstab ) {
- Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /etc/fstab" );
- return undef;
- }
- my $addfstab = 0;
- if ( ! defined $current_fstab->{$dest} ) {
- $current_fstab->{$dest} = $add_mount;
- $addfstab = 1;
- }
- else {
- foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
- $addfstab = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
- }
- }
-
- my $addproc = 0;
- if ( ! defined $current_proc->{$dest} ) {
- $addproc = 1;
- }
- else {
- my $fs_proc = $current_proc->{$dest};
- foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
- if ( $key eq 'options' ) {
- $addproc = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
- }
- else {
- $addproc = 1 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
- }
- }
- }
-
- if ( $addfstab || $addproc || ! -d $dest ) {
- 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 ( ! -d $dest && $dest ne 'none' ) {
- if ( ! defined ( $FUNCTIONS{'mkdir'} ) ) {
- Warn( $CODE->{'OPEN'}, "Function mkdir is needed by addmount" );
- return 1;
- }
- $FUNCTIONS{'mkdir'}->( $ref_section, $dest, $options, $hash_subst );
- }
- if ( $addfstab ) {
- my $tmp = Get_tmp_dest("/etc/fstab");
- unless ( open ( NEWFSTAB, ">".$tmp ) ) {
- Warn( $CODE->{'OPEN'}, "Impossible de creer " . $tmp );
- return 1;
- }
- $current_fstab->{$dest} = $add_mount;
- my $new_fstab = Build_fstab_from_structure ( $current_fstab );
- print NEWFSTAB join ( "", @{$new_fstab} );
- close ( NEWFSTAB );
- if ( $options->{'diff'} ) {
- deferredlogsystem( "diff -uN '/etc/fstab' '" . $tmp . "'" );
- }
- if ( ! $options->{'simul'} ) {
- if ( ! move ( $tmp, "/etc/fstab" ) ) {
- Warn( $CODE->{'OPEN'}, "Unable to move new fstab ".$tmp." to /etc/fstab" );
- return 1;
- }
- }
- }
- if ( $addproc ) {
- if ( $options->{'diff'} ) {
- foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
- my $value = $current_proc->{$dest}->{$key} || '?';
- if ( $key eq 'options' ) {
- Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $current_fstab->{$dest}->{$key} ne $add_mount->{$key} );
- }
- else {
- Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $value ne $add_mount->{$key} );
- }
- }
- }
- if ( ! $options->{'simul'} && ! $options->{'noaction'} ) {
- # Unmounting fs
- my $remount = 1;
- foreach my $key ( 'source', 'dest', 'fstype' ) {
- $remount = 0 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
- }
- if ( $remount ) {
- my $cmd = "mount -o 'remount,".$add_mount->{'options'}."' '".$dest."'";
- if ( deferredlogsystem( $cmd ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable to remount ".$dest." with options ".$add_mount->{'options'} );
- return 1;
- }
- }
- else {
- my $umount = ( $add_mount->{'source'} ne $current_proc->{$dest}->{'source'} )
- ? $current_proc->{$dest}->{'source'}
- : $add_mount->{'source'};
- if ( deferredlogsystem( "umount '".$umount."'" ) ) {
- Warn ( $CODE->{'OPEN'}, "Unable to unmount ".$umount );
- return 1;
- }
- my $mount_cmd = "mount -t '".$add_mount->{'fstype'}."' - o '".$add_mount->{'options'}."' '"
- .$add_mount->{'source'}."' '".$add_mount->{'dest'}."'";
- if ( deferredlogsystem ( $mount_cmd ) ) {
- Warn ( $CODE->{'EXEC'}, "Unable to mount ".$dest." with command ".$mount_cmd );
- return 1;
- }
- }
- }
- }
- Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
- Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
- }
- return 0;
-};
$FUNCTIONS{'ignore'} = sub ($$$$$) {
my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
@@ -709,45 +208,6 @@
}
}
Do_chownmod ( $ref_section, $dest, $options );
- if ( $cmp ) {
- Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
- Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
- }
- return 0;
-};
-
-$DEPENDS{'mkdir'} = sub ($$$) {
- my ( $ref_section, $dest, $options ) = @_;
-
- while ( $dest ne "/" && $dest ne "." ) {
- $ref_section->{'depends'} .= " " . dirname($dest);
- $dest = dirname($dest);
- }
-};
-
-$FUNCTIONS{'mkdir'} = sub ($$$$$) {
- my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
-
- my $cmp = 0;
-
- $hash_subst->{'SECTIONNAME'} = $dest;
- if ( ! -d $dest ) {
- $cmp = 1;
- 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'} ) {
- Do_moveold( $dest, $options );
- if ( deferredlogsystem( "/bin/mkdir -p '" . $dest . "'" ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable to create directory ".$dest );
- return 1;
- }
- }
- }
- Do_chownmod( $ref_section, $dest, $options );
if ( $cmp ) {
Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
@@ -848,6 +308,12 @@
elsif ( $action eq "apt-get" || $action eq "" ) {
Installpk_depends ( $ref_section, $dest, $options );
}
+ elsif ( $action eq "mkdir" ) {
+ Mkdir_depends ( $ref_section, $dest, $options );
+ }
+ elsif ( $action eq "addmount" ) {
+ Addmount_depends ( $ref_section, $dest, $options );
+ }
elsif ( $DEPENDS{$action} ) {
$DEPENDS{$action}->( $ref_section, $dest, $options );
}
@@ -866,6 +332,9 @@
}
return Installpkg_action ( $ref_section, $dest, $options, $hash_subst, $global_config ) if ( $action eq "apt-get" || $action eq "installpkg" );
}
+ return Purgepkg_action ( $ref_section, $dest, $options, $hash_subst, $global_config ) if ( $action eq "dpkg-purge" || $action eq "purgepkg" );
+ return Mkdir_action ( $ref_section, $dest, $options, $hash_subst, $global_config ) if ( $action eq "mkdir" );
+ return Addmount_action ( $ref_section, $dest, $options, $hash_subst, $global_config ) if ( $action eq "addmount" );
return $FUNCTIONS{$action}->( $ref_section, $dest, $options, $hash_subst, $global_config );
}
Added: branches/next-gen/lib/PFTools/Update/Addmount.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Addmount.pm?rev=829&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Addmount.pm (added)
+++ branches/next-gen/lib/PFTools/Update/Addmount.pm Wed Aug 18 14:42:02 2010
@@ -1,0 +1,283 @@
+package PFTools::Update::Addmount;
+##
+## $Id$
+##
+## 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 Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+ Addmount_depends
+ Addmount_action
+);
+
+our @EXPORT_OK = qw();
+
+use File::Compare;
+use File::Copy;
+use Text::Diff;
+use PFTools::Logger;
+use PFTools::Conf;
+use PFTools::Update::Common;
+use PFTools::Update::Mkdir;
+
+###############################################
+# Constants
+
+my $DEFAULT_FSTYPE = 'nfs';
+my $DEFAULT_OPTIONS = 'defaults,noexec,nosuid,nodev,hard,intr';
+
+
+###############################################
+# Functions
+
+sub Addmount_depends ($$$) {
+ my ( $ref_section, $dest, $options ) = @_;
+
+ while ( $dest ne "/" && $dest ne "." ) {
+ $ref_section->{'depends'} .= " " . dirname ( $dest );
+ $dest = dirname ( $dest );
+ }
+}
+
+sub __Get_ip_host_from_GLOBAL ($$) {
+ my ( $host, $global_config ) = @_;
+
+ my $ip = $host;
+ my $zone = Get_zone_from_hostname ( $host, $global_config );
+ if ( ! defined $zone ) {
+ Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve zone for hostname ".$host );
+ return undef;
+ }
+ $ip =~ s/\.$zone$//;
+ $host =~ /^([^.]+)(\.([^.]+))?$/;
+ my ( $hostshort, $hostvlan ) = ( $1, $3 );
+ my $hosttype = Get_hosttype_from_hostname ( $hostshort, $global_config );
+ if ( ! defined $hosttype ) {
+ Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve hosttype for hostname ".$host );
+ return undef;
+ }
+ my $site_list = Get_site_from_hostname ( $hostshort, $global_config );
+ my $site;
+ if ( ! defined $site_list || scalar @{$site_list} > 1 ) {
+ Warn ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$host." : unknown or multiple declaration" );
+ return undef;
+ }
+ else {
+ $site = shift @{$site_list};
+ }
+ if ( ! isipaddr ( $host ) ) {
+ my $resolved = Resolv_hostname_from_GLOBAL ( $host, $global_config, $zone, $site, $hosttype );
+ if ( ! defined $resolved ) {
+ Warn ( $CODE->{'RESOLV'}, "Unknown host ".$host );
+ return undef;
+ }
+ elsif ( scalar @{$resolved} > 1 ) {
+ Warn ( $CODE->{'RESOLV'}, "Multiple response for ".$host." : unable to choose the right one" );
+ return undef;
+ }
+ else {
+ $ip = shift @{$resolved};
+ }
+ }
+ return $ip
+}
+
+sub __Resolve_fstab_entry ($) {
+ my ( $param ) = @_;
+
+ my $pf_config = Init_PF_CONFIG ();
+ my $fs_entry = $param->{'fs_entry'};
+ if ( $fs_entry->{'fstype'} =~ /^$pf_config->{'regex'}->{'network_fstype'}$/ ) {
+ foreach my $key ( 'source', 'options' ) {
+ my $value = ( $key eq 'options' )
+ ? $fs_entry->{$key} || $DEFAULT_OPTIONS
+ : $fs_entry->{$key};
+ my $val_addr = $value;
+ $val_addr =~ ( $key eq 'options' )
+ ? s/^(.*,)?ip=([^,]+)(,.*)?$/$2/
+ : s/^([^:]+):(.+)$/$1/;
+ my $val_ip = __Get_ip_host_from_GLOBAL ( $val_addr, $param->{'global_config'} ) if ( $val_addr );
+ return 1 if ( ! defined $val_ip );
+ $value =~ ( $key eq 'options' )
+ ? s/^(.*,)?ip=([^,]+)(,.*)?$/$1ip=$val_ip$3/
+ : s/^([^:]+):(.+)$/$val_ip:$2/;
+ $fs_entry->{$key} = $value;
+ }
+ }
+ return 0;
+}
+
+sub __Build_fstab_entry_from_config {
+ my ( $param ) = @_;
+
+ my $fs_entry = $param->{'ref_section'};
+ $fs_entry->{'dest'} = $param->{'dest'};
+ foreach my $key ( 'source', 'options' ) {
+ $fs_entry->{$key} = Subst_vars ( $fs_entry->{$key}, $param->{'subst'} );
+ }
+ my $resolve_param = {
+ 'fs_entry' => $fs_entry,
+ 'global_config' => $param->{'global_config'}
+ };
+ if ( __Resolve_fstab_entry ( $resolve_param ) ) {
+ return undef;
+ };
+ return $fs_entry;
+}
+
+sub Addmount_action ($$$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+ $hash_subst->{'SECTIONNAME'} = $dest;
+ # Source
+ my $add_mount = __Build_fstab_entry_from_config (
+ {
+ 'dest' => $dest,
+ 'subst' => $hash_subst,
+ 'global_config' => $global_config,
+ 'ref_section' => $ref_section
+ }
+ );
+ return 1 if ( ! defined $add_mount );
+ $hash_subst->{'SOURCE'} = $add_mount->{'source'};
+ $hash_subst->{'OPTIONS'} = join ( ',', sort split ( ',', $add_mount->{'options'} ) );
+ $hash_subst->{'FSTYPE'} = $ref_section->{'fstype'} || $DEFAULT_FSTYPE;
+
+ my $current_fstab = Build_structure_from_fstab ( "/etc/fstab" );
+ if ( ! defined $current_fstab ) {
+ Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /etc/fstab" );
+ return undef;
+ }
+ my $current_proc = Build_structure_from_fstab ( "/proc/mounts" );
+ if ( ! defined $current_fstab ) {
+ Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /etc/fstab" );
+ return undef;
+ }
+ my $addfstab = 0;
+ if ( ! defined $current_fstab->{$dest} ) {
+ $current_fstab->{$dest} = $add_mount;
+ $addfstab = 1;
+ }
+ else {
+ foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
+ $addfstab = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
+ }
+ }
+
+ my $addproc = 0;
+ if ( ! defined $current_proc->{$dest} ) {
+ $addproc = 1;
+ }
+ else {
+ my $fs_proc = $current_proc->{$dest};
+ foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
+ if ( $key eq 'options' ) {
+ $addproc = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
+ }
+ else {
+ $addproc = 1 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
+ }
+ }
+ }
+
+ if ( $addfstab || $addproc || ! -d $dest ) {
+ 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 ( ! -d $dest && $dest ne 'none' ) {
+ Mkdir_action ( $ref_section, $dest, $options, $hash_subst );
+ }
+ if ( $addfstab ) {
+ my $tmp = Get_tmp_dest ("/etc/fstab");
+ unless ( open ( NEWFSTAB, ">".$tmp ) ) {
+ Warn( $CODE->{'OPEN'}, "Impossible de creer " . $tmp );
+ return 1;
+ }
+ $current_fstab->{$dest} = $add_mount;
+ my $new_fstab = Build_fstab_from_structure ( $current_fstab );
+ print NEWFSTAB join ( "", @{$new_fstab} );
+ close ( NEWFSTAB );
+ if ( $options->{'diff'} ) {
+ deferredlogsystem( "diff -uN '/etc/fstab' '" . $tmp . "'" );
+ }
+ if ( ! $options->{'simul'} ) {
+ if ( ! move ( $tmp, "/etc/fstab" ) ) {
+ Warn( $CODE->{'OPEN'}, "Unable to move new fstab ".$tmp." to /etc/fstab" );
+ return 1;
+ }
+ }
+ }
+ if ( $addproc ) {
+ if ( $options->{'diff'} ) {
+ foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
+ my $value = $current_proc->{$dest}->{$key} || '?';
+ if ( $key eq 'options' ) {
+ Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $current_fstab->{$dest}->{$key} ne $add_mount->{$key} );
+ }
+ else {
+ Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $value ne $add_mount->{$key} );
+ }
+ }
+ }
+ if ( ! $options->{'simul'} && ! $options->{'noaction'} ) {
+ # Unmounting fs
+ my $remount = 1;
+ foreach my $key ( 'source', 'dest', 'fstype' ) {
+ $remount = 0 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
+ }
+ if ( $remount ) {
+ my $cmd = "mount -o 'remount,".$add_mount->{'options'}."' '".$dest."'";
+ if ( deferredlogsystem( $cmd ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to remount ".$dest." with options ".$add_mount->{'options'} );
+ return 1;
+ }
+ }
+ else {
+ my $umount = ( $add_mount->{'source'} ne $current_proc->{$dest}->{'source'} )
+ ? $current_proc->{$dest}->{'source'}
+ : $add_mount->{'source'};
+ if ( deferredlogsystem( "umount '".$umount."'" ) ) {
+ Warn ( $CODE->{'OPEN'}, "Unable to unmount ".$umount );
+ return 1;
+ }
+ my $mount_cmd = "mount -t '".$add_mount->{'fstype'}."' - o '".$add_mount->{'options'}."' '"
+ .$add_mount->{'source'}."' '".$add_mount->{'dest'}."'";
+ if ( deferredlogsystem ( $mount_cmd ) ) {
+ Warn ( $CODE->{'EXEC'}, "Unable to mount ".$dest." with command ".$mount_cmd );
+ return 1;
+ }
+ }
+ }
+ }
+ Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+ Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+ }
+ return 0;
+}
+
+1;
Propchange: branches/next-gen/lib/PFTools/Update/Addmount.pm
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed Aug 18 14:42:02 2010
@@ -1,0 +1,2 @@
+Id
+Revision
Added: branches/next-gen/lib/PFTools/Update/Mkdir.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Mkdir.pm?rev=829&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Mkdir.pm (added)
+++ branches/next-gen/lib/PFTools/Update/Mkdir.pm Wed Aug 18 14:42:02 2010
@@ -1,0 +1,83 @@
+package PFTools::Update::Addfile;
+##
+## $Id$
+##
+## 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 Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+ Mkdir_depends
+ Mkdir_action
+);
+
+our @EXPORT_OK = qw();
+
+use File::Compare;
+use File::Copy;
+use Text::Diff;
+use PFTools::Logger;
+use PFTools::Conf;
+use PFTools::Update::Common;
+
+
+sub Mkdir_depends ($$$) {
+ my ( $ref_section, $dest, $options ) = @_;
+
+ while ( $dest ne "/" && $dest ne "." ) {
+ $ref_section->{'depends'} .= " " . dirname($dest);
+ $dest = dirname($dest);
+ }
+}
+
+sub Mkdir_action ($$$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+ my $cmp = 0;
+
+ $hash_subst->{'SECTIONNAME'} = $dest;
+ if ( ! -d $dest ) {
+ $cmp = 1;
+ 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'} ) {
+ Do_moveold( $dest, $options );
+ if ( deferredlogsystem( "/bin/mkdir -p '" . $dest . "'" ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to create directory ".$dest );
+ return 1;
+ }
+ }
+ }
+ Do_chownmod( $ref_section, $dest, $options );
+ if ( $cmp ) {
+ Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+ Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+ }
+ return 0;
+}
+
+1;
Propchange: branches/next-gen/lib/PFTools/Update/Mkdir.pm
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed Aug 18 14:42:02 2010
@@ -1,0 +1,2 @@
+Id
+Revision
Added: branches/next-gen/lib/PFTools/Update/Purgepkg.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Purgepkg.pm?rev=829&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Purgepkg.pm (added)
+++ branches/next-gen/lib/PFTools/Update/Purgepkg.pm Wed Aug 18 14:42:02 2010
@@ -1,0 +1,83 @@
+package PFTools::Update::Purgepkg;
+##
+## $Id$
+##
+## 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 Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+ Purgepkg_action
+);
+
+our @EXPORT_OK = qw();
+
+use PFTools::Logger;
+use PFTools::Conf;
+use PFTools::Packages;
+use PFTools::Update::Common;
+
+sub Purge_pkg_action ($$$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+ $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 ( $options->{'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( $ref_section, $options, $hash_subst ) && return 1;
+ Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+ if ( !$options->{'simul'} ) {
+ if ( ! Purge_pkg ( $options->{'pkg_type'}, $dest ) ) {
+ Warn ( $CODE->{'OPEN'}, "An error occured during purge for package ".$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;
+};
+
+1;
Propchange: branches/next-gen/lib/PFTools/Update/Purgepkg.pm
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed Aug 18 14:42:02 2010
@@ -1,0 +1,2 @@
+Id
+Revision
More information about the pf-tools-commits
mailing list