#!/bin/bash
#
# $Id$
#
# PBA getversions tool
#
# (C) ITEG IT-Engineers GmbH 2010-2021
#
# 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.
#

# pba-getversion
#
# Parses the current version from all found debian*/changelog and spec/*.spec
# 

# params

if [ -n "$(ls -1d debian*/changelog 2>/dev/null)" ] ; then
  echo "INFO: Versions from Debian changelogs:"
  ls -1d debian*/changelog 2>/dev/null |while read DEBCHANGELOG
  do
    DEBVER=$(head -1 ${DEBCHANGELOG} |sed -e 's/^.*(//' |sed -e 's/).*$//')
    echo "${DEBCHANGELOG}: ${DEBVER}"
  done
else
  echo "INFO: No debian*/changelog files to parse versions from."
fi

if [ -n "$(ls -1d spec*/*.spec 2>/dev/null)" ] ; then
  echo "INFO: Versions from rpm specs:"
  ls -1d spec*/*.spec 2>/dev/null |while read RPMSPEC
  do
    RPMVER=$(egrep "^Version: " ${RPMSPEC} |head -1 |cut -f2- -d' ')
    RPMREL=$(egrep "^Release: " ${RPMSPEC} |head -1 |cut -f2- -d' ')
    echo "${RPMSPEC}: ${RPMVER}-${RPMREL}"
  done
else
  echo "INFO: No spec*/*.spec files to parse versions from."
fi
 
