#! /usr/bin/perl
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# Copyright (C) 2010  Raphael Bossek <bossekr@debian.org>
#

use strict;
use lib "/usr/share/bugzilla3";

# Work-arround to be able to use Bugzilla functionality where
# shutdownhtml parameter is set.
$0="checksetup_nondebian.pl";
require Bugzilla;
require Bugzilla::Config;
require Getopt::Long;

my $opt_stdin = 0;
my $opt_infile = 0;
Getopt::Long::GetOptions('stdin' => \$opt_stdin, 'infile' => \$opt_infile);

my $p = Bugzilla::Config::read_param_file();
if (exists $p->{$ARGV[0]}) {
	if (not exists $ARGV[1]) {
		if ($opt_stdin) {
			chomp ($ARGV[1] = <STDIN>);
		} else {
			print $p->{$ARGV[0]} . "\n";
		}
	}
	if (exists $ARGV[1]) {
		if ($opt_infile and not $opt_stdin) {
			open (f, $ARGV[1]) or exit (2);
			chomp ($ARGV[1] = <f>);
			close (f);
		}
		$p->{$ARGV[0]} = $ARGV[1];
		Bugzilla::Config::write_params ($p);
	}
} else {
	exit (1);
}

exit (0);
