#!/bin/sh

# sbopkglint test, must be sourced by sbopkglint (not run standalone).

# PKG, PRGNAM, VERSION, ARCH are set by sbopkglint. also the current
# directory is the root of the installed package tree.

# Unlike the rest of the tests (those ending in .t.sh), this one runs
# before the package's doinst.sh does. Purpose for this is to check
# for the existence of stuff in the package tarball that shouldn't be
# there (e.g. /usr/info/dir), but might correctly be created by doinst.sh.

#######################################################################
badfiles="\
usr/info/dir \
usr/info/dir.gz \
usr/share/icons/hicolor/icon-theme.cache \
usr/share/glib-2.0/schemas/gschemas.compiled \
usr/share/mime/mime.cache \
usr/share/applications/mimeinfo.cache \
usr/lib/gio/modules/giomodule.cache \
usr/lib64/gio/modules/giomodule.cache \
usr/lib/perl5/perllocal.pod \
usr/lib64/perl5/perllocal.pod \
var/cache/fontconfig/CACHEDIR.TAG \
var/cache/man/usr-man/CACHEDIR.TAG"

for i in $badfiles; do
	[ -e "$i" ] && warn "package contains forbidden file: $i"
done

if [ -d usr/share/fonts ]; then
	find_warnfiles "package contains forbidden file(s):" \
		usr/share/fonts -name 'fonts.*'
fi

find_warnfiles "package contains actual symlinks:" \
	-P . -type l

[ -f install/slack-desc ] || warn "required file install/slack-desc is missing"

# Next test is supposed to complain if the package is "empty". What
# "empty" means is, there's nothing in the package outside of usr/doc
# and install/. This happens when a SlackBuild doesn't do error checking
# (no "set -e" or "|| exit 1" tests) and the 'make' or whatever it
# does fails, undetected.
# This is a stopgap, really. If someone submits a SlackBuild that doesn't
# do any error checking, it will always create a package and exit
# with 0 status (success)... if it does something more complex than
# build/install a single tarball, part of it might succeed and another
# part might fail. There's no way to detect a situation like that in
# the general case.

if [ "$( find . -type d -maxdepth 2 -a \! \( -path ./usr -o -path ./usr/doc -o -path . -o -path ./install \) )" = "" ]; then
	warn "package is empty (contains nothing outside of install/ and/or usr/doc)"
fi
