#! /bin/bash
#
# Copyright (c) 2009, 2010, 2011, 2012 SUSE Linux Product GmbH, Germany.
# Licensed under GPL v2, see COPYING file for details.
#
# Written by Michael Matz and Stephan Coolo
# Enhanced by Andreas Jaeger
declare -i watchdog_host_timeout_seconds='3600'
declare -i watchdog_touch_percent_prior_timeout='25'
declare -i watchdog_next_touch_seconds=0
function watchdog_reset
{
local uptime idle
local -i next_touch now
read uptime idle < /proc/uptime
now="${uptime%.*}"
next_touch=$(( ${now} + ( (${watchdog_host_timeout_seconds} * ${watchdog_touch_percent_prior_timeout}) / 100 ) ))
watchdog_next_touch_seconds=${next_touch}
}
function watchdog_touch
{
local uptime idle
local -i next_touch now
read uptime idle < /proc/uptime
now="${uptime%.*}"
if test "${now}" -lt "${watchdog_next_touch_seconds}"
then
return
fi
echo 'build-compare touching host-watchdog.'
watchdog_reset
}
function wprint
{
echo "$@"
watchdog_reset
}
filter_disasm()
{
[[ $nofilter ]] && return
sed -e '
s/^ *[0-9a-f]\+://
s/\$0x[0-9a-f]\+/$something/
s/callq *[0-9a-f]\+/callq /
s/# *[0-9a-f]\+/# /
s/\(0x\)\?[0-9a-f]\+(/offset(/
s/[0-9a-f]\+
s/^<\(.*\)>:/\1:/
s/<\(.*\)+0x[0-9a-f]\+>/<\1 + ofs>/
'
}
filter_xenefi() {
# PE32+ executable (EFI application) x86-64 (stripped to external PDB), for MS Windows
perl -e "open fh, '+<', '$f'; seek fh, 0x80 + 0x08, SEEK_SET; print fh 'time'; seek fh, 0x80 + 0x58, SEEK_SET; print fh 'chck';"
}
filter_pyc() {
perl -e "open fh, '+<', '$f'; seek fh, 4, SEEK_SET; print fh '0000';"
}
filter_dvi() {
# Opcodes 247: pre; i[1], num[4], den[4], mag[4], k[1], x[k]
perl -e "
my \$rec;
open fh, '+<', '$f';
my \$dummy = read fh, \$rec, 15;
(\$pre, \$i, \$num, \$den, \$mag, \$k) = unpack('C2 N3 C', \$rec);
seek fh, 15, SEEK_SET;
while (\$k > 0) {
print fh '0';
\$k--;
}
"
}
filter_png() {
convert "$f" +set date:create +set date:modify "${f}.$PPID.$$"
mv -f "${f}.$PPID.$$" "${f}"
}
filter_emacs_lisp() {
sed -i -e '
s|^;;; .ompiled by abuild@.* on ... ... .. ..:..:.. ....|;;; compiled by abuild@buildhost on Wed Jul 01 00:00:00 2009|
s|^;;; from file .*\.el|;;; from file /home/abuild/rpmbuild/BUILD/anthy-9100h/src-util/elc.8411/anthy-azik.el|
s|^;;; emacs version .*|;;; emacs version 21.5 (beta34) "kale" XEmacs Lucid.|
s|^;;; bytecomp version .*|;;; bytecomp version 2.28 XEmacs; 2009-08-09.|
' "$f"
}
filter_pdf() {
# PDF files contain a unique ID, remove it
# Format of the ID is:
# /ID [<9ACE247A70CF9BEAFEE15E116259BD6D> <9ACE247A70CF9BEAFEE15E116259BD6D>]
# with optional spaces. pdftex creates also:
# /CreationDate (D:20120103083206Z)
# /ModDate (D:20120103083206Z)
# and possibly XML metadata as well
sed -i \
'/obj/,/endobj/{
s%/ID \?\[ \?<[^>]\+> \?<[^>]\+> \?\]%/IDrandom%g;
s%/CreationDate \?(D:[^)]*)%/CreationDate (D: XXX)%g;
s%/ModDate \?(D:[^)]*)%/ModDate (D: XXX)%g;
s%[^<]*%XXX%g;
s%[^<]*%XXX%g;
s%[^<]*%XXX%g;
s%[^<]*%XXX%g;
s%[^<]*%XXX%g;
}' "$f"
}
filter_ps() {
sed -i -e '
/^%%CreationDate:[[:blank:]]/d
/^%%Creator:[[:blank:]]groff[[:blank:]]version[[:blank:]]/d
/^%DVIPSSource:[[:blank:]]/d
' "$f"
}
filter_mo() {
sed -i -e "s,POT-Creation-Date: ....-..-.. ..:..+....,POT-Creation-Date: 1970-01-01 00:00+0000," "$f"
}
filter_linuxrc_config() {
sed -i '/^InitrdID:/s@^.*@InitrdID: something@' "$f"
}
# call specified filter on old and new file
filter_generic()
{
filtertype=$1
[[ $nofilter ]] && return
local f
for f in "old/$file" "new/$file" ; do
eval "filter_$filtertype $f"
done
}
# returns 0 if both files are identical
# returns 1 if files differ or one is missing
# returns 2 if files must be processed further
verify_before_processing()
{
local file="$1"
local cmpout="$2"
if test ! -e "old/$file"; then
wprint "Missing in old package: $file"
return 1
fi
if test ! -e "new/$file"; then
wprint "Missing in new package: $file"
return 1
fi
# consider only files and symlinks
if test ! -f "old/$file"; then
return 0
fi
if test ! -f "new/$file"; then
return 0
fi
if cmp -b "old/$file" "new/$file" > "${cmpout}" ; then
return 0
fi
if test -s "${cmpout}" ; then
# cmp produced output for futher processing
return 2
fi
# cmp failed
return 1
}
diff_two_files()
{
local offset length
verify_before_processing "${file}" "${dfile}"
case "$?" in
0) return 0 ;;
1) return 1 ;;
*) ;;
esac
offset=`sed 's@^.*differ: byte @@;s@,.*@@' < $dfile`
wprint "$file differs at offset '$offset' ($ftype)"
offset=$(( ($offset >> 6) << 6 ))
length=512
diff -u \
--label "old $file (hex)" \
--label "new $file (hex)" \
<( hexdump -C -s $offset -n $length "old/$file" ) \
<( hexdump -C -s $offset -n $length "new/$file" ) | $buildcompare_head
return 1
}
trim_man_first_line()
{
# Handles the first line if it is like:
#.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
#.\" Automatically generated by Pandoc 2.9.2.1
#.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.43.3.
local f=$1
[[ $nofilter ]] && return
sed -i -e '1{
s|^\.\\"[[:blank:]]\+Automatically[[:blank:]]generated[[:blank:]]by[[:blank:]].*|.\\" Automatically generated by SomeTool|
s|^\.\\"[[:blank:]]\+DO[[:blank:]]NOT[[:blank:]]MODIFY[[:blank:]]THIS[[:blank:]]FILE![[:blank:]]\+It[[:blank:]]was[[:blank:]]generated[[:blank:]]by[[:blank:]]help2man[[:blank:]].*|.\\" Overly verbose help2man|
}' $f
}
trim_man_TH()
{
# Handles lines like:
# .TH debhelper 7 "2010-02-27" "7.4.15" "Debhelper"
# .TH DIRMNGR-CLIENT 1 2010-02-27 "Dirmngr 1.0.3" "GNU Privacy Guard"
# .TH ccmake 1 "March 06, 2010" "ccmake 2.8.1-rc3"
# .TH QEMU-IMG 1 "2010-03-14" " " " "
# .TH kdecmake 1 "May 07, 2010" "cmake 2.8.1"
# .TH "appender.h" 3 "12 May 2010" "Version 1.2.1" "log4c" \" -*- nroff -*-
# .TH "appender.h" 3 "Tue Aug 31 2010" "Version 1.2.1" "log4c" \" -*- nroff -*-
# .TH "OFFLINEIMAP" "1" "11 May 2010" "John Goerzen" "OfflineIMAP Manual"
# .TH gv 3guile "13 May 2010"
#.TH "GIT\-ARCHIMPORT" "1" "09/13/2010" "Git 1\&.7\&.1" "Git Manual"
# .TH LDIRECTORD 8 "2010-10-20" "perl v5.12.2" "User Contributed Perl Documentation"
# .TH ccmake 1 "February 05, 2012" "ccmake 2.8.7"
# .TH "appender.h" 3 "Tue Aug 31 2010" "Version 1.2.1" "log4c" \" -*- nroff -*-
# .TH ARCH "1" "September 2010" "GNU coreutils 8.5" "User Commands"
# .TH "GCM-CALIBRATE" "1" "03 February 2012" "" ""
#.TH Locale::Po4a::Xml.pm 3pm "2015-01-30" "Po4a Tools" "Po4a Tools"
local f=$1
[[ $nofilter ]] && return
# (.TH quoted section) (quoted_date)(*)
sed -i -e 's|^\([[:blank:]]*\.TH[[:blank:]]\+"[^"]\+"[[:blank:]]\+[^[:blank:]]\+\)[[:blank:]]\+\("[^"]\+"\)\([[:blank:]]\+.*\)\?|\1 "qq2000-01-01"\3|' $f
# (.TH unquoted section) (quoted_date)(*)
sed -i -e 's|^\([[:blank:]]*\.TH[[:blank:]]\+[^"][^[:blank:]]\+[[:blank:]]\+[^[:blank:]]\+\)[[:blank:]]\+\("[^"]\+"\)\([[:blank:]]\+.*\)\?|\1 "uq2000-02-02"\3|' $f
# (.TH quoted section) (unquoted_date)(*)
sed -i -e 's|^\([[:blank:]]*\.TH[[:blank:]]\+"[^"]\+"[[:blank:]]\+[^[:blank:]]\+\)[[:blank:]]\+\([^"][^[:blank:]]\+\)\([[:blank:]]\+.*\)\?|\1 qu2000-03-03\3|' $f
# (.TH unquoted section) (unquoted_date)(*)
sed -i -e 's|^\([[:blank:]]*\.TH[[:blank:]]\+[^"][^[:blank:]]\+[[:blank:]]\+[^[:blank:]]\+\)[[:blank:]]\+\([^"][^[:blank:]]\+\)\([[:blank:]]\+.*\)\?|\1 uu2000-04-04\3|' $f
}
strip_numbered_anchors()
{
# Remove numbered anchors on Docbook / HTML files.
#
#
# 1 TeX
#
#
#