3d135aa5 |
#! /bin/bash
|
627095dd |
function check-for-header()
{ |
f82f5d82 |
for n in Summary Name Version Release License Group Vendor Distribution ; do |
627095dd |
grep -e "^$n:" $1 > /dev/null
if [ $? -ne 0 ] ; then
echo "ERROR in $1: $n: must present in the header"
exit 1
fi
done
}
|
3d135aa5 |
# Dist tag must present in Release:
function check-for-dist-tag()
{
cat $1 | grep "Release:" | grep "%{?dist}" > /dev/null
if [ "$?" -ne 0 ];then
echo "ERROR in $1: Release field doesn't contain %{?dist} tag"
cat $1 | grep "Release:"
exit 1
fi
}
# Check for Version-Release matching top entry from the Changelog
function check-for-correct-version()
{
versions=`sed -e '1,/%changelog/d' $1 | grep '<' | grep '>' | grep '*' | cut -f 2 -d '>'`;
latest_version_in_changelog=`echo $versions | cut -d ' ' -f 1`
version=`cat $1 | grep Version: | cut -f 2 -d ':' | sed 's/ //g' | sed '1!d'`;
sub_version=`cat $1 | grep Release: | cut -f 2 -d ':' | cut -f 1 -d '%' | sed 's/ //g' | tr -d ' '`
s=`echo ${sub_version//[[:blank:]]/}`
v=`echo ${version//[[:blank:]]/}`
full_version=${v}-${s};
if [ "${latest_version_in_changelog}" != "${full_version}" ]; then
echo "ERROR in $1: Top changelog entry version ${latest_version_in_changelog} does NOT MATCH package version ${full_version}"
echo "Please update %changelog or Version,Release: in $1 to make them match each other"
exit 1
fi
}
|
627095dd |
# Changelog should have:
# - correct day of week for the date
# - descending chronological order |
9c04fdb7 |
# - whitespaces are ignored while validating dates |
3d135aa5 |
function check-for-bogus-dates()
{ |
9c04fdb7 |
local prev_epoch_seconds=$(date +%s)
local D=''
local m=''
local d=''
local y=''
local epoch_seconds=''
|
43325296 |
sed -e '1,/%changelog/d' "$1" | grep '^\*' | awk '{printf "%s %s %02d %04d\n", $2, $3, $4, $5}' | \ |
9c04fdb7 |
while read D m d y
do
day=$(date --date="$m $d $y" '+%a') |
3d135aa5 |
if [ "${D}" != "${day}" ]; then |
8f56b626 |
echo "ERROR in $1: bogus date $m $d $y found - actual day is $day, but found $D" |
3d135aa5 |
exit 1
fi |
9c04fdb7 |
epoch_seconds=$(date --date "$m $d $y" +%s) |
627095dd |
if [ $prev_epoch_seconds -lt $epoch_seconds ]; then
echo "ERROR in $1: %changelog not in descending chronological order" |
9c04fdb7 |
echo "Date validation failed at $D $m $d $y" |
627095dd |
exit 1
fi
prev_epoch_seconds=$epoch_seconds |
3d135aa5 |
done
}
# No trailing spaces
function check-for-trailing-spaces()
{
grep -e " $" $1
if [ $? -eq 0 ] ; then |
627095dd |
echo "ERROR in $1: trailing spaces detected"
exit 1 |
3d135aa5 |
fi
}
|
627095dd |
# Use %configure instead of ./configure
# De not redefine standard paths parameters |
3d135aa5 |
function check-for-configure()
{
grep -e "./configure" $1
if [ $? -eq 0 ] ; then |
627095dd |
echo "ERROR in $1: use %configure instead of ./configure"
exit 1 |
3d135aa5 |
fi |
627095dd |
for param in prefix exec-prefix bindir sbindir libdir includedir sysconfdir datadir libexecdir sharedstatedir mandir infodir localstatedir; do
grep -e "\(configure\|^\)[ \t]\+--$param=%{_$param}" $1
if [ $? -eq 0 ] ; then
echo "ERROR in $1: --$param can be ommited when using %configure"
exit 1
fi
done |
3d135aa5 |
}
# All BuildRequires should on the top
function check-for-buildrequires()
{
sed -e '1,/%description/d' $1 | grep -e "^BuildRequires"
if [ $? -eq 0 ] ; then |
627095dd |
echo "ERROR in $1: BuildRequires in subpackages detected."
echo "Move all BuildRequires to the top"
exit 1 |
3d135aa5 |
fi
}
SPECS=`git diff --name-only $1 @ | grep -e "SPECS/.*.spec$"`
for i in `echo $SPECS`;
do
echo Analyzing $i ...
if [ ! -f $i ]; then
echo "$i is removed by the current changeset."
else |
627095dd |
check-for-header $i |
3d135aa5 |
check-for-dist-tag $i
check-for-correct-version $i
check-for-bogus-dates $i
check-for-trailing-spaces $i
check-for-configure $i
check-for-buildrequires $i
fi
done |