#!/bin/busybox sh
#
# lint-pkg.sh -- check various things in the package
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

. $(dirname $0)/scripts.subr

check_fhs()
{
	printf "${BOLD}==> checking directory hierarchy${RESET}\n"

	if tar tf $1 | grep -Ev '^(bin|etc|include|lib|libexec|local|share|tmp|var)' 1>&2; then
		echo "warning: the above files are not part of Vanilla Linux FHS" 1>&2
	fi
}

check_libtool()
{
	printf "${BOLD}==> checking presence of libtool files:${RESET}\n"

	if tar tf $1 | grep -E '\.la$' 1>&2; then
		echo "warning: the following libtool files must be removed" 1>&2
	fi
}

check_manpages()
{
	printf "${BOLD}==> checking manual pages in uncompressed form:${RESET}\n"

	if tar tf $1 | grep -E 'share/man/man./.*\.(gz|bz2)$'; then
		echo "warning: the above files must not be compressed" 1>&2
	fi
}

usage()
{
	echo "usage: lint-pkg.sh binary-package" 1>&2
	exit 1
}

if [ "$#" -lt 1 ]; then
	usage
	# NOTREACHED
fi

printf "${BOLD}=> checking binary package content for $1${RESET}\n"

check_fhs $1
check_libtool $1
check_manpages $1
