#!/usr/bin/perl

###############################################################################
## Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
###############################################################################

use strict;
use warnings;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../www/perl-lib" }

use SMT::Utils;

use Locale::gettext ();
use POSIX ();     # Needed for setlocale()

POSIX::setlocale(&POSIX::LC_MESSAGES, "");

my $exec = "/usr/sbin/smt-scc-sync";
my $cfg = undef;
eval
{
    $cfg = SMT::Utils::getSMTConfig();
};
if($@ || !defined $cfg)
{
    print sprintf(__("Cannot read the SMT configuration file: %s"), $@);
    exit 1;
}

if ( $cfg->val('NU', 'ApiType', 'NCC') eq 'NCC')
{
    print __("NCC is not supported in this version of SMT");
    exit 1;
}

sub executeCommand
{
  my $command = shift;
  my @options = @_;

  my $cmd = "$command ";

  # quote all the options, otherwise whithespace causes problems
  foreach (@options)
  {
    $_ =~ s/\'/\\\'/;
    $cmd .= "'$_' ";
  }

  #print "execute '$cmd'\n";
  if ( ! -e $command )
  {
    die "$cmd command not installed\n";
  }
  return system($cmd);
}

my $ret = executeCommand($exec, @ARGV);
exit $ret;

#
# Manpage
#

=head1 NAME

smt-sync - sync from customer center

=head1 SYNOPSIS

smt-sync [--help|-h] [options]

=head1 DESCRIPTION

Wrapper for smt-ncc-sync or smt-scc-sync depending on the configuration.


=head1 AUTHORS and CONTRIBUTORS

Duncan Mac-Vicar Prett, Lukas Ocilka, Jens Daniel Schmidt, Michael Calmer

=head1 LICENSE

Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 675 Mass
Ave, Cambridge, MA 02139, USA.

=cut

