#!/usr/bin/perl 
## @file issp
# @brief
# @details This script provides system rpm, SU and patch information for use by PM
# @author Dave Cairns
# @date 09/30/08
# @version 1.00 - Initial version

=pod

=head1 NAME

B<issp> - Generates a list of installed RPMs, SUs and patches

=head1 SYNOPSIS

B<issp> [B<-h, --help>]

=head1 DESCRIPTION

Provides a list of installed RPMs, SUs and patches. Output is displayed on screen and stored in the file MIRCC.txt

=head1 OPTIONS

=over 4

=item B<-h, --help>

Print this help message and exit

=back

=head1 EXAMPLES

=over 4

=item Print list 

$ B<issp>
 START:
 ##################
 Release: 6.00.00.00
 Machine: i686
 HostName: abc.domain.name.com
 ##################
 RPMs:
 pcre-devel-4.5-3.2.RHEL4
 PyQt-3.13-1
 qt-designer-3.3.3-9.3
 kdebase-devel-3.3.1-5.8
 kdesdk-3.3.1-2
 tetex-afm-2.0.2-22.EL4.7
 linuxdoc-tools-0.9.20-14
 docbook-utils-pdf-0.6.14-4
 compat-libstdc++-296-2.96-132.7.2
 libdbi-0.6.5-10.RHEL4.1
 gsl-1.5-2.rhel4
 unixODBC-kde-2.2.11-1.RHEL4.1
 cyrus-sasl-ntlm-2.1.19-5.EL4
 rusers-0.17-41.40.1
 compat-gcc-32-c++-3.2.3-47.3
 zsh-4.2.0-3.EL.3
 am-utils-6.0.9-15.RHEL4
 elfutils-libelf-devel-0.97-5
 tftp-0.39-1
 ##################
 SUs:
 basesystem-8.0-5.1.1.001|Start:nrsm|Stop:nrsm|Reboot:no|Spec:no
 kernel-headers-2.6.18-53.el5.002|Start:|Stop:|Reboot:no|Spec:Yes
 zlib-1.2.3.3.003.001|Start:dbcom,sps,ncs|Stop:ncs,dbcom,sps|Reboot:yes|Spec:no
 mktemp-2.0-0.0.0.005.001|Start:|Stop:|Reboot:yes|Spec|yes
 ##################
 Patches:
 p12345_1|Start:dbcom|Stop:dbcom|Spec:no
 p22345_1|Start:|Stop:|Spec:no
 p53233_1|Start:dbcom,sps|Stop:dbcom,sps|Spec:yes
 ##################
 EOF:
                                                         
=back

=head1 SEE ALSO

B<pload>, B<pins>, B<poos>, B<pout>, B<plis>, B<pstat>

=cut

use lib "/opt/nortel/base/lib/";

use warnings;
use strict;

use common_variables;
use common_functions;
use English;
use Switch;
use baselog;
use basedb;

use Getopt::Long;

use patchutil::patching;
use base_semctl;

sub issp_main();  #entry point

exit(issp_main());

sub issp_main()
{
   if (warning_if_not_nortel_grp())
   {
      return $ERROR;
   }

   set_subsystem('Base_Patch');
   my $ret = $OK;
   my $patches;
   my $semmngr;
   my $helpflag;

   my $res = GetOptions("help"=>\$helpflag);

   if (!$res)
   {
      print "Incorrect options provided\n";
      print_pod_usage();
      return $ERROR;
   } ## end if (!$res)

   #Parameters checking
   if ($helpflag)
   {
      print_pod_usage();
      return $OK;
   } ## end if ($helpflag)

   if ($ARGV[0]) ## ARGV[0] only has data if there were uncaught parameters. 
   {
      print "Incorrect options provided\n";
      print_pod_usage();
      return $ERROR;
   } ## end if ($ARGV[0])

   signals_ignore();
   $semmngr = base_semctl::new("PATCH");
   if (!defined($semmngr))
   {
      my $error_descr = $!;
      baselog($LOG_ERROR, "Cannot create semaphore manager object ($error_descr).",$TRUE);
      return $ERROR;
   } ## end if (!defined($semmngr)...
   if (!$semmngr->sem_take($SEM_PATCH, IPC_NOWAIT))
   {
      baselog($LOG_ERROR, "Cannot take semaphore. Patching operation aborted.\n", $TRUE);
      undef $semmngr;
      return $ERROR;
   } ## end if (!$semmngr->sem_take...

   $patches = new patchutil::patching;
   unless (defined $patches)
   {
      baselog($LOG_ERROR, 'The "patching" creation failed',$TRUE);
      if (!$semmngr->sem_give($SEM_PATCH))
      {
         baselog($LOG_ERROR, "Cannot release semaphore.");
      }
      undef $semmngr;
      return $ERROR;
   } ## end unless (defined $patches)

   unless ($patches->show_issp())
   {
      baselog($LOG_ERROR, "Can not get issp info\n", $TRUE);
      $ret = $ERROR;
   }

   undef $patches;

   if (!$semmngr->sem_give($SEM_PATCH))
   {
      baselog($LOG_ERROR, "Cannot release semaphore.");
      $ret = $ERROR;
   } ## end if (!$semmngr->sem_give...
   undef $semmngr;

   return $ret;
} ## end sub issp_main()

