#!/usr/bin/perl # written 2003 by John Borwick. # Takes a list of RPMs, figures out what the current CD offers, and repeatedly # tries to install all the RPMs the machine doesn't have. # Example usage: # machine1% perl rpm-brute.pl machine2-rpm-list.txt use strict; use warnings; our $RPMS_dir = "/mnt/cdrom/RedHat/RPMS"; our $max_queue_count = 3; opendir( CD, $RPMS_dir) or die "Can't get to $RPMS_dir\n"; our %rpms_to_get = remove_versions( map { s/\s+//g; ( $_ => 1 ) } <> ); our %rpms_we_have = remove_versions( machine_rpms() ); eliminate_installed_rpms(); #foreach my $rpm (keys %rpms_to_get) { # print $rpm,"\n"; #} our %CD_FILES = map { ( remove_versions($_), $_ ) } grep /rpm$/, readdir(CD); our @CD_QUEUE = map { $CD_FILES{$_} } grep $CD_FILES{$_}, keys %rpms_to_get; our %QUEUE_COUNT; while ( my $next_file = shift @CD_QUEUE ) { print "trying to install $next_file\n"; if ( system("/bin/rpm", "-Uvh", "$RPMS_dir/$next_file" ) ) { $QUEUE_COUNT{ $next_file } ++; print " failure # $QUEUE_COUNT{$next_file}, "; if ( $QUEUE_COUNT{ $next_file} <= $max_queue_count ) { print " requeuing.\n"; push @CD_QUEUE, $next_file; } else { print " too many retries, stopping.\n"; } } else { print " success!\n"; } } sub machine_rpms { map { s/\s+//g; ( $_ => 1 ) } `/bin/rpm -q -a`; } sub remove_versions { my @loc = @_; foreach (@loc) { s/-[^\-]+-[^\-]+$//; } @loc; } sub eliminate_installed_rpms { foreach my $key ( keys %rpms_to_get) { delete $rpms_to_get{$key} if $rpms_we_have{$key}; } }