PERL   37

rpmcompare

Guest on 18th June 2022 12:55:13 AM

  1. #!/usr/bin/perl -w
  2.  
  3. #Point these to a directory of RH and rebuilt (aka WB) RPMS
  4. $WB_RPMS = "/centos-3/build7/i386/RedHat/RPMS/";
  5. $RH_RPMS = "/centos-3/build8/i386/RedHat/RPMS/";
  6.  
  7. # Size difference to trigger error, .1 = plus/minus 10%
  8. $SizeError=.10;
  9.  
  10. # Working directories
  11. # Careful where these point, they get a "rm -rf" cleaning!
  12. $RHTMP="/tmp/RH-$$";
  13. $WBTMP="/tmp/WB-$$";
  14.  
  15. opendir(DIR,$RH_RPMS);
  16. @allrpms= grep (/rpm$/, readdir(DIR) );
  17. closedir(DIR);
  18.  
  19. foreach $rpm (sort @allrpms){
  20.     if (! (-e "$WB_RPMS/$rpm") ) {
  21.         print " No equivalent original for $rpm \t skipping\n";
  22.         next;
  23.     }
  24.     # Initialize
  25.     %allfiles=(); %RHhash=(); %WBhash=();
  26.     $fileproblems=0; $libproblems=0;
  27.     system("rm -rf $RHTMP;mkdir $RHTMP");
  28.     system("rm -rf $WBTMP;mkdir $WBTMP");
  29.     # Extract RPMS
  30.     system("cd $RHTMP/; rpm2cpio $RH_RPMS/$rpm | cpio -id --no-absolute-filenames --quiet");
  31.     system("cd $WBTMP/; rpm2cpio $WB_RPMS/$rpm | cpio -id --no-absolute-filenames --quiet");
  32.  
  33.     # Parse name/size info
  34.     @RHnamesize=`cd $RHTMP/; find ./ -printf "%p:_:%s\n"`;
  35.     @WBnamesize=`cd $WBTMP/; find ./ -printf "%p:_:%s\n"`;
  36.     for ($i=0;$i<@RHnamesize;$i++){
  37.         ($file,$size)=split(/:_:/,$RHnamesize[$i]);
  38.         $RHhash{"$file"}=$size;
  39.         $allfiles{"$file"}=1;
  40.     }
  41.     for ($i=0;$i<@WBnamesize;$i++){
  42.         ($file,$size)=split(/:_:/,$WBnamesize[$i]);
  43.         $WBhash{"$file"}=$size;
  44.         $allfiles{"$file"}=1;
  45.     }
  46.  
  47.    
  48.     # Print and tag file errors if appropraite
  49.     printf ("%-50s\t", $rpm);
  50.     foreach $file (keys %allfiles){
  51.         if (!(exists $RHhash{"$file"})){
  52.             print "\n\tPackage contains extra file:  $file";
  53.             $fileproblems=1;
  54.         }
  55.         elsif (!(exists $WBhash{"$file"})){
  56.             print "\n\tPackage is missing file: $file";
  57.             $fileproblems=1;
  58.         }
  59.         else {
  60.             if ($RHhash{"$file"}>0){
  61.                 $ratio=($WBhash{"$file"})/($RHhash{"$file"})}
  62.             else{
  63.                 $ratio=1-$WBhash{"$file"};  # Negative ratios indicate filesize vs. zero in RedHat
  64.             }
  65.             if (($ratio-1)*($ratio-1)>($SizeError*$SizeError)) {
  66.                 printf("\n\tSize Ratio: %3.2f on file:%s",$ratio,$file);
  67.                 $fileproblems=1;
  68.             };
  69.         }
  70.     }
  71.  
  72.    
  73.     # Select executable files
  74.     @RHexec=`cd $RHTMP/; find ./ -perm +111 -type f -print`;
  75.  
  76.     # Check library dependencies
  77.     foreach $executable (@RHexec) {
  78.         chop $executable;
  79.  
  80.         #  Move on if no equivalent binary exists in rebuild
  81.         if (! (-e "$WBTMP/$executable") ) {next;}
  82.  
  83.         # Get shared libs
  84.         @RHlibs=`ldd $RHTMP/$executable`;
  85.         @WBlibs=`ldd $WBTMP/$executable`;
  86.  
  87.         # Clean up ldd output
  88.         $RHlibline=join('',(sort @RHlibs));
  89.         $WBlibline=join('',(sort @WBlibs));
  90.         $RHlibline=~ s/=>(.*)(\n)/\n/g; $RHlibline=~ s/(\s+)/ /g;
  91.         $WBlibline=~ s/=>(.*)(\n)/\n/g; $WBlibline=~ s/(\s+)/ /g;
  92.         @RHlibs=split(/ /,$RHlibline);
  93.         @WBlibs=split(/ /,$WBlibline);
  94.  
  95.         # Print and tag library errors
  96.         foreach $lib (@RHlibs){
  97.             $searchpat=$lib;
  98.             $searchpat =~ s/\+/\\\+/g;
  99.             $searchpat =~ s/\./\\\./g;
  100.             unless ($WBlibline =~ (/$searchpat/)){
  101.                 print "\n\tMissing link in $executable:\t$lib";$libproblems=1;
  102.             }
  103.         }
  104.            
  105.         foreach $lib (@WBlibs){
  106.             $searchpat=$lib;
  107.             $searchpat =~ s/\+/\\\+/g;
  108.             $searchpat =~ s/\./\\\./g;
  109.             unless ($RHlibline =~ (/$searchpat/)){
  110.                 print "\n\tExtra link in $executable:\t$lib";$libproblems=1;
  111.             }
  112.         }
  113.     }
  114.     if ($fileproblems || $libproblems) { print "\n\n";} else {print "MATCH\n";}
  115. }

Raw Paste


Login or Register to edit or fork this paste. It's free.