#!/usr/bin/perl

## @file swVersionShow
# @brief show applications base applications info
# @details  returns information about installed base configuration, 
#           application configuration, applications list and their versions.
#           If some packages were installed it also returns insformation about 
#           installed packages.
# @author
# @date
# @version 1.00 - Initial version
# @note

=pod

=head1 NAME

B<swVersionShow> show applications and base applications info

=head1 SYNOPSIS

B<swVersionShow> [B<--help>]

=head1 DESCRIPTION

B<swVersionShow> returns information about installed
base configuration, application configuration, applications list and their versions.
If some packages were installed it also returns insformation about installed packages.

The Application CD is split into two configuration types: 

=over 4

=item - CS1000 NRS and Security Services

=item - CS1000 Element Manager and Security Services

=back

=head1 OPTIONS

=over 4

=item B<-help>

Print this help message and exit.

=back

=head1 EXAMPLES

$ B<swVersionShow>
 Product Release: 6.00.00.00
 Base Applications
    base                         6.00.00
    Snmp-Daemon-TrapLib          6.00.00
    sm                           6.00.00
    Jboss-Quantum                6.00.00
 Application configuration: EM+SM
 Packages:
     EM
     SM
 Configuration version:     6.00.07
    nrsm                         6.00.07
    nrsmWebService               6.00.07
                                   
If applications are not installed:

$ B<swVersionShow>
 
 Product Release: 6.00.00.00
 Base Applications
    base                         6.00.00
    Snmp-Daemon-TrapLib          6.00.00
    sm                           6.00.00
    Jboss-Quantum                6.00.00
 Application configuration: undefined
 Configuration version:     undefined

=head1 CAVEATS

B<swVersionShow> can be run only under Nortel authorized accounts.

=head1 SEE ALSO

B<baseVersionShow> and B<appVersionShow>

=cut

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

use strict;
use warnings;
use common_variables;
use common_functions;
use baselog;
use appinstall::show_app_info;
use base_semctl;

## @fn main()
# @brief Entry point.
# @details
# @param None
# @return $OK - on success
# @return $ERROR - on error
# @author
# @date 
sub main
{
   if (warning_if_not_nortel_grp())
   {
      return $ERROR;
   }

   if (defined $ARGV[0] and $ARGV[0] =~ /help$/)
   {
      print_pod_usage();
      return $OK;
   }

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

   unless (showAppInfo("all"))
   {
      baselog($LOG_ERROR, "Cannot get information about applications installed\n", $TRUE);
      undef $semmngr;
      return $ERROR;
   }

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

exit(main());

