Use https by default
[gentoo.git] / sys-apps / baselayout / baselayout-2.2.ebuild
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 inherit eutils multilib
6
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"
11
12 LICENSE="GPL-2"
13 SLOT="0"
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"
16
17 pkg_setup() {
18         multilib_layout
19 }
20
21 # Create our multilib dirs - the Makefile has no knowledge of this
22 multilib_warn() {
23         local syms=$1 dirs=$2 def_libdir=$3
24
25         [ -z "${syms}${dirs}" ] && return
26
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}:"
30                 ewarn "$1"
31         fi
32 }
33 multilib_layout() {
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...
36
37         [ -z "${def_libdir}" ] && die "your DEFAULT_ABI=$DEFAULT_ABI appears to be invalid"
38
39         # figure out which paths should be symlinks and which should be directories
40         local dirs syms exp d
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}"
47                         else
48                                 [ -h "${d}" ] && syms+=" ${d}"
49                         fi
50                 done
51         done
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."
59                 echo
60         fi
61
62         # setup symlinks and dirs where we expect them to be; do not migrate
63         # data ... just fall over in that case.
64         local prefix
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 ...
70                                 continue
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
77                                 else
78                                         die "non-empty dir found where we needed a symlink: ${prefix}lib"
79                                 fi
80                         else
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
87                         fi
88                 else
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
97                                 else
98                                         mkdir -p "${prefix}lib" || die
99                                 fi
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
103                                 # to "lib32" ...
104                                 case ${CHOST} in
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"
112                                                 fi
113                                         fi
114                                         ;;
115                                 esac
116                         else
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
122                         fi
123                 fi
124         done
125 }
126
127 pkg_preinst() {
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
134
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
139
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.
143         multilib_layout
144         if use build ; then
145                 emake -C "${D}/usr/share/${PN}" DESTDIR="${ROOT}" layout || die
146         fi
147         rm -f "${D}"/usr/share/${PN}/Makefile
148 }
149
150 src_install() {
151         emake \
152                 OS=$(usex kernel_FreeBSD BSD Linux) \
153                 DESTDIR="${D}" \
154                 install || die
155         dodoc ChangeLog.svn
156
157         # need the makefile in pkg_preinst
158         insinto /usr/share/${PN}
159         doins Makefile || die
160
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.
167         local libdir ldpaths
168         for libdir in $(get_all_libdirs) ; do
169                 ldpaths+=":/${libdir}:/usr/${libdir}:/usr/local/${libdir}"
170         done
171         echo "LDPATH='${ldpaths#:}'" >> "${D}"/etc/env.d/00basic
172
173         # rc-scripts version for testing of features that *should* be present
174         echo "Gentoo Base System release ${PV}" > "${D}"/etc/gentoo-release
175 }
176
177 pkg_postinst() {
178         local x
179
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
189         done
190
191         # Force shadow permissions to not be world-readable #260993
192         for x in shadow ; do
193                 [ -e "${ROOT}etc/${x}" ] && chmod o-rwx "${ROOT}etc/${x}"
194         done
195
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
199         fi
200
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
205                         echo
206                         ewarn "The following users lack passwords!"
207                         ewarn ${bad_users}
208                 fi
209         fi
210
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
214
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
219                         echo
220                         ewarn "The following users have non-existent shells!"
221                         ewarn "${bad_shells}"
222                 fi
223         fi
224
225         # http://bugs.gentoo.org/361349
226         if use kernel_linux; then
227                 mkdir -p "${ROOT}"/run
228
229                 if ! grep -qs "^tmpfs.*/run " "${ROOT}"/proc/mounts ; then
230                         echo
231                         ewarn "You should reboot the system now to get /run mounted with tmpfs!"
232                 fi
233         fi
234 }