#!/usr/bin/perl
#
# $Id$
#
# PBA rpm release program
#
# (C) IBCL Informatik-Buero e.U. 2010
#
# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

use strict;

require "/usr/lib/pba/pba-functions.pl";
require "/usr/lib/pba/devtools-functions.pl";

$main::scriptName = "pba-rpmrelease";

$main::helpMessage = '
 Syntax:
  '.$main::scriptName.' [CommandOptions] [Options]

 CommandOptions are:
  --help      Prints this help text and exits.
  --version   Prints the version info and exits.

 Without a special command option, pba-release releases a project, 
 i.e. feeds an apropriate pba builder or archive.

 Options are:
  -b directory   Put source package in specified local directory, do not upload.
                 To trigger this behviour directory must exist or contain a /
  -b buildhost   Use buildhost as buildhost.
  -b DEFAULT     Use DefaultBuildHost if configured in devtools.conf,
                 ask back otherwise
  -b AUTO        Use DefaultBuildHost if configured in devtools.conf,
                 use randomly selected buildhost without asking otherwise
  -c configdir   Read configdir/* rather than /etc/pba/*
  -d             Debug mode, logs everything.
  -o selector    Restrict to Only debian.*selector/control
  -q             Quiet mode, supresses informative messages.
  -u             Build unsigned packages; not recommended.
  -v             Verbose verboser, logs more.
';
#-f configfile    Read /etc/pba/configfile rather than /etc/pba/builder.conf

$main::optionList = "b:c:do:quv";

prepareGetopts();

initPBAFunctions();

initDevToolsFunctions();

parseConfig();

checkDevToolsConfig();

readDebianFiles();
readSpecFiles();

checkPackageVersions();
if ($main::versionDifferences > 0) {
  my $nrChangelogFiles = scalar(@main::changelogFiles);
  my $nrSpecFiles = scalar(@main::specFiles);
  print "ERROR: ".$main::versionDifferences." version differences among ".$nrChangelogFiles." debian*/changelog and ".$nrSpecFiles." spec*/*.spec files.\n";
  print "The top version from ".$main::topVersionChangelog." is ".$main::topVersionVersion.".\n";
  cleanupAndDie("FATAL: Refusing to release inconsistent versions. Try to use pba-syncchangelogs.\n");
  exit 1;
}

releaseSRPMPackages();

exit 0;

