1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 inherit eutils multilib
7 DESCRIPTION="Filesystem baselayout and init scripts"
8 HOMEPAGE="https://www.gentoo.org/"
9 SRC_URI="mirror://gentoo/${P}.tar.bz2
10 https://dev.gentoo.org/~vapier/dist/${P}.tar.bz2"
14 KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
15 IUSE="build kernel_linux"
21 # Create our multilib dirs - the Makefile has no knowledge of this
23 local syms=$1 dirs=$2 def_libdir=$3
25 [ -z "${syms}${dirs}" ] && return
27 ewarn "Your system profile has SYMLINK_LIB=${SYMLINK_LIB}, so that means"
28 if [ -z "${syms}" ] ; then
29 ewarn "you need to have these paths as symlinks to ${def_libdir}:"
34 local libdir libdirs=$(get_all_libdirs) def_libdir=$(get_abi_LIBDIR $DEFAULT_ABI)
35 : ${libdirs:=lib} # it isn't that we don't trust multilib.eclass...
37 [ -z "${def_libdir}" ] && die "your DEFAULT_ABI=$DEFAULT_ABI appears to be invalid"
39 # figure out which paths should be symlinks and which should be directories
41 for libdir in ${libdirs} ; do
42 exp=( {,usr/,usr/local/}${libdir} )
43 for d in "${exp[@]/#/${ROOT}}" ; do
44 # most things should be dirs
45 if [ "${SYMLINK_LIB}" = "yes" ] && [ "${libdir}" = "lib" ] ; then
46 [ ! -h "${d}" ] && [ -e "${d}" ] && dirs+=" ${d}"
48 [ -h "${d}" ] && syms+=" ${d}"
52 if [ -n "${syms}${dirs}" ] ; then
53 ewarn "Your system profile has SYMLINK_LIB=${SYMLINK_LIB:-no}, so that means you need to"
54 ewarn "have these paths configured as follows:"
55 [ -n "${dirs}" ] && ewarn "symlinks to '${def_libdir}':${dirs}"
56 [ -n "${syms}" ] && ewarn "directories:${syms}"
57 ewarn "The ebuild will attempt to fix these, but only for trivial conversions."
58 ewarn "If things fail, you will need to manually create/move the directories."
62 # setup symlinks and dirs where we expect them to be; do not migrate
63 # data ... just fall over in that case.
65 for prefix in "${ROOT}"{,usr/,usr/local/} ; do
66 if [ "${SYMLINK_LIB}" = yes ] ; then
67 # we need to make sure "lib" points to the native libdir
68 if [ -h "${prefix}lib" ] ; then
69 # it's already a symlink! assume it's pointing to right place ...
71 elif [ -d "${prefix}lib" ] ; then
72 # "lib" is a dir, so need to convert to a symlink
73 ewarn "Converting ${prefix}lib from a dir to a symlink"
74 rm -f "${prefix}lib"/.keep
75 if rmdir "${prefix}lib" 2>/dev/null ; then
76 ln -s ${def_libdir} "${prefix}lib" || die
78 die "non-empty dir found where we needed a symlink: ${prefix}lib"
81 # nothing exists, so just set it up sanely
82 ewarn "Initializing ${prefix}lib as a symlink"
83 mkdir -p "${prefix}" || die
84 rm -f "${prefix}lib" || die
85 ln -s ${def_libdir} "${prefix}lib" || die
86 mkdir -p "${prefix}${def_libdir}" #423571
89 # we need to make sure "lib" is a dir
90 if [ -h "${prefix}lib" ] ; then
91 # "lib" is a symlink, so need to convert to a dir
92 ewarn "Converting ${prefix}lib from a symlink to a dir"
93 rm -f "${prefix}lib" || die
94 if [ -d "${prefix}lib32" ] ; then
95 ewarn "Migrating ${prefix}lib32 to ${prefix}lib"
96 mv "${prefix}lib32" "${prefix}lib" || die
98 mkdir -p "${prefix}lib" || die
100 elif [ -d "${prefix}lib" ] ; then
101 # make sure the old "lib" ABI location does not exist; we
102 # only symlinked the lib dir on systems where we moved it
105 *-gentoo-freebsd*) ;; # We want it the other way on fbsd.
106 i?86*|x86_64*|powerpc*|sparc*|s390*)
107 if [ -d "${prefix}lib32" ] ; then
108 rm -f "${prefix}lib32"/.keep
109 if ! rmdir "${prefix}lib32" 2>/dev/null ; then
110 ewarn "You need to merge ${prefix}lib32 into ${prefix}lib"
111 die "non-empty dir found where there should be none: ${prefix}lib32"
117 # nothing exists, so just set it up sanely
118 ewarn "Initializing ${prefix}lib as a dir"
119 mkdir -p "${prefix}" || die
120 rm -f "${prefix}lib" || die
121 ln -s ${def_libdir} "${prefix}lib" || die
128 # Bug #217848 - Since the remap_dns_vars() called by pkg_preinst() of
129 # the baselayout-1.x ebuild copies all the real configs from the user's
130 # /etc/conf.d into ${D}, it makes them all appear to be the default
131 # versions. In order to protect them from being unmerged after this
132 # upgrade, modify their timestamps.
133 touch "${ROOT}"/etc/conf.d/* 2>/dev/null
135 # This is written in src_install (so it's in CONTENTS), but punt all
136 # pending updates to avoid user having to do etc-update (and make the
137 # pkg_postinst logic simpler).
138 rm -f "${ROOT}"/etc/._cfg????_gentoo-release
140 # We need to install directories and maybe some dev nodes when building
141 # stages, but they cannot be in CONTENTS.
142 # Also, we cannot reference $S as binpkg will break so we do this.
145 emake -C "${D}/usr/share/${PN}" DESTDIR="${ROOT}" layout || die
147 rm -f "${D}"/usr/share/${PN}/Makefile
152 OS=$(usex kernel_FreeBSD BSD Linux) \
157 # need the makefile in pkg_preinst
158 insinto /usr/share/${PN}
159 doins Makefile || die
161 # handle multilib paths. do it here because we want this behavior
162 # regardless of the C library that you're using. we do explicitly
163 # list paths which the native ldconfig searches, but this isn't
164 # problematic as it doesn't change the resulting ld.so.cache or
165 # take longer to generate. similarly, listing both the native
166 # path and the symlinked path doesn't change the resulting cache.
168 for libdir in $(get_all_libdirs) ; do
169 ldpaths+=":/${libdir}:/usr/${libdir}:/usr/local/${libdir}"
171 echo "LDPATH='${ldpaths#:}'" >> "${D}"/etc/env.d/00basic
173 # rc-scripts version for testing of features that *should* be present
174 echo "Gentoo Base System release ${PV}" > "${D}"/etc/gentoo-release
180 # We installed some files to /usr/share/baselayout instead of /etc to stop
181 # (1) overwriting the user's settings
182 # (2) screwing things up when attempting to merge files
183 # (3) accidentally packaging up personal files with quickpkg
184 # If they don't exist then we install them
185 for x in master.passwd passwd shadow group fstab ; do
186 [ -e "${ROOT}etc/${x}" ] && continue
187 [ -e "${ROOT}usr/share/baselayout/${x}" ] || continue
188 cp -p "${ROOT}usr/share/baselayout/${x}" "${ROOT}"etc
191 # Force shadow permissions to not be world-readable #260993
193 [ -e "${ROOT}etc/${x}" ] && chmod o-rwx "${ROOT}etc/${x}"
196 # Take care of the etc-update for the user
197 if [ -e "${ROOT}"/etc/._cfg0000_gentoo-release ] ; then
198 mv "${ROOT}"/etc/._cfg0000_gentoo-release "${ROOT}"/etc/gentoo-release
201 # whine about users that lack passwords #193541
202 if [[ -e ${ROOT}/etc/shadow ]] ; then
203 local bad_users=$(sed -n '/^[^:]*::/s|^\([^:]*\)::.*|\1|p' "${ROOT}"/etc/shadow)
204 if [[ -n ${bad_users} ]] ; then
206 ewarn "The following users lack passwords!"
211 # baselayout leaves behind a lot of .keep files, so let's clean them up
212 find "${ROOT}"/lib*/rcscripts/ -name .keep -exec rm -f {} + 2>/dev/null
213 find "${ROOT}"/lib*/rcscripts/ -depth -type d -exec rmdir {} + 2>/dev/null
215 # whine about users with invalid shells #215698
216 if [[ -e ${ROOT}/etc/passwd ]] ; then
217 local bad_shells=$(awk -F: 'system("test -e " $7) { print $1 " - " $7}' /etc/passwd | sort)
218 if [[ -n ${bad_shells} ]] ; then
220 ewarn "The following users have non-existent shells!"
221 ewarn "${bad_shells}"
225 # http://bugs.gentoo.org/361349
226 if use kernel_linux; then
227 mkdir -p "${ROOT}"/run
229 if ! grep -qs "^tmpfs.*/run " "${ROOT}"/proc/mounts ; then
231 ewarn "You should reboot the system now to get /run mounted with tmpfs!"