Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Feb 2021 08:42:39 +0900
From:      Tatsuki Makino <tatsuki_makino@hotmail.com>
To:        freebsd-ports@freebsd.org
Subject:   poudriere: build packages for LOCALBASE=/opt
Message-ID:  <TY2PR02MB4013E1DBA4DF42AD748F7013FAB49@TY2PR02MB4013.apcprd02.prod.outlook.com>
In-Reply-To: <20201103175013.GC31104@blisses.org>
References:  <20201101233032.GC6041@blisses.org> <26d05414-1b0a-0383-4e1e-ec3dd472ff37@FreeBSD.org> <20201102144119.GA31104@blisses.org> <HK2PR02MB400231FA0D8C3DE5E61DD639FA100@HK2PR02MB4002.apcprd02.prod.outlook.com> <20201102234323.GB31104@blisses.org> <TY2PR02MB4013C594BDB36A88A6766DEDFA110@TY2PR02MB4013.apcprd02.prod.outlook.com> <20201103175013.GC31104@blisses.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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:+"$@"}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?TY2PR02MB4013E1DBA4DF42AD748F7013FAB49>