#!/usr/bin/perl -w
#
# Copyright (c) 2011 SUSE Linux Products GmbH
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

use strict;
use File::Basename;
use Data::Dumper;

BEGIN {
    my $app  = dirname($0)."/..";
    push @INC, "$app" if(-d "$app/SUSE");
}

use SUSE::RegistrationStatus;
use Getopt::Long;
use Locale::gettext ();

sub __
{
    my $msgid = shift;
    my $domain = "subscription-tools";
    return Locale::gettext::dgettext ($domain, $msgid);
}

sub usage
{
    print STDERR "usage: $0 [--quiet|-q]\n";
    print STDERR "       $0 [--debug|-d]\n";
    print STDERR "       $0 [--help|-h|-?]\n";
    print STDERR __("Options:\n");
    print STDERR "      -h -? [--help]               ".__("show this help\n");
    print STDERR "         -q [--quiet]              ".__("print no messages\n");
    print STDERR "\n";
    print STDERR __("isRegistered checks if this system is registered.\n");
    print STDERR __("isRegistered exit with 0 if the system is registered.\n");
    print STDERR __("Otherwise it exist with 1\n");
    exit 2;
}

my $quiet = 0;
my $help  = 0;

my $result = GetOptions ("quiet|q"  => \$quiet,
                         "help|h|?" => \$help);

if ($help)
{
    usage();
}

my $reg = SUSE::RegistrationStatus->new();
my $status = $reg->isRegistered();

if(!$quiet)
{
    my $details = $reg->details();
    print "$details";
}
if ($status)
{
    exit 0;
}
exit 1;

#
# Manpage
#

=head1 NAME

isRegistered

=head1 SYNOPSIS

isRegistered [options]

=head1 DESCRIPTION

C<isRegistered> checks if this system is registered at NCC, SMT, SUSE Manager or a SLMS server.

=head1 OPTIONS

=over 4

=item --quiet -q

Do not print messages on stdout or stderr. Only the exit code indicate if
the system is registered or not.

=back

=head1 AUTHORS and CONTRIBUTORS

Duncan Mac-Vicar Prett, Michael Calmer

=head1 LICENSE

Copyright (c) 2011 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 version 2.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

=cut
