poudriere: build packages for LOCALBASE=/opt

Tatsuki Makino tatsuki_makino at hotmail.com
Wed Feb 3 23:42:51 UTC 2021


Hello.

To create a package for LOCALBASE=/opt, export LOCALBASE=/opt alone is not enough. First gettext-runtime will fail.
There are still some tweaks to be done to make it work properly to path and libraries.
I've created a patch (only a few people have it :) ) that does that when we create or update a jail, but it requires creating multiple jails, which is a pain.
So I created a hook script (see Hooks of poudriere(8)) like the one at the end of this email.
This will be tweaked when poudriere mount the reference jail. It always works when the environment variable LOCALBASE is not /usr/local.
For this reason, it is a good idea to write the following in poudriere.conf.

# if name of the jail starts with opt. (e.g. -j opt13amd64)
case "${jail}" in
opt*)
	export LOCALBASE=/opt
	;;
esac

# if name of the portstree starts with opt. (e.g. -p opt)
case "${ptname}" in
opt*)
	export LOCALBASE=/opt
	;;
esac

# if name of the setname is opt. (e.g. -z opt)
case "${setname}" in
opt)
	export LOCALBASE=/opt
	;;
esac

Best regards.

Here is the hook script. =========================================

#! /bin/sh

hook_jail_use_non_default_localbase ()
{
	if [ "${0##*/}" != jail.sh ] ; then
		echo "This script should be installed to ${POUDRIERED}/hooks/jail.sh"
		return 1
	fi

	case "${1}" in	# (
	mount)
		local mnt="${2:-}"
		if [ "${mnt}" != "${MASTERMNT:-/nonexistent}" ] ; then
			#echo "mount point is different from the reference"
			return 0
		fi

		if [ "${LOCALBASE:-/usr/local}" = /usr/local ] ; then
			#echo "LOCALBASE is /usr/local"
			return 0
		fi

		#echo "LOCALBASE -> ${LOCALBASE}"

		local lbq login_env

		lbq="$(echo -n "${LOCALBASE}" | sed -e 's,/,\\&,g;')"
		login_env=",LOCALBASE=${lbq}"

		sed -i '' \
			-e "/:setenv=/{s/,LOCALBASE=[^,:]*//;s/:\(setenv.*\):/:\1${login_env}:/;};" \
			-e "/:path=/{/${lbq}/!{s/\/usr\/local\(\/[^ :]*\)/& ${lbq}\1/g;};};" \
			"${mnt}/etc/login.conf"
		cap_mkdb "${mnt}/etc/login.conf"

		# for interactive shell
		if [ "${mnt}/.cshrc" -ef "${mnt}/root/.cshrc" ] ; then
			sed -i '' \
				-e "/path =/{/${lbq}/!{s/\/usr\/local\(\/[^ )]*\)/& ${lbq}\1/g;};};" \
				"${mnt}/root/.cshrc"
			ln -f -v -- "${mnt}/root/.cshrc" "${mnt}/.cshrc"
		else
			sed -i '' \
				-e "/path =/{/${lbq}/!{s/\/usr\/local\(\/[^ )]*\)/& ${lbq}\1/g;};};" \
				"${mnt}/root/.cshrc" "${mnt}/.cshrc"
		fi
		if [ "${mnt}/.profile" -ef "${mnt}/root/.profile" ] ; then
			sed -i '' \
				-e "/PATH=/{/${lbq}/!{s/\/usr\/local\(\/[^:]*\)/&:${lbq}\1/g;};};" \
				"${mnt}/root/.profile"
			ln -f -v -- "${mnt}/root/.profile" "${mnt}/.profile"
		else
			sed -i '' \
				-e "/PATH=/{/${lbq}/!{s/\/usr\/local\(\/[^:]*\)/&:${lbq}\1/g;};};" \
				"${mnt}/root/.profile" "${mnt}/.profile"
		fi

		sysrc -R "${mnt}" -x \
			"local_startup" \
			"ldconfig_paths" \
			"ldconfigsoft_paths" \
			"ldconfig_paths_aout" \
			"ldconfig_local_dirs" \
			"ldconfig_local32_dirs" \
			"ldconfig_localsoft_dirs"

		sysrc -R "${mnt}" \
			"local_startup+= ${LOCALBASE}/etc/rc.d" \
			"ldconfig_paths+= ${LOCALBASE}/lib ${LOCALBASE}/lib/compat/pkg" \
			"ldconfigsoft_paths+= ${LOCALBASE}/libsoft" \
			"ldconfig_paths_aout+= ${LOCALBASE}/lib/aout" \
			"ldconfig_local_dirs+= ${LOCALBASE}/libdata/ldconfig" \
			"ldconfig_local32_dirs+= ${LOCALBASE}/libdata/ldconfig32" \
			"ldconfig_localsoft_dirs+= ${LOCALBASE}/libdata/ldconfigsoft"

		;;	# (
	*)
		;;
	esac
}

hook_jail_use_non_default_localbase ${1:+"$@"}


More information about the freebsd-ports mailing list