#!/usr/bin/perl
## @file    baseparamsconfig
# @brief    This script prompts user and configures
#   \li dns settings
#   \li NTP settings
#   \li date and time
# @param   --show prints information about current configuration.
# @author  Alex Arkhipov
# @date    January 2007
# @version 1.00 - Initial version
# @version 1.01 - POD section was added; the usage is displayed by the
#          common function - print_pod_usage() now.
# @version 1.02 - Two colons were removed before shared functions and variables.
#          date and time
# @version 1.03 - invocation of the "getParams" function has been changed.

=pod

=head1 NAME

B<baseparamconfig> - print current parametrs of system configuration.

=head1 SYNOPSIS

B<baseparamconfig> [B<--show>]|[B<--help>]

=head1 DESCRIPTION

This script prompts user and configures the following system settings:

=over 4

=item - network parameters

=item - dns settings

=back

=head1 OPTIONS

=over 4

=item B<--show>  

Show current parameters configuration

=item B<--help>

Print this help message and exit.

=back

=head1 EXAMPLES

=over 4

=item B<baseparamconfig>

prints user new system settings

=item B<baseparamsconfig> I<--show>

prints current system settings' values

=back

=head1 CAVEATS

The B<baseparamsconfig> command requires B<root> password to be run.
The system reboot is triggered after B<baseparamsconfig> is completed.

=head1 SEE ALSO

B<dnsconfig>, B<networkconfig>, B<ntpconfig>, B<datetimeconfig>

=cut

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

use warnings;
use strict;

use common_variables;
use common_functions;
use baseParams;
use baseParamsUI;
use baselog;

sub main();

exit(main());

sub main()
{

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

   my %data;

   if (!defined(getParams(\%data)))
   {
      baselog($LOG_ERROR, "Cannot get current data\n", $TRUE);
      return $ERROR;
   }

   if ((scalar(@ARGV) == 1) && ($ARGV[0] eq "--show"))
   {
      print_baseparam_config(\%data);
      return $OK;
   }
   elsif (scalar(@ARGV) > 0)
   {
      print_pod_usage("Incorrect option provided");
      return $ERROR;
   }
   signals_ignore();

   # Prompt user for new network settings
   configNetwork(\%data);

   # DNS Server Configuration
   configDNSServer(\%data);

   # Timezone Configuration
   configTimeZone(\%data);

   print_baseparam_config(\%data);
   if (rebootPrompt())
   {
      if (setupDNS(\%data))
      {
         baselog($LOG_INFO, "DNS servers have been set up successfully\n", $TRUE);
      }
      else
      {
         baselog($LOG_ERROR, "DNS servers setup failed\n", $TRUE);
      }

      if (setupNetwork(\%data))
      {
         baselog($LOG_INFO, "Network has been set up successfully\n", $TRUE);
      }
      else
      {
         baselog($LOG_ERROR, "Network setup failed\n", $TRUE);
      }

      if (setupTimeZone(\%data))
      {
         baselog($LOG_INFO, "Timezone has been set up successfully\n", $TRUE);
      }
      else
      {
         baselog($LOG_ERROR, "Timezone setup failed\n", $TRUE);
      }
      print "System parameters have been changed. Rebooting...\n";
      system($REBOOT);
   } ## end if (rebootPrompt())
   else
   {
      print "Exiting...\n";
      return $OK;
   }
} ## end sub main()

__END__
