# Template file for 'your-freedom'
pkgname=your-freedom
version=20200919
revision=1
_gitver=295467175d405848f02ee7c98661ee8097528c3c
create_wrksrc=yes
build_style=meta
short_desc="Conflicts with nonfree packages to ensure your system is free"
maintainer="reback00 <reback00@protonmail.com>"
license="GPL-3.0-or-later"
homepage="https://git.parabola.nu/blacklist.git"
distfiles="https://git.parabola.nu/blacklist.git/plain/blacklist.txt?id=${_gitver}>blacklist.txt"
checksum=c0c90cb0f8939cbad725861ca26fb2b1f79e49b920b8e1e5f48d6fb8366a010e

# Set this below to yes to allow some packages that have minor issues
# (like branding, suggesting optional dependencies etc.). But it should
# be used with caution because if you're not careful, some nonfree
# packages may come through.
_allow_semifree=no

# Set this below to yes to allow some packages listed on allowlist.txt.
# allowlist.txt should list each package name that should be allowed on each
# line. In case some package is already libre on default repo and should be
# indicated, enter the package name twice adding a ":" between them. If you
# change the file, remember to clear cache according to the note below in the
# comment.
_use_allowlist=yes

# Set this below to yes to enable denying packages listed on denylist.txt.
# Packages listed on that file will be added to the conflicts list. Useful for
# packages not listed on Parabola's blacklist.txt but present on Void. List
# each package name on each line of that file.
_use_denylist=yes


# Note 1: This package is still under testing. It is inspired by the Parabola's
# your-freedom package. However, libretools is not explored yet.

# Note 2: If you are building this package locally and have built it in the
# past it is a good idea to clean cache to remove any history of it's conflict
# data from past versions:
#   $ rm hostdir/binpkgs/{*-repodata,your-freedom-*.xbps}


# Commands outside functions run multiple times.
# Setting $conflicts once does not work (it forgets it next time).
# There is no way to determine which run will set the conflict correctly.
# This is a workaround to set it when the $conflicts is found as being empty.
if [ -z "$conflicts" ] && [ -f "$XBPS_SRCDISTDIR/${pkgname}-${version}/blacklist.txt" ]; then

	cd "$XBPS_SRCDISTDIR/${pkgname}-${version}"

	if [ "$_allow_semifree" == "yes" ]; then
		conflicts=$(awk -F ':' '{ if ( $1 != $2) {print $1} }' "blacklist.txt" | awk '{print}' ORS=' ')
	else
		conflicts=$(awk -F ':' '{print $1}' "blacklist.txt" | awk '{print}' ORS=' ')
	fi

	if [ "$_use_denylist" == "yes" ] && [ -f "${XBPS_SRCPKGDIR}/${pkgname}/denylist.txt" ]; then
		while read package; do
			if [ "$package" != "" ]; then
				conflicts="$conflicts $package"
			fi
		done < "${XBPS_SRCPKGDIR}/${pkgname}/denylist.txt"
	fi

	if [ "$_use_allowlist" == "yes" ] && [ -f "${XBPS_SRCPKGDIR}/${pkgname}/allowlist.txt" ]; then
		while read linedata; do
			if [ "$linedata" != "" ]; then
				package=$( echo "$linedata" | awk -F ':' '{print $1}' )
				if [ "$expr" == "" ]; then
					expr="$package\s*"
				else
					expr="$expr\|$package\s*"
				fi
			fi
		done < "${XBPS_SRCPKGDIR}/${pkgname}/allowlist.txt"
		conflicts=$(echo "${conflicts}" | sed "s/\($expr\)//g")
	fi

fi
