133 lines
3.8 KiB
Perl
133 lines
3.8 KiB
Perl
#!/usr/bin/perl -w
|
|
#----------------------------------------------------------------------
|
|
# Yum database updates
|
|
# Copyright (C) 2005 Gordon Rowell <gordonr@gormand.com.au>
|
|
#
|
|
# 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 or 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#----------------------------------------------------------------------
|
|
|
|
use strict;
|
|
use esmith::ConfigDB;
|
|
|
|
my $db = esmith::ConfigDB->open_ro or die "Couldn't open ConfigDB\n";
|
|
|
|
my $pid = fork;
|
|
exit 1 unless defined $pid;
|
|
# now two processes are executing
|
|
if ($pid == 0) {
|
|
|
|
use constant YUM_CRON_FLAG => '/var/lock/subsys/yum-cron';
|
|
# we do not use yum-cron /etc/cron.daily file
|
|
# so we keep away the subsys file
|
|
#if ($db->get_prop('yum', 'AutoInstallUpdates') eq 'enabled')
|
|
#{
|
|
# (system('/bin/touch', YUM_CRON_FLAG) == 0) or
|
|
# warn "Couldn't touch " . YUM_CRON_FLAG . "\n";
|
|
#}
|
|
#else
|
|
#{
|
|
# system("/usr/bin/systemctl -q stop yum-cron");
|
|
# system("/usr/bin/systemctl -q mask yum-cron");
|
|
unlink YUM_CRON_FLAG;
|
|
#}
|
|
|
|
# XXX - WARNING - XXX
|
|
#
|
|
# For speed and to reduce log noise, we don't use
|
|
# the esmith::DB routines here
|
|
|
|
# We do not use -R xxx to sleep for a while, as we do this at cron level
|
|
# this allows faster results when needed or delayed when not
|
|
|
|
use constant YUM_CMD => "/usr/bin/yum -d 0 -e 0 ";
|
|
|
|
# avoid error with no installed groups file.
|
|
system(YUM_CMD." groups mark convert -d 0 -e 0 1>/dev/null") unless (-d "/var/lib/yum/groups/");
|
|
|
|
# yum check to have fresh metadata
|
|
system(YUM_CMD." check-update 1>/dev/null");
|
|
|
|
my $tmp_file;
|
|
|
|
END { $tmp_file and -f $tmp_file and unlink $tmp_file; }
|
|
|
|
for my $list_option ( qw(available installed updates) )
|
|
{
|
|
my $file = "/home/e-smith/db/yum_${list_option}";
|
|
$tmp_file = "/home/e-smith/db/yum_${list_option}.tmp";
|
|
|
|
open DB, ">$tmp_file" or die "Couldn't create $tmp_file\n";
|
|
|
|
print DB "# Generated by $0: " . scalar localtime() . "\n";
|
|
|
|
open YUM, "-|", YUM_CMD . "list $list_option" or
|
|
die "Couldn't call yum list $list_option\n";
|
|
|
|
#strip header, preventing inclusion as package
|
|
my $header = <YUM>;
|
|
while ( <YUM> )
|
|
{
|
|
my ($package, $version, $repo) = split /\s+/;
|
|
|
|
next unless $package and $version and $repo;
|
|
|
|
if ($list_option eq 'available')
|
|
{
|
|
my $RestrictRpm = $db->get_prop('yum', 'RestrictRpm') || '';
|
|
my $RestrictRepo = $db->get_prop('yum', 'RestrictRepo') || '';
|
|
my @rpms = split(/,/, $RestrictRpm);
|
|
my @repos = split(/,/, $RestrictRepo);
|
|
|
|
if ( ($#rpms < 0 && $#repos < 0)
|
|
|| (grep { $package =~ /$_/ } @rpms)
|
|
|| (grep { $repo =~ /$_/ } @repos)
|
|
)
|
|
{
|
|
print DB "$package=package|Repo|$repo|Version|$version\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print DB "$package=package|Repo|$repo|Version|$version\n";
|
|
}
|
|
}
|
|
|
|
close YUM or warn "yum list $list_option status $?\n";
|
|
|
|
open YUM, "-|", YUM_CMD . "grouplist $list_option" or
|
|
die "Couldn't call yum grouplist $list_option\n";
|
|
|
|
while ( <YUM> )
|
|
{
|
|
next if /^\s*$/;
|
|
|
|
next unless /^\s+/;
|
|
|
|
s/\s+//g;
|
|
|
|
print DB "$_=group\n";
|
|
}
|
|
|
|
close YUM or warn "yum grouplist $list_option status $?\n";
|
|
|
|
close DB;
|
|
|
|
rename $tmp_file, $file or die "Couldn't rename $tmp_file $file\n";
|
|
}
|
|
|
|
exit 0;
|
|
}
|
|
exit 0;
|