#!/usr/bin/perl 

## @file appVersionShow
# @brief show applications info
# @details This command shows the name of the installed  
#          configuration and list applications names and versions.
# @author
# @date
# @version 1.00 - Initial version
# @note

=pod

=head1 NAME

B<appVersionShow> - show applications info

=head1 SYNOPSIS

B<appVersionShow> [B<--help>]

=head1 DESCRIPTION

This command shows the name of the installed configuration and list applications names and versions.
If some packages were installed it also shows 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

=over 4

=item B<$ appVersionShow>

 Application configuration: EM+SM
 Packages:
     EM
     SM
 Configuration version:     6.00.07
    nrsm                         6.00.07
    nrsmWebService               6.00.07                       
                        
=item If applications are not installed:

=item B<$ appVersionShow>

 Application configuration: undefined
 Configuration version:     undefined

=back

=head1 CAVEATS

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

=head1 SEE ALSO

B<baseVersionShow> and B<swVersionShow>

=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("appVersionShow");
   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("app"))
   {
      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());
