#!/bin/sh
sqlite3 "$REPOCOP_TEST_TMPDIR/tmp.db" <<EOSQL
attach database '$REPOCOP_TEST_DBDIR/rpm.db' as rpm;
CREATE TEMPORARY TABLE t0 (archpkgid);
CREATE TEMPORARY TABLE t1 (pkgid, total);
CREATE TEMPORARY TABLE t2 (pkgid, usrshare);
CREATE TEMPORARY TABLE t3 (pkgid, total, usrshare);
CREATE TEMPORARY TABLE tc (pkgid, usrshare);
INSERT INTO t0 SELECT pkgid from rpm where arch <> 'noarch';
INSERT INTO t1 SELECT pkgid, SUM(filesize) from t0 LEFT JOIN rpm_files ON pkgid=archpkgid group by pkgid;
-- DELETE FROM t1 WHERE total <= 1048576;
DELETE FROM t1 WHERE total <= 524288;
INSERT INTO t2 SELECT pkgid, SUM(filesize) from t0 LEFT JOIN rpm_files ON pkgid=archpkgid WHERE filename glob '/usr/share/*' group by pkgid;
-- DELETE FROM t2 WHERE usrshare <= 1048576;
DELETE FROM t2 WHERE usrshare <= 524288;
DROP TABLE t0;
INSERT INTO tc SELECT t1.pkgid, usrshare FROM t2 LEFT JOIN t1 ON t1.pkgid=t2.pkgid WHERE usrshare > 524288 AND usrshare = total;
INSERT INTO t3 SELECT t1.pkgid, total, usrshare FROM t2 LEFT JOIN t1 ON t1.pkgid=t2.pkgid WHERE usrshare > 4194304 OR (usrshare > 2097152 AND usrshare/total > 0.5);
DROP TABLE t1;
DROP TABLE t2;
DELETE FROM t3 WHERE pkgid IN (SELECT pkgid FROM tc);
.mode tabs
.output $REPOCOP_TEST_TMPDIR/msg
select pkgid from tc;
.output $REPOCOP_TEST_TMPDIR/msg2
select pkgid from t3;
EOSQL
for i in `cat $REPOCOP_TEST_TMPDIR/msg`; do repocop-test-info -t arch-dep-package-consists-of-usr-share -k $i "The package consists of architecture-independent data in" \
"/usr/share, while it is an architecture-dependent package." \
"This is wasteful of mirror space and bandwidth, as we then end up with" \
"multiple copies of this data, one for each architecture." \
"If the data in /usr/share is not architecture-independent, it is a policy" \
"violation, and in this case, you should move that data elsewhere."; done
for i in `cat $REPOCOP_TEST_TMPDIR/msg2`; do repocop-test-info -k $i "The package has a significant amount of architecture-independent data in" \
"/usr/share, while it is an architecture-dependent package." \
"This is wasteful of mirror space and bandwidth, as we then end up with" \
"multiple copies of this data, one for each architecture." \
"If the data in /usr/share is not architecture-independent, it is a policy" \
"violation, and in this case, you should move that data elsewhere."; done
rm $REPOCOP_TEST_TMPDIR/*
