summaryrefslogtreecommitdiff
blob: 9f59ae36b38f615e41b0bbecadc5c907a61745a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=6

inherit eutils multilib libtool

MY_P=${P/-prefix/}  # just use "upstream" sources
DESCRIPTION="Minimal baselayout for Gentoo Prefix installs"
HOMEPAGE="https://www.gentoo.org/"
SRC_URI="mirror://gentoo/${MY_P}.tar.bz2
	https://dev.gentoo.org/~vapier/dist/${MY_P}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~arm ~ppc-aix ~x64-cygwin ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris ~x86-winnt"

RDEPEND="sys-apps/gentoo-functions"
DEPEND="${RDEPEND}"

S=${WORKDIR}/${MY_P}

pkg_preinst() {
	# This is written in src_install (so it's in CONTENTS), but punt all
	# pending updates to avoid user having to do etc-update (and make the
	# pkg_postinst logic simpler).
	rm -f "${EROOT}"/etc/._cfg????_gentoo-release
}

src_prepare() {
	if use prefix-chain; then
		epatch "${FILESDIR}"/baselayout-${PV}-prefix-chaining.patch

		# need to set the PKG_CONFIG_PATH globally for this prefix, when
		# chaining is enabled, since pkg-config may not be installed locally,
		# but still .pc files should be found for all RDEPENDable prefixes in
		# the chain.
		echo "PKG_CONFIG_PATH=\"/usr/lib/pkgconfig:/usr/share/pkgconfig\"" >> etc/env.d/00basic
		echo "PORTAGE_OVERRIDE_EPREFIX=\"${EPREFIX}\"" >> etc/env.d/00basic
		echo "PORTAGE_CONFIGROOT=\"${EPREFIX}\"" >> etc/env.d/00basic
		echo "EPREFIX=\"${EPREFIX}\"" >> etc/env.d/00basic
	fi
	default
}

src_install() {
	# make functions.sh available in /etc/init.d (from gentoo-functions)
	# Note: we cannot replace the symlink with a file here, or Portage will
	# config-protect it, and etc-update can't handle symlink to file updates
	dodir etc/init.d
	dosym ../../lib/gentoo/functions.sh /etc/init.d/functions.sh

	dodir etc
	sed \
		-e "/PATH=/!s:/\(etc\|usr/bin\|bin\):\"${EPREFIX}\"/\1:g" \
		-e "/PATH=/s|\([:\"]\)/|\1${EPREFIX}/|g" \
		etc/profile > "${ED}"/etc/profile || die
	if ! use prefix-chain; then
		sed \
			-e "/PATH=.*\/sbin/s|\"$|:/usr/sbin:/sbin\"|" \
			-e "/PATH=.*\/bin/s|\"$|:/usr/bin:/bin\"|" \
			-i "${ED}"/etc/profile || die
	fi
	dodir etc/env.d
	sed \
		-e "s:/\(etc/env.d\|opt\|usr\):${EPREFIX}/\1:g" \
		-e "/^PATH=/s|\"$|:${EPREFIX}/usr/sbin:${EPREFIX}/sbin\"|" \
		etc/env.d/00basic > "${ED}"/etc/env.d/00basic || die
	dodoc ChangeLog.svn

	# add the host OS MANPATH
	if [[ -d "${ROOT}"/usr/share/man ]] ; then
		echo 'MANPATH="/usr/share/man"' > "${ED}"/etc/env.d/99basic || die
	fi

	# rc-scripts version for testing of features that *should* be present
	echo "Gentoo Prefix Base System release ${PV}" > "${ED}"/etc/gentoo-release

	# FHS compatibility symlinks stuff
	dosym /var/tmp /usr/tmp

	# add a dummy to avoid Portage shebang errors
	dodir sbin
	cat > "${ED}"/sbin/runscript <<- EOF
		#!/usr/bin/env sh
		source "${EPREFIX}/lib/gentoo/functions.sh"

		eerror "runscript/openrc-run not supported by Gentoo Prefix Base System release ${PV}" 1>&2
		exit 1
	EOF
	chmod 755 "${ED}"/sbin/runscript || die
	cp "${ED}"/sbin/{runscript,openrc-run} || die
}

pkg_postinst() {
	# Take care of the etc-update for the user
	if [ -e "${EROOT}"/etc/._cfg0000_gentoo-release ] ; then
		mv "${EROOT}"/etc/._cfg0000_gentoo-release "${EROOT}"/etc/gentoo-release
	fi

	# baselayout leaves behind a lot of .keep files, so let's clean them up
	find "${EROOT}"/lib/rcscripts/ -name .keep -exec rm -f {} + 2>/dev/null
	find "${EROOT}"/lib/rcscripts/ -depth -type d -exec rmdir {} + 2>/dev/null
}