sys-apps/irqbalance: arm64 keyworded (bug #721536)
[gentoo.git] / sys-apps / baselayout-prefix / baselayout-prefix-2.6-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit multilib
7
8 # just use "upstream" sources
9 MY_P=${P/-prefix/}
10 MY_PN=${PN/-prefix/}
11 S="${WORKDIR}/${MY_P}"
12
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"
17         inherit git-r3
18 else
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"
21 fi
22
23 LICENSE="GPL-2"
24 SLOT="0"
25 IUSE="build kernel_FreeBSD kernel_linux +split-usr"
26
27 my_prefix_commits=(
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'
36 )
37 for my_c in ${my_prefix_commits[*]}
38 do
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[@]}" )
41 done
42 unset my_prefix_commits my_c
43
44 pkg_setup() {
45         multilib_layout
46 }
47
48 # Create our multilib dirs - the Makefile has no knowledge of this
49 multilib_layout() {
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...
56
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"
65                                         continue
66                                 fi
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"
71                                 else
72                                         einfo "creating directory ${dir}"
73                                         mkdir -p "${dir}" ||
74                                                 die "Unable to create ${dir} directory"
75                                 fi
76                         done
77                 done
78                 return 0
79         fi
80
81         [ -z "${def_libdir}" ] &&
82                 die "your DEFAULT_ABI=$DEFAULT_ABI appears to be invalid"
83
84         # figure out which paths should be symlinks and which should be directories
85         local dirs syms exp d
86         for libdir in ${libdirs} ; do
87                 if use split-usr ; then
88                         exp=( {,usr/,usr/local/}${libdir} )
89                 else
90                         exp=( {usr/,usr/local/}${libdir} )
91                 fi
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}"
96                         else
97                                 [ -h "${d}" ] && syms+=" ${d}"
98                         fi
99                 done
100         done
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."
108                 echo
109         fi
110
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/} )
115         else
116                 prefix_lst=( "${EROOT}"{usr/,usr/local/} )
117         fi
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 ...
123                                 continue
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
130                                 else
131                                         die "non-empty dir found where we needed a symlink: ${prefix}lib"
132                                 fi
133                         else
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
140                         fi
141                 else
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
150                                 else
151                                         mkdir -p "${prefix}lib" || die
152                                 fi
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
156                                 # to "lib32" ...
157                                 case ${CHOST} in
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"
165                                                 fi
166                                         fi
167                                         ;;
168                                 esac
169                         else
170                                 # nothing exists, so just set it up sanely
171                                 ewarn "Initializing ${prefix}lib as a dir"
172                                 mkdir -p "${prefix}lib" || die
173                         fi
174                 fi
175         done
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}"
180                         fi
181                 done
182         fi
183 }
184
185 pkg_preinst() {
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
190
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.
194         multilib_layout
195         if use build ; then
196                 if use split-usr ; then
197                         emake -C "${ED}/usr/share/${PN}" DESTDIR="${ROOT}" layout
198                 else
199                         emake -C "${ED}/usr/share/${PN}" DESTDIR="${ROOT}" layout-usrmerge
200                 fi
201         fi
202         rm -f "${ED}"/usr/share/${PN}/Makefile
203 }
204
205 src_prepare() {
206         default
207
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.
214         local libdir ldpaths
215         for libdir in $(get_all_libdirs) ; do
216                 ldpaths+=":${EPREFIX}/${libdir}:${EPREFIX}/usr/${libdir}"
217                 ldpaths+=":${EPREFIX}/usr/local/${libdir}"
218         done
219         echo "LDPATH='${ldpaths#:}'" >> etc/env.d/50baselayout
220 }
221
222 src_configure() {
223         local OS
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 \
228                          Linux ) ) )
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}|" \
233                 -i Makefile || die
234 }
235
236 src_install() {
237         emake ROOT="${ROOT}" DESTDIR="${D}" install
238         dodoc ChangeLog
239
240         # need the makefile in pkg_preinst
241         insinto /usr/share/${PN}
242         doins Makefile
243
244         use prefix-guest || return 0
245
246         # add a dummy to avoid Portage shebang errors
247         dodir sbin
248         cat > "${ED}"/sbin/runscript <<- EOF
249                 #!/usr/bin/env sh
250                 source "${EPREFIX}/lib/gentoo/functions.sh"
251
252                 eerror "runscript/openrc-run not supported by Gentoo Prefix Base System release ${PV}" 1>&2
253                 exit 1
254         EOF
255         chmod 755 "${ED}"/sbin/runscript || die
256         cp "${ED}"/sbin/{runscript,openrc-run} || die
257 }
258
259 pkg_postinst() {
260         local x
261
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
271         done
272
273         # Force shadow permissions to not be world-readable #260993
274         for x in shadow ; do
275                 [ -e "${EROOT}/etc/${x}" ] && chmod o-rwx "${EROOT}/etc/${x}"
276         done
277
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
281         fi
282
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
287                         echo
288                         ewarn "The following users lack passwords!"
289                         ewarn ${bad_users}
290                 fi
291         fi
292
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
297                         echo
298                         ewarn "The following users have non-existent shells!"
299                         ewarn "${bad_shells}"
300                 fi
301         fi
302
303         # https://bugs.gentoo.org/361349
304         if use kernel_linux; then
305                 mkdir -p "${EROOT}"/run
306
307                 local found fstype mountpoint
308                 while read -r _ mountpoint fstype _; do
309                 [[ ${mountpoint} = /run ]] && [[ ${fstype} = tmpfs ]] && found=1
310                 done < "${ROOT}"/proc/mounts
311                 [[ -z ${found} ]] &&
312                         ewarn "You should reboot now to get /run mounted with tmpfs!"
313         fi
314
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"
319                 fi
320
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."
324                 fi
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"
329                 fi
330         done
331
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."
335         fi
336 }