getSolPatches.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/perl -w
  2. # --- BEGIN COPYRIGHT BLOCK ---
  3. # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  4. # Copyright (C) 2005 Red Hat, Inc.
  5. # All rights reserved.
  6. #
  7. # License: GPL (version 3 or any later version).
  8. # See LICENSE for details.
  9. # --- END COPYRIGHT BLOCK ---
  10. $patchdir = "/var/sadm/patch";
  11. # key is the major patch number
  12. # the value is a hash ref which has two keys 'iminor' and 'val'
  13. # the value of key 'iminor' is the minor patch number
  14. # the system keeps track of all revisions (minor number) for each patch (major number)
  15. # we only want to list the highest revision, since on Solaris higher revisions include
  16. # and supersede lower revisions
  17. # the value of key 'val' is the string to print out
  18. %patches = ();
  19. opendir PATCHDIR, $patchdir or die "Error: could not open $patchdir: $!: you must be superuser to run this script\n";
  20. while ($dir = readdir PATCHDIR) {
  21. if ($dir =~ /(\d+)\-(\d+)/) {
  22. $major = $1;
  23. $minor = $2;
  24. $iminor = int($2);
  25. if (! $patches{$major} || ! $patches{$major}->{iminor} || ($patches{$major}->{iminor} < $iminor)) {
  26. open IN, "$patchdir/$dir/README.$major\-$minor" or die "Error: could not open $patchdir/$dir/README.$major\-$minor: $! - you must be superuser to run this script\n";
  27. while (<IN>) {
  28. chop;
  29. if (/^Synopsis:\s+/) {
  30. $desc = $';
  31. }
  32. if (/^Date:\s+/) {
  33. $date = $';
  34. }
  35. if (/^SunOS Release:\s+(\d+)\.(\d+)/) {
  36. $majrel = $1;
  37. $minrel = $2;
  38. last;
  39. }
  40. }
  41. $required = 1; # how to tell if patch is not required, only recommended?
  42. $patches{$major}->{val} = "{$major,$iminor,$required,2$minrel,0,0,\"$date: $desc\"},\n";
  43. close IN;
  44. $patches{$major}->{iminor} = $iminor;
  45. }
  46. }
  47. }
  48. closedir PATCHDIR;
  49. $date = gmtime;
  50. $host = `hostname`;
  51. $dom = `domainname`;
  52. $rel = `cat /etc/release`;
  53. chomp $host;
  54. chomp $dom;
  55. chomp $date;
  56. print "/* This list was generated by $0 */\n";
  57. print "/* on $host.$dom */\n";
  58. print "/* at $date GMT */\n";
  59. print "/* Here is the information from /etc/release:\n";
  60. print $rel;
  61. print " The following is a list of patches installed on the system */\n";
  62. print "/* a patch that is commented out is either a duplicate or */\n";
  63. print "/* a patch that is superseded by another patch */\n";
  64. for $major (sort keys %patches) {
  65. print $patches{$major}->{val};
  66. }