From: cajus Date: Tue, 18 Mar 2008 11:28:27 +0000 (+0000) Subject: Added support for loading / parsing package lists X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bfe3f7fb5cdf5996408dd6b9475787f2f85574f9;p=gosa.git Added support for loading / parsing package lists git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9919 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 8ef8e039b..c933a674f 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -40,6 +40,8 @@ use Sys::Syslog qw( :DEFAULT setlogsock); use Cwd; use File::Spec; use File::Basename; +use File::Find; +use File::Copy; use File::Path; use GOSA::DBsqlite; use GOSA::GosaSupportDaemon; @@ -52,7 +54,7 @@ use lib "/usr/lib/gosa-si/modules"; my (%cfg_defaults, $foreground, $verbose, $ping_timeout); my ($bus_activ, $bus, $msg_to_bus, $bus_cipher); -my ($server, $server_mac_address); +my ($server); my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay); my ($known_modules); my ($pid_file, $procid, $pid, $log_file); @@ -60,6 +62,9 @@ my ($arp_activ, $arp_fifo); my ($xml); my $sources_list; my $max_clients; +my %repo_files=(); +my $repo_path; +my %repo_dirs=(); # variables declared in config file are always set to 'our' our (%cfg_defaults, $log_file, $pid_file, $server_ip, $server_port, $SIPackages_key, @@ -69,6 +74,7 @@ our (%cfg_defaults, $log_file, $pid_file, # additional variable which should be globaly accessable our $server_address; +our $server_mac_address; our $bus_address; our $gosa_address; our $no_bus; @@ -175,6 +181,7 @@ my $max_children = 2; "packages-list" => [\$packages_list_file_name, '/var/lib/gosa-si/packages.db'], "messaging" => [\$messaging_file_name, '/var/lib/gosa-si/messaging.db'], "source-list" => [\$sources_list, '/etc/apt/sources.list'], + "repo-path" => [\$repo_path, '/srv/www/repository'], "ldap-uri" => [\$ldap_uri, ""], "ldap-base" => [\$ldap_base, ""], "ldap-admin-dn" => [\$ldap_admin_dn, ""], @@ -946,8 +953,8 @@ sub update_jobdb_status_for_send_msgs { sub _start { my ($kernel) = $_[KERNEL]; &trigger_db_loop($kernel); - #$kernel->yield('create_fai_server_db', $fai_server_tn ); - #$kernel->yield('create_fai_release_db', $fai_release_tn ); + $kernel->yield('create_fai_server_db', $fai_server_tn ); + $kernel->yield('create_fai_release_db', $fai_release_tn ); $kernel->sig(USR1 => "sig_handler"); } @@ -1282,6 +1289,7 @@ sub watch_for_new_jobs { sub refresh_ldap_handle { my $mesg; + daemon_log("DEBUG: Trying to create a connection to URI $ldap_uri", 5); # Get an ldap handle, if we don't have one if( ! defined $ldap_handle ){ $ldap_handle = Net::LDAP->new( $ldap_uri ); @@ -1820,13 +1828,13 @@ sub create_sources_list { my $fh; open($fh, ">$result") or return undef; - if(defined($ldap_server_dn) && length($ldap_server_dn)>0) { + if(defined($ldap_server_dn) and length($ldap_server_dn) > 0) { my $mesg=$ldap_handle->search( - base => $ldap_server_dn, - scope => 'base', - attrs => 'FAIrepository', - ); - + base => $ldap_server_dn, + scope => 'base', + attrs => 'FAIrepository', + filter => 'objectClass=FAIrepositoryServer' + ); if($mesg->count) { foreach my $entry(@{$mesg->{'entries'}}) { my ($server, $tag, $release, $sections)= split /\|/, $entry->get_value('FAIrepository'); @@ -1882,6 +1890,7 @@ sub create_packages_list_db { daemon_log("INFO: create_packages_list_db: finished", 5); return; } + sub run_create_packages_list_db { my ($session, $heap) = @_[SESSION, HEAP]; my $task = POE::Wheel::Run->new( @@ -1892,18 +1901,22 @@ sub run_create_packages_list_db { ); $heap->{task}->{ $task->ID } = $task; } + sub parse_package_info { my ($baseurl, $dist, $section)= @_; my ($package); my ($path) = ($baseurl =~ m%://[^/]*(.*)$%); + $repo_dirs{ "${repo_path}/pool" } = 1; foreach $package ("Packages.gz"){ daemon_log("DEBUG: create_packages_list: fetch $baseurl, $dist, $section", 7); get_package( "$baseurl/dists/$dist/$section/binary-$arch/$package", "$outdir/$dist/$section" ); parse_package( "$outdir/$dist/$section", $dist, $path ); } + find(\&cleanup_and_extract, keys( %repo_dirs ) ); } + sub get_package { my ($url, $dest)= @_; @@ -1919,8 +1932,9 @@ sub get_package { } return 0; } + sub parse_package { - my ($path, $dist, $srv_path )= @_; + my ($path, $dist, $srv_path)= @_; my ($package, $version, $section, $description); my @sql_list; my $PACKAGES; @@ -1977,6 +1991,12 @@ sub parse_package { next; } + # Trigger for filename + if ($line =~ /^Filename:\s/){ + my ($filename) = ($line =~ /^Filename: (.*)$/); + store_fileinfo( $package, $filename, $dist, $srv_path, $version, $repo_path ); + next; + } } close( $PACKAGES ); @@ -1985,18 +2005,51 @@ sub parse_package { $packages_list_db->exec_statementlist(\@sql_list); } -# -#sub store_fileinfo { -# my( $package, $file, $dist, $path, $vers ) = @_; -# -# my %fileinfo = ( -# 'package' => $package, -# 'dist' => $dist, -# 'version' => $vers -# ); -# -# $repo_files{ "${srvdir}${path}/$file" } = \%fileinfo; -#} +sub store_fileinfo { + my( $package, $file, $dist, $path, $vers, $srvdir) = @_; + + my %fileinfo = ( + 'package' => $package, + 'dist' => $dist, + 'version' => $vers, + ); + + $repo_files{ "${srvdir}/$file" } = \%fileinfo; +} + +sub cleanup_and_extract { + + my %templates = (); + my $fileinfo = $repo_files{ $File::Find::name }; + + if( defined $fileinfo ) { + print STDERR "============> $File::Find::name\n"; + + my $dir = "$outdir/$fileinfo->{ 'dist' }/debconf.d"; + system( "mkdir -p '$dir'" ); + + system( "dpkg -e '$File::Find::name' '$dir/DEBIAN'" ); + if( -f "$dir/DEBIAN/templates" ) { + my $package = $fileinfo->{ 'package' }; + my $newver = $fileinfo->{ 'version' }; + + daemon_log("DEBUG: Found debconf templates in '$package' - $newver", 5); + if( exists $templates{ "$fileinfo->{ 'dist' }/$package" } ) { + my $oldver = $templates{ "$fileinfo->{ 'dist' }/$package" }; + my $ret = system( "dpkg --compare-versions '$oldver' gt '$newver'" ); + if( ! $ret ) { + daemon_log("DEBUG: duplicated '$package' ($newver) in $fileinfo->{ 'dist' } - keeping tmpl v'$oldver'", 5); + return; + } + else { + daemon_log("DEBUG: duplicated '$package' ($newver) in $fileinfo->{ 'dist' } - overwriting tmpl v'$oldver'", 5); + } + } + $templates{ "$fileinfo->{ 'dist' }/$package" } = $newver; + move( "$dir/DEBIAN/templates", "$dir/$package.templates" ); + } + } +} #==== MAIN = main ============================================================== diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index 5efc73cd9..c8078499a 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -23,7 +23,7 @@ use lib "/usr/lib/gosa-si/server/events"; BEGIN{} END {} -my ($server_ip, $server_mac_address, $server_port, $SIPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface); +my ($server_ip, $server_port, $SIPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface); my ($bus_activ, $bus_key, $bus_ip, $bus_port); my $server; my $event_hash; @@ -41,7 +41,7 @@ my %cfg_defaults = ( }, "server" => { "ip" => [\$server_ip, "0.0.0.0"], - "mac-address" => [\$server_mac_address, "00:00:00:00:00"], + "mac-address" => [\$main::server_mac_address, "00:00:00:00:00"], "port" => [\$server_port, "20081"], "ldap-uri" => [\$ldap_uri, ""], "ldap-base" => [\$ldap_base, ""], @@ -63,27 +63,28 @@ my %cfg_defaults = ( # if server_ip is not an ip address but a name if( inet_aton($server_ip) ){ $server_ip = inet_ntoa(inet_aton($server_ip)); } $network_interface= &get_interface_for_ip($server_ip); -$server_mac_address= &get_mac($network_interface); +$main::server_mac_address= &get_mac($network_interface); &import_events(); # Unit tag can be defined in config if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { # Read gosaUnitTag from LDAP - &main::refresh_ldap_handle(); + &main::refresh_ldap_handle(); if( defined($main::ldap_handle) ) { - &main::daemon_log("INFO: Searching for servers gosaUnitTag with mac address $server_mac_address",5); + &main::daemon_log("INFO: Searching for servers gosaUnitTag with mac address $main::server_mac_address",5); # Perform search for Unit Tag $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], - filter => "(macaddress=$server_mac_address)" + filter => "(macaddress=$main::server_mac_address)" ); if ($mesg->count == 1) { my $entry= $mesg->entry(0); my $unit_tag= $entry->get_value("gosaUnitTag"); + $main::ldap_server_dn= $mesg->entry(0)->dn; if(defined($unit_tag) && length($unit_tag) > 0) { &main::daemon_log("INFO: Detected gosaUnitTag $unit_tag for creating entries", 5); $main::gosa_unit_tag= $unit_tag; @@ -102,6 +103,7 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { if ($mesg->count == 1) { my $entry= $mesg->entry(0); my $unit_tag= $entry->get_value("gosaUnitTag"); + $main::ldap_server_dn= $mesg->entry(0)->dn; if(defined($unit_tag) && length($unit_tag) > 0) { &main::daemon_log("INFO: Detected gosaUnitTag $unit_tag for creating entries", 5); $main::gosa_unit_tag= $unit_tag; @@ -120,6 +122,7 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { if ($mesg->count == 1) { my $entry= $mesg->entry(0); my $unit_tag= $entry->get_value("gosaUnitTag"); + $main::ldap_server_dn= $mesg->entry(0)->dn; if(defined($unit_tag) && length($unit_tag) > 0) { &main::daemon_log("INFO: Detected gosaUnitTag $unit_tag for creating entries", 5); $main::gosa_unit_tag= $unit_tag; @@ -303,8 +306,8 @@ sub get_mac { my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list # A configured MAC Address should always override a guessed value - if ($server_mac_address and length($server_mac_address) > 0) { - $result= $server_mac_address; + if ($main::server_mac_address and length($main::server_mac_address) > 0) { + $result= $main::server_mac_address; } socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')