sys-apps/openrc: remove old unstable versions
[gentoo.git] / sys-apps / systemd / systemd-239-r4.ebuild
1 # Copyright 2011-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 if [[ ${PV} == 9999 ]]; then
7         EGIT_REPO_URI="https://github.com/systemd/systemd.git"
8         inherit git-r3
9 else
10         SRC_URI="https://github.com/systemd/systemd/archive/v${PV}/${P}.tar.gz
11                 https://dev.gentoo.org/~floppym/dist/${P}-patches-2.tar.gz"
12         KEYWORDS="alpha amd64 arm arm64 ~hppa ia64 ~mips ppc ppc64 sparc x86"
13 fi
14
15 PYTHON_COMPAT=( python{3_5,3_6,3_7} )
16
17 inherit bash-completion-r1 linux-info meson multilib-minimal ninja-utils pam python-any-r1 systemd toolchain-funcs udev user
18
19 DESCRIPTION="System and service manager for Linux"
20 HOMEPAGE="https://www.freedesktop.org/wiki/Software/systemd"
21
22 LICENSE="GPL-2 LGPL-2.1 MIT public-domain"
23 SLOT="0/2"
24 IUSE="acl apparmor audit build cryptsetup curl elfutils +gcrypt gnuefi http idn importd +kmod libidn2 +lz4 lzma nat pam pcre policykit qrcode +resolvconf +seccomp selinux +split-usr ssl +sysv-utils test vanilla xkb"
25
26 REQUIRED_USE="importd? ( curl gcrypt lzma )"
27 RESTRICT="!test? ( test )"
28
29 MINKV="3.11"
30
31 COMMON_DEPEND=">=sys-apps/util-linux-2.30:0=[${MULTILIB_USEDEP}]
32         sys-libs/libcap:0=[${MULTILIB_USEDEP}]
33         !<sys-libs/glibc-2.16
34         acl? ( sys-apps/acl:0= )
35         apparmor? ( sys-libs/libapparmor:0= )
36         audit? ( >=sys-process/audit-2:0= )
37         cryptsetup? ( >=sys-fs/cryptsetup-1.6:0= )
38         curl? ( net-misc/curl:0= )
39         elfutils? ( >=dev-libs/elfutils-0.158:0= )
40         gcrypt? ( >=dev-libs/libgcrypt-1.4.5:0=[${MULTILIB_USEDEP}] )
41         http? (
42                 >=net-libs/libmicrohttpd-0.9.33:0=
43                 ssl? ( >=net-libs/gnutls-3.1.4:0= )
44         )
45         idn? (
46                 libidn2? ( net-dns/libidn2:= )
47                 !libidn2? ( net-dns/libidn:= )
48         )
49         importd? (
50                 app-arch/bzip2:0=
51                 sys-libs/zlib:0=
52         )
53         kmod? ( >=sys-apps/kmod-15:0= )
54         lz4? ( >=app-arch/lz4-0_p131:0=[${MULTILIB_USEDEP}] )
55         lzma? ( >=app-arch/xz-utils-5.0.5-r1:0=[${MULTILIB_USEDEP}] )
56         nat? ( net-firewall/iptables:0= )
57         pam? ( virtual/pam:=[${MULTILIB_USEDEP}] )
58         pcre? ( dev-libs/libpcre2 )
59         qrcode? ( media-gfx/qrencode:0= )
60         seccomp? ( >=sys-libs/libseccomp-2.3.3:0= )
61         selinux? ( sys-libs/libselinux:0= )
62         xkb? ( >=x11-libs/libxkbcommon-0.4.1:0= )"
63
64 # baselayout-2.2 has /run
65 RDEPEND="${COMMON_DEPEND}
66         >=sys-apps/baselayout-2.2
67         selinux? ( sec-policy/selinux-base-policy[systemd] )
68         sysv-utils? ( !sys-apps/sysvinit )
69         !sysv-utils? ( sys-apps/sysvinit )
70         resolvconf? ( !net-dns/openresolv )
71         !build? ( || (
72                 sys-apps/util-linux[kill(-)]
73                 sys-process/procps[kill(+)]
74                 sys-apps/coreutils[kill(-)]
75         ) )
76         !sys-auth/nss-myhostname
77         !<sys-kernel/dracut-044
78         !sys-fs/eudev
79         !sys-fs/udev"
80
81 # sys-apps/dbus: the daemon only (+ build-time lib dep for tests)
82 PDEPEND=">=sys-apps/dbus-1.9.8[systemd]
83         >=sys-apps/hwids-20150417[udev]
84         >=sys-fs/udev-init-scripts-25
85         policykit? ( sys-auth/polkit )
86         !vanilla? ( sys-apps/gentoo-systemd-integration )"
87
88 # Newer linux-headers needed by ia64, bug #480218
89 DEPEND="${COMMON_DEPEND}
90         app-arch/xz-utils:0
91         dev-util/gperf
92         >=dev-util/intltool-0.50
93         >=sys-apps/coreutils-8.16
94         >=sys-kernel/linux-headers-${MINKV}
95         virtual/pkgconfig[${MULTILIB_USEDEP}]
96         gnuefi? ( >=sys-boot/gnu-efi-3.0.2 )
97         test? ( sys-apps/dbus )
98         app-text/docbook-xml-dtd:4.2
99         app-text/docbook-xml-dtd:4.5
100         app-text/docbook-xsl-stylesheets
101         dev-libs/libxslt:0
102         $(python_gen_any_dep 'dev-python/lxml[${PYTHON_USEDEP}]')
103 "
104
105 pkg_pretend() {
106         if [[ ${MERGE_TYPE} != buildonly ]]; then
107                 local CONFIG_CHECK="~AUTOFS4_FS ~BLK_DEV_BSG ~CGROUPS
108                         ~CHECKPOINT_RESTORE ~DEVTMPFS ~EPOLL ~FANOTIFY ~FHANDLE
109                         ~INOTIFY_USER ~IPV6 ~NET ~NET_NS ~PROC_FS ~SIGNALFD ~SYSFS
110                         ~TIMERFD ~TMPFS_XATTR ~UNIX
111                         ~CRYPTO_HMAC ~CRYPTO_SHA256 ~CRYPTO_USER_API_HASH
112                         ~!FW_LOADER_USER_HELPER_FALLBACK ~!GRKERNSEC_PROC ~!IDE ~!SYSFS_DEPRECATED
113                         ~!SYSFS_DEPRECATED_V2"
114
115                 use acl && CONFIG_CHECK+=" ~TMPFS_POSIX_ACL"
116                 use seccomp && CONFIG_CHECK+=" ~SECCOMP ~SECCOMP_FILTER"
117                 kernel_is -lt 3 7 && CONFIG_CHECK+=" ~HOTPLUG"
118                 kernel_is -lt 4 7 && CONFIG_CHECK+=" ~DEVPTS_MULTIPLE_INSTANCES"
119                 kernel_is -ge 4 10 && CONFIG_CHECK+=" ~CGROUP_BPF"
120
121                 if linux_config_exists; then
122                         local uevent_helper_path=$(linux_chkconfig_string UEVENT_HELPER_PATH)
123                         if [[ -n ${uevent_helper_path} ]] && [[ ${uevent_helper_path} != '""' ]]; then
124                                 ewarn "It's recommended to set an empty value to the following kernel config option:"
125                                 ewarn "CONFIG_UEVENT_HELPER_PATH=${uevent_helper_path}"
126                         fi
127                         if linux_chkconfig_present X86; then
128                                 CONFIG_CHECK+=" ~DMIID"
129                         fi
130                 fi
131
132                 if kernel_is -lt ${MINKV//./ }; then
133                         ewarn "Kernel version at least ${MINKV} required"
134                 fi
135
136                 check_extra_config
137         fi
138 }
139
140 pkg_setup() {
141         :
142 }
143
144 src_unpack() {
145         default
146         [[ ${PV} != 9999 ]] || git-r3_src_unpack
147 }
148
149 src_prepare() {
150         # Do NOT add patches here
151         local PATCHES=()
152
153         [[ -d "${WORKDIR}"/patches ]] && PATCHES+=( "${WORKDIR}"/patches )
154
155         # Add local patches here
156         PATCHES+=(
157                 "${FILESDIR}"/239-debug-extra.patch
158                 "${FILESDIR}"/CVE-2019-6454.patch
159         )
160
161         if ! use vanilla; then
162                 PATCHES+=(
163                         "${FILESDIR}/gentoo-Dont-enable-audit-by-default.patch"
164                         "${FILESDIR}/gentoo-systemd-user-pam.patch"
165                         "${FILESDIR}/gentoo-uucp-group-r1.patch"
166                         "${FILESDIR}/gentoo-generator-path.patch"
167                 )
168         fi
169
170         default
171 }
172
173 src_configure() {
174         # Prevent conflicts with i686 cross toolchain, bug 559726
175         tc-export AR CC NM OBJCOPY RANLIB
176
177         python_setup
178
179         multilib-minimal_src_configure
180 }
181
182 meson_use() {
183         usex "$1" true false
184 }
185
186 meson_multilib() {
187         if multilib_is_native_abi; then
188                 echo true
189         else
190                 echo false
191         fi
192 }
193
194 meson_multilib_native_use() {
195         if multilib_is_native_abi && use "$1"; then
196                 echo true
197         else
198                 echo false
199         fi
200 }
201
202 multilib_src_configure() {
203         local myconf=(
204                 --localstatedir="${EPREFIX}/var"
205                 -Dpamlibdir="$(getpam_mod_dir)"
206                 # avoid bash-completion dep
207                 -Dbashcompletiondir="$(get_bashcompdir)"
208                 # make sure we get /bin:/sbin in PATH
209                 -Dsplit-usr=$(usex split-usr true false)
210                 -Drootprefix="$(usex split-usr "${EPREFIX:-/}" "${EPREFIX}/usr")"
211                 -Dsysvinit-path=
212                 -Dsysvrcnd-path=
213                 # Avoid infinite exec recursion, bug 642724
214                 -Dtelinit-path="${EPREFIX}/lib/sysvinit/telinit"
215                 # no deps
216                 -Defi=$(meson_multilib)
217                 -Dima=true
218                 # Optional components/dependencies
219                 -Dacl=$(meson_multilib_native_use acl)
220                 -Dapparmor=$(meson_multilib_native_use apparmor)
221                 -Daudit=$(meson_multilib_native_use audit)
222                 -Dlibcryptsetup=$(meson_multilib_native_use cryptsetup)
223                 -Dlibcurl=$(meson_multilib_native_use curl)
224                 -Delfutils=$(meson_multilib_native_use elfutils)
225                 -Dgcrypt=$(meson_use gcrypt)
226                 -Dgnu-efi=$(meson_multilib_native_use gnuefi)
227                 -Defi-libdir="${EPREFIX}/usr/$(get_libdir)"
228                 -Dmicrohttpd=$(meson_multilib_native_use http)
229                 $(usex http -Dgnutls=$(meson_multilib_native_use ssl) -Dgnutls=false)
230                 -Dimportd=$(meson_multilib_native_use importd)
231                 -Dbzip2=$(meson_multilib_native_use importd)
232                 -Dzlib=$(meson_multilib_native_use importd)
233                 -Dkmod=$(meson_multilib_native_use kmod)
234                 -Dlz4=$(meson_use lz4)
235                 -Dxz=$(meson_use lzma)
236                 -Dlibiptc=$(meson_multilib_native_use nat)
237                 -Dpam=$(meson_use pam)
238                 -Dpcre2=$(meson_multilib_native_use pcre)
239                 -Dpolkit=$(meson_multilib_native_use policykit)
240                 -Dqrencode=$(meson_multilib_native_use qrcode)
241                 -Dseccomp=$(meson_multilib_native_use seccomp)
242                 -Dselinux=$(meson_multilib_native_use selinux)
243                 #-Dtests=$(meson_multilib_native_use test)
244                 -Ddbus=$(meson_multilib_native_use test)
245                 -Dxkbcommon=$(meson_multilib_native_use xkb)
246                 # hardcode a few paths to spare some deps
247                 -Dkill-path=/bin/kill
248                 -Dntp-servers="0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org 2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"
249                 # Breaks screen, tmux, etc.
250                 -Ddefault-kill-user-processes=false
251
252                 # multilib options
253                 -Dbacklight=$(meson_multilib)
254                 -Dbinfmt=$(meson_multilib)
255                 -Dcoredump=$(meson_multilib)
256                 -Denvironment-d=$(meson_multilib)
257                 -Dfirstboot=$(meson_multilib)
258                 -Dhibernate=$(meson_multilib)
259                 -Dhostnamed=$(meson_multilib)
260                 -Dhwdb=$(meson_multilib)
261                 -Dldconfig=$(meson_multilib)
262                 -Dlocaled=$(meson_multilib)
263                 -Dman=$(meson_multilib)
264                 -Dnetworkd=$(meson_multilib)
265                 -Dquotacheck=$(meson_multilib)
266                 -Drandomseed=$(meson_multilib)
267                 -Drfkill=$(meson_multilib)
268                 -Dsysusers=$(meson_multilib)
269                 -Dtimedated=$(meson_multilib)
270                 -Dtimesyncd=$(meson_multilib)
271                 -Dtmpfiles=$(meson_multilib)
272                 -Dvconsole=$(meson_multilib)
273         )
274
275         if multilib_is_native_abi && use idn; then
276                 myconf+=(
277                         -Dlibidn2=$(usex libidn2 true false)
278                         -Dlibidn=$(usex libidn2 false true)
279                 )
280         else
281                 myconf+=(
282                         -Dlibidn2=false
283                         -Dlibidn=false
284                 )
285         fi
286
287         meson_src_configure "${myconf[@]}"
288 }
289
290 multilib_src_compile() {
291         eninja
292 }
293
294 multilib_src_test() {
295         unset DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR
296         eninja test
297 }
298
299 multilib_src_install() {
300         DESTDIR="${D}" eninja install
301 }
302
303 multilib_src_install_all() {
304         local rootprefix=$(usex split-usr '' /usr)
305
306         # meson doesn't know about docdir
307         mv "${ED%/}"/usr/share/doc/{systemd,${PF}} || die
308
309         einstalldocs
310         dodoc "${FILESDIR}"/nsswitch.conf
311
312         if ! use resolvconf; then
313                 rm -f "${ED%/}${rootprefix}"/sbin/resolvconf || die
314         fi
315
316         if ! use sysv-utils; then
317                 rm "${ED%/}${rootprefix}"/sbin/{halt,init,poweroff,reboot,runlevel,shutdown,telinit} || die
318                 rm "${ED%/}"/usr/share/man/man1/init.1 || die
319                 rm "${ED%/}"/usr/share/man/man8/{halt,poweroff,reboot,runlevel,shutdown,telinit}.8 || die
320         fi
321
322         if ! use resolvconf && ! use sysv-utils; then
323                 rmdir "${ED%/}${rootprefix}"/sbin || die
324         fi
325
326         # Preserve empty dirs in /etc & /var, bug #437008
327         keepdir /etc/{binfmt.d,modules-load.d,tmpfiles.d}
328         keepdir /etc/systemd/{ntp-units.d,user} /var/lib/systemd
329         keepdir /etc/udev/{hwdb.d,rules.d}
330         keepdir /var/log/journal/remote
331
332         # Symlink /etc/sysctl.conf for easy migration.
333         dosym ../sysctl.conf /etc/sysctl.d/99-sysctl.conf
334
335         # If we install these symlinks, there is no way for the sysadmin to remove them
336         # permanently.
337         rm -f "${ED%/}"/etc/systemd/system/multi-user.target.wants/systemd-networkd.service || die
338         rm -f "${ED%/}"/etc/systemd/system/dbus-org.freedesktop.network1.service || die
339         rm -f "${ED%/}"/etc/systemd/system/multi-user.target.wants/systemd-resolved.service || die
340         rm -f "${ED%/}"/etc/systemd/system/dbus-org.freedesktop.resolve1.service || die
341         rm -fr "${ED%/}"/etc/systemd/system/network-online.target.wants || die
342         rm -fr "${ED%/}"/etc/systemd/system/sockets.target.wants || die
343         rm -fr "${ED%/}"/etc/systemd/system/sysinit.target.wants || die
344
345         local udevdir=/lib/udev
346         use split-usr || udevdir=/usr/lib/udev
347
348         rm -r "${ED%/}${udevdir}/hwdb.d" || die
349
350         if use split-usr; then
351                 # Avoid breaking boot/reboot
352                 dosym ../../../lib/systemd/systemd /usr/lib/systemd/systemd
353                 dosym ../../../lib/systemd/systemd-shutdown /usr/lib/systemd/systemd-shutdown
354         fi
355 }
356
357 migrate_locale() {
358         local envd_locale_def="${EROOT%/}/etc/env.d/02locale"
359         local envd_locale=( "${EROOT%/}"/etc/env.d/??locale )
360         local locale_conf="${EROOT%/}/etc/locale.conf"
361
362         if [[ ! -L ${locale_conf} && ! -e ${locale_conf} ]]; then
363                 # If locale.conf does not exist...
364                 if [[ -e ${envd_locale} ]]; then
365                         # ...either copy env.d/??locale if there's one
366                         ebegin "Moving ${envd_locale} to ${locale_conf}"
367                         mv "${envd_locale}" "${locale_conf}"
368                         eend ${?} || FAIL=1
369                 else
370                         # ...or create a dummy default
371                         ebegin "Creating ${locale_conf}"
372                         cat > "${locale_conf}" <<-EOF
373                                 # This file has been created by the sys-apps/systemd ebuild.
374                                 # See locale.conf(5) and localectl(1).
375
376                                 # LANG=${LANG}
377                         EOF
378                         eend ${?} || FAIL=1
379                 fi
380         fi
381
382         if [[ ! -L ${envd_locale} ]]; then
383                 # now, if env.d/??locale is not a symlink (to locale.conf)...
384                 if [[ -e ${envd_locale} ]]; then
385                         # ...warn the user that he has duplicate locale settings
386                         ewarn
387                         ewarn "To ensure consistent behavior, you should replace ${envd_locale}"
388                         ewarn "with a symlink to ${locale_conf}. Please migrate your settings"
389                         ewarn "and create the symlink with the following command:"
390                         ewarn "ln -s -n -f ../locale.conf ${envd_locale}"
391                         ewarn
392                 else
393                         # ...or just create the symlink if there's nothing here
394                         ebegin "Creating ${envd_locale_def} -> ../locale.conf symlink"
395                         ln -n -s ../locale.conf "${envd_locale_def}"
396                         eend ${?} || FAIL=1
397                 fi
398         fi
399 }
400
401 pkg_postinst() {
402         newusergroup() {
403                 enewgroup "$1"
404                 enewuser "$1" -1 -1 -1 "$1"
405         }
406
407         enewgroup input
408         enewgroup kvm 78
409         enewgroup render
410         enewgroup systemd-journal
411         newusergroup systemd-bus-proxy
412         newusergroup systemd-coredump
413         newusergroup systemd-journal-gateway
414         newusergroup systemd-journal-remote
415         newusergroup systemd-journal-upload
416         newusergroup systemd-network
417         newusergroup systemd-resolve
418         newusergroup systemd-timesync
419
420         systemd_update_catalog
421
422         # Keep this here in case the database format changes so it gets updated
423         # when required. Despite that this file is owned by sys-apps/hwids.
424         if has_version "sys-apps/hwids[udev]"; then
425                 udevadm hwdb --update --root="${EROOT%/}"
426         fi
427
428         udev_reload || FAIL=1
429
430         # Bug 465468, make sure locales are respect, and ensure consistency
431         # between OpenRC & systemd
432         migrate_locale
433
434         systemd_reenable systemd-networkd.service systemd-resolved.service
435
436         if [[ ${FAIL} ]]; then
437                 eerror "One of the postinst commands failed. Please check the postinst output"
438                 eerror "for errors. You may need to clean up your system and/or try installing"
439                 eerror "systemd again."
440                 eerror
441         fi
442 }
443
444 pkg_prerm() {
445         # If removing systemd completely, remove the catalog database.
446         if [[ ! ${REPLACED_BY_VERSION} ]]; then
447                 rm -f -v "${EROOT}"/var/lib/systemd/catalog/database
448         fi
449 }