1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
8 # just use "upstream" sources
11 S="${WORKDIR}/${MY_P}"
13 DESCRIPTION="Filesystem baselayout and init scripts"
14 HOMEPAGE="https://wiki.gentoo.org/wiki/No_homepage"
15 if [[ ${PV} = 9999 ]]; then
16 EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/${MY_PN}.git"
19 SRC_URI="https://gitweb.gentoo.org/proj/${MY_PN}.git/snapshot/${MY_P}.tar.bz2"
20 KEYWORDS="~arm ~arm64 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris ~x86-winnt"
25 IUSE="build kernel_FreeBSD kernel_linux +split-usr"
28 # commits in reverse order as listed by:
29 # git log --decorate=no --oneline --no-abbrev-commit origin/master..
30 a054fcc408ad48f775f7379834385c6a707d7a53 # also create etc/gentoo-release
31 5926fe447541607ed137d67ca84080326584b2fc # create usr/bin during layout-usrmerge
32 395424f90c8ca6969589905cbf86d74fae9d7ea6 # add prefix-stack support
33 95a8e95af948014d024842892be1405d656ab5fc # add prefix-guest support
34 c88ceddbfc6a965dc0153aef21e012e774d9e30c # sync prefix usage for Makefile target 'layout'
35 c9338e89cdb603c1e08998bba28fbc977a62fc51 # add prefix support per Makefile target 'install'
37 for my_c in ${my_prefix_commits[*]}
39 SRC_URI+=" https://github.com/haubi/gentoo-baselayout/commit/${my_c}.patch -> ${PN}-${my_c}.patch"
40 PATCHES=( "${DISTDIR}/${PN}-${my_c}.patch" "${PATCHES[@]}" )
42 unset my_prefix_commits my_c
48 # Create our multilib dirs - the Makefile has no knowledge of this
50 use prefix && return 0
51 local dir def_libdir libdir libdirs
52 local prefix prefix_lst
53 def_libdir=$(get_abi_LIBDIR $DEFAULT_ABI)
54 libdirs=$(get_all_libdirs)
55 : ${libdirs:=lib} # it isn't that we don't trust multilib.eclass...
57 if [[ -z "${SYMLINK_LIB}" || ${SYMLINK_LIB} = no ]] ; then
58 prefix_lst=( "${EROOT}"{,usr/,usr/local/} )
59 for prefix in ${prefix_lst[@]}; do
60 for libdir in ${libdirs}; do
61 dir="${prefix}${libdir}"
62 if [[ -e "${dir}" ]]; then
63 [[ ! -d "${dir}" ]] &&
64 die "${dir} exists but is not a directory"
67 if ! use split-usr && [[ ${prefix} = ${EROOT} ]]; then
68 einfo "symlinking ${dir} to usr/${libdir}"
69 ln -s usr/${libdir} ${dir} ||
70 die " Unable to make ${dir} symlink"
72 einfo "creating directory ${dir}"
74 die "Unable to create ${dir} directory"
81 [ -z "${def_libdir}" ] &&
82 die "your DEFAULT_ABI=$DEFAULT_ABI appears to be invalid"
84 # figure out which paths should be symlinks and which should be directories
86 for libdir in ${libdirs} ; do
87 if use split-usr ; then
88 exp=( {,usr/,usr/local/}${libdir} )
90 exp=( {usr/,usr/local/}${libdir} )
92 for d in "${exp[@]}" ; do
93 # most things should be dirs
94 if [ "${SYMLINK_LIB}" = "yes" ] && [ "${libdir}" = "lib" ] ; then
95 [ ! -h "${d}" ] && [ -e "${d}" ] && dirs+=" ${d}"
97 [ -h "${d}" ] && syms+=" ${d}"
101 if [ -n "${syms}${dirs}" ] ; then
102 ewarn "Your system profile has SYMLINK_LIB=${SYMLINK_LIB:-no}, so that means you need to"
103 ewarn "have these paths configured as follows:"
104 [ -n "${dirs}" ] && ewarn "symlinks to '${def_libdir}':${dirs}"
105 [ -n "${syms}" ] && ewarn "directories:${syms}"
106 ewarn "The ebuild will attempt to fix these, but only for trivial conversions."
107 ewarn "If things fail, you will need to manually create/move the directories."
111 # setup symlinks and dirs where we expect them to be; do not migrate
112 # data ... just fall over in that case.
113 if use split-usr ; then
114 prefix_lst=( "${EROOT}"{,usr/,usr/local/} )
116 prefix_lst=( "${EROOT}"{usr/,usr/local/} )
118 for prefix in "${prefix_lst[@]}"; do
119 if [ "${SYMLINK_LIB}" = yes ] ; then
120 # we need to make sure "lib" points to the native libdir
121 if [ -h "${prefix}lib" ] ; then
122 # it's already a symlink! assume it's pointing to right place ...
124 elif [ -d "${prefix}lib" ] ; then
125 # "lib" is a dir, so need to convert to a symlink
126 ewarn "Converting ${prefix}lib from a dir to a symlink"
127 rm -f "${prefix}lib"/.keep
128 if rmdir "${prefix}lib" 2>/dev/null ; then
129 ln -s ${def_libdir} "${prefix}lib" || die
131 die "non-empty dir found where we needed a symlink: ${prefix}lib"
134 # nothing exists, so just set it up sanely
135 ewarn "Initializing ${prefix}lib as a symlink"
136 mkdir -p "${prefix}" || die
137 rm -f "${prefix}lib" || die
138 ln -s ${def_libdir} "${prefix}lib" || die
139 mkdir -p "${prefix}${def_libdir}" #423571
142 # we need to make sure "lib" is a dir
143 if [ -h "${prefix}lib" ] ; then
144 # "lib" is a symlink, so need to convert to a dir
145 ewarn "Converting ${prefix}lib from a symlink to a dir"
146 rm -f "${prefix}lib" || die
147 if [ -d "${prefix}lib32" ] ; then
148 ewarn "Migrating ${prefix}lib32 to ${prefix}lib"
149 mv "${prefix}lib32" "${prefix}lib" || die
151 mkdir -p "${prefix}lib" || die
153 elif [ -d "${prefix}lib" ] && ! has lib32 ${libdirs} ; then
154 # make sure the old "lib" ABI location does not exist; we
155 # only symlinked the lib dir on systems where we moved it
158 *-gentoo-freebsd*) ;; # We want it the other way on fbsd.
159 i?86*|x86_64*|powerpc*|sparc*|s390*)
160 if [[ -d ${prefix}lib32 && ! -h ${prefix}lib32 ]] ; then
161 rm -f "${prefix}lib32"/.keep
162 if ! rmdir "${prefix}lib32" 2>/dev/null ; then
163 ewarn "You need to merge ${prefix}lib32 into ${prefix}lib"
164 die "non-empty dir found where there should be none: ${prefix}lib32"
170 # nothing exists, so just set it up sanely
171 ewarn "Initializing ${prefix}lib as a dir"
172 mkdir -p "${prefix}lib" || die
176 if ! use split-usr ; then
177 for libdir in ${libdirs}; do
178 if [[ ! -e "${EROOT}${libdir}" ]]; then
179 ln -s usr/"${libdir}" "${EROOT}${libdir}"
186 # This is written in src_install (so it's in CONTENTS), but punt all
187 # pending updates to avoid user having to do etc-update (and make the
188 # pkg_postinst logic simpler).
189 rm -f "${EROOT}"/etc/._cfg????_gentoo-release
191 # We need to install directories and maybe some dev nodes when building
192 # stages, but they cannot be in CONTENTS.
193 # Also, we cannot reference $S as binpkg will break so we do this.
196 if use split-usr ; then
197 emake -C "${ED}/usr/share/${PN}" DESTDIR="${ROOT}" layout
199 emake -C "${ED}/usr/share/${PN}" DESTDIR="${ROOT}" layout-usrmerge
202 rm -f "${ED}"/usr/share/${PN}/Makefile
208 # handle multilib paths. do it here because we want this behavior
209 # regardless of the C library that you're using. we do explicitly
210 # list paths which the native ldconfig searches, but this isn't
211 # problematic as it doesn't change the resulting ld.so.cache or
212 # take longer to generate. similarly, listing both the native
213 # path and the symlinked path doesn't change the resulting cache.
215 for libdir in $(get_all_libdirs) ; do
216 ldpaths+=":${EPREFIX}/${libdir}:${EPREFIX}/usr/${libdir}"
217 ldpaths+=":${EPREFIX}/usr/local/${libdir}"
219 echo "LDPATH='${ldpaths#:}'" >> etc/env.d/50baselayout
224 # although having a prefix, RAP uses full Linux baselayout
225 OS=$(usex prefix-stack prefix-stack \
226 $(usex prefix-guest prefix-guest \
227 $(usex kernel_FreeBSD BSD \
229 # set up immutable Makefile variables once
230 sed -e "/^EPREFIX\s*?\?=\s*$/s|?\?=.*|= ${EPREFIX}|" \
231 -e "/^BROOT\s*?\?=\s*$/s|?\?=.*|= ${BROOT}|" \
232 -e "/^OS\s*?\?=\s*$/s|?\?=.*|= ${OS}|" \
237 emake ROOT="${ROOT}" DESTDIR="${D}" install
240 # need the makefile in pkg_preinst
241 insinto /usr/share/${PN}
244 use prefix-guest || return 0
246 # add a dummy to avoid Portage shebang errors
248 cat > "${ED}"/sbin/runscript <<- EOF
250 source "${EPREFIX}/lib/gentoo/functions.sh"
252 eerror "runscript/openrc-run not supported by Gentoo Prefix Base System release ${PV}" 1>&2
255 chmod 755 "${ED}"/sbin/runscript || die
256 cp "${ED}"/sbin/{runscript,openrc-run} || die
262 # We installed some files to /usr/share/baselayout instead of /etc to stop
263 # (1) overwriting the user's settings
264 # (2) screwing things up when attempting to merge files
265 # (3) accidentally packaging up personal files with quickpkg
266 # If they don't exist then we install them
267 for x in master.passwd passwd shadow group fstab ; do
268 [ -e "${EROOT}/etc/${x}" ] && continue
269 [ -e "${EROOT}/usr/share/baselayout/${x}" ] || continue
270 cp -p "${EROOT}/usr/share/baselayout/${x}" "${EROOT}"/etc
273 # Force shadow permissions to not be world-readable #260993
275 [ -e "${EROOT}/etc/${x}" ] && chmod o-rwx "${EROOT}/etc/${x}"
278 # Take care of the etc-update for the user
279 if [ -e "${EROOT}"/etc/._cfg0000_gentoo-release ] ; then
280 mv "${EROOT}"/etc/._cfg0000_gentoo-release "${EROOT}"/etc/gentoo-release
283 # whine about users that lack passwords #193541
284 if [[ -e "${EROOT}"/etc/shadow ]] ; then
285 local bad_users=$(sed -n '/^[^:]*::/s|^\([^:]*\)::.*|\1|p' "${EROOT}"/etc/shadow)
286 if [[ -n ${bad_users} ]] ; then
288 ewarn "The following users lack passwords!"
293 # whine about users with invalid shells #215698
294 if [[ -e "${EROOT}"/etc/passwd ]] ; then
295 local bad_shells=$(awk -F: 'system("test -e " $7) { print $1 " - " $7}' "${EROOT}"/etc/passwd | sort)
296 if [[ -n ${bad_shells} ]] ; then
298 ewarn "The following users have non-existent shells!"
299 ewarn "${bad_shells}"
303 # https://bugs.gentoo.org/361349
304 if use kernel_linux; then
305 mkdir -p "${EROOT}"/run
307 local found fstype mountpoint
308 while read -r _ mountpoint fstype _; do
309 [[ ${mountpoint} = /run ]] && [[ ${fstype} = tmpfs ]] && found=1
310 done < "${ROOT}"/proc/mounts
312 ewarn "You should reboot now to get /run mounted with tmpfs!"
315 for x in ${REPLACING_VERSIONS}; do
316 if ver_test ${x} -lt 2.4; then
317 ewarn "After updating ${EROOT}/etc/profile, please run"
318 ewarn "env-update && . ${EPREFIX}/etc/profile"
321 if ver_test ${x} -lt 2.6; then
322 ewarn "Please run env-update then log out and back in to"
323 ewarn "update your path."
325 # clean up after 2.5 typos
326 # https://bugs.gentoo.org/show_bug.cgi?id=656380
327 if [[ ${x} == 2.5 ]]; then
328 rm -fr "${EROOT}{,usr"
332 if [[ -e "${EROOT}"/etc/env.d/00basic ]]; then
333 ewarn "${EROOT}/etc/env.d/00basic is now ${EROOT}/etc/env.d/50baselayout"
334 ewarn "Please migrate your changes."