1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 inherit eutils flag-o-matic multilib pam toolchain-funcs
9 DESCRIPTION="OpenRC manages the services, startup and shutdown of a host"
10 HOMEPAGE="https://www.gentoo.org/proj/en/base/openrc/"
12 if [[ ${PV} == "9999" ]]; then
13 EGIT_REPO_URI="git://github.com/OpenRC/${PN}.git"
16 SRC_URI="https://dev.gentoo.org/~williamh/dist/${P}.tar.bz2"
17 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
22 IUSE="audit debug elibc_glibc ncurses pam newnet prefix +netifrc selinux static-libs
23 tools unicode kernel_linux kernel_FreeBSD"
25 COMMON_DEPEND="kernel_FreeBSD? ( || ( >=sys-freebsd/freebsd-ubin-9.0_rc sys-process/fuser-bsd ) )
26 elibc_glibc? ( >=sys-libs/glibc-2.5 )
27 ncurses? ( sys-libs/ncurses:5= )
32 tools? ( dev-lang/perl )
33 audit? ( sys-process/audit )
36 !<sys-process/procps-3.3.9-r2
39 sys-apps/policycoreutils
42 !<sys-apps/baselayout-2.1-r1
43 !<sys-fs/udev-init-scripts-27"
44 DEPEND="${COMMON_DEPEND}
46 ncurses? ( virtual/pkgconfig )"
47 RDEPEND="${COMMON_DEPEND}
49 kernel_linux? ( || ( >=sys-apps/sysvinit-2.86-r6 sys-process/runit ) )
50 kernel_FreeBSD? ( sys-freebsd/freebsd-sbin )
53 sec-policy/selinux-base-policy
54 sec-policy/selinux-openrc
58 PDEPEND="netifrc? ( net-misc/netifrc )"
61 sed -i 's:0444:0644:' mk/sys.mk || die
63 if [[ ${PV} == "9999" ]] ; then
64 local ver="git-${EGIT_VERSION:0:6}"
65 sed -i "/^GITVER[[:space:]]*=/s:=.*:=${ver}:" mk/gitver.mk || die
68 # Allow user patches to be applied without modifying the ebuild
75 MAKE_ARGS="${MAKE_ARGS}
77 LIBEXECDIR=${EPREFIX}/$(get_libdir)/rc
79 MKSELINUX=$(usex selinux)
82 MKSTATICLIBS=$(usex static-libs)
83 MKTOOLS=$(usex tools)"
86 if use kernel_linux ; then
87 MAKE_ARGS="${MAKE_ARGS} OS=Linux"
89 elif use kernel_FreeBSD ; then
90 MAKE_ARGS="${MAKE_ARGS} OS=FreeBSD"
93 export BRANDING="Gentoo ${brand}"
94 use prefix && MAKE_ARGS="${MAKE_ARGS} MKPREFIX=yes PREFIX=${EPREFIX}"
95 export DEBUG=$(usev debug)
96 export MKTERMCAP=$(usev ncurses)
98 tc-export CC AR RANLIB
102 # set_config <file> <option name> <yes value> <no value> test
103 # a value of "#" will just comment out the option
105 local file="${ED}/$1" var=$2 val com
106 eval "${@:5}" && val=$3 || val=$4
107 [[ ${val} == "#" ]] && com="#" && val='\2'
108 sed -i -r -e "/^#?${var}=/{s:=([\"'])?([^ ]*)\1?:=\1${val}\1:;s:^#?:${com}:}" "${file}"
111 set_config_yes_no() {
112 set_config "$1" "$2" YES NO "${@:3}"
116 emake ${MAKE_ARGS} DESTDIR="${D}" install
118 # move the shared libs back to /usr so ldscript can install
119 # more of a minimal set of files
120 # disabled for now due to #270646
121 #mv "${ED}"/$(get_libdir)/lib{einfo,rc}* "${ED}"/usr/$(get_libdir)/ || die
122 #gen_usr_ldscript -a einfo rc
123 gen_usr_ldscript libeinfo.so
124 gen_usr_ldscript librc.so
126 if ! use kernel_linux; then
127 keepdir /$(get_libdir)/rc/init.d
129 keepdir /$(get_libdir)/rc/tmp
131 # Backup our default runlevels
132 dodir /usr/share/"${PN}"
133 cp -PR "${ED}"/etc/runlevels "${ED}"/usr/share/${PN} || die
134 rm -rf "${ED}"/etc/runlevels
136 # Setup unicode defaults for silly unicode users
137 set_config_yes_no /etc/rc.conf unicode use unicode
140 set_config_yes_no /etc/conf.d/keymaps windowkeys '(' use x86 '||' use amd64 ')'
142 # On HPPA, do not run consolefont by default (bug #222889)
144 rm -f "${ED}"/usr/share/openrc/runlevels/boot/consolefont
147 # Support for logfile rotation
148 insinto /etc/logrotate.d
149 newins "${FILESDIR}"/openrc.logrotate openrc
151 # install the gentoo pam.d file
152 newpamd "${FILESDIR}"/start-stop-daemon.pam start-stop-daemon
154 # install documentation
163 local runlevel=${2:-boot}
164 # if the initscript is not going to be installed and is not
165 # currently installed, return
166 [[ -e "${ED}"/etc/init.d/${initd} || -e "${EROOT}"etc/init.d/${initd} ]] \
168 [[ -e "${EROOT}"etc/runlevels/${runlevel}/${initd} ]] && return
170 # if runlevels dont exist just yet, then create it but still flag
171 # to pkg_postinst that it needs real setup #277323
172 if [[ ! -d "${EROOT}"etc/runlevels/${runlevel} ]] ; then
173 mkdir -p "${EROOT}"etc/runlevels/${runlevel}
174 touch "${EROOT}"etc/runlevels/.add_boot_init.created
177 elog "Auto-adding '${initd}' service to your ${runlevel} runlevel"
178 ln -snf /etc/init.d/${initd} "${EROOT}"etc/runlevels/${runlevel}/${initd}
180 add_boot_init_mit_config() {
181 local config=$1 initd=$2
182 if [[ -e ${EROOT}${config} ]] ; then
183 if [[ -n $(sed -e 's:#.*::' -e '/^[[:space:]]*$/d' "${EROOT}"${config}) ]] ; then
184 add_boot_init ${initd}
190 local f LIBDIR=$(get_libdir)
192 # avoid default thrashing in conf.d files when possible #295406
193 if [[ -e "${EROOT}"etc/conf.d/hostname ]] ; then
195 unset hostname HOSTNAME
196 source "${EROOT}"etc/conf.d/hostname
197 : ${hostname:=${HOSTNAME}}
198 [[ -n ${hostname} ]] && set_config /etc/conf.d/hostname hostname "${hostname}"
202 # set default interactive shell to sulogin if it exists
203 set_config /etc/rc.conf rc_shell /sbin/sulogin "#" test -e /sbin/sulogin
205 # termencoding was added in 0.2.1 and needed in boot
206 has_version ">=sys-apps/openrc-0.2.1" || add_boot_init termencoding
208 # swapfiles was added in 0.9.9 and needed in boot (february 2012)
209 has_version ">=sys-apps/openrc-0.9.9" || add_boot_init swapfiles
211 if ! has_version ">=sys-apps/openrc-0.11"; then
212 add_boot_init sysfs sysinit
215 if ! has_version ">=sys-apps/openrc-0.11.3" ; then
216 migrate_udev_mount_script
217 add_boot_init tmpfiles.setup boot
220 # these were added in 0.12.
221 if ! has_version ">=sys-apps/openrc-0.12"; then
222 add_boot_init loopback
223 add_boot_init tmpfiles.dev sysinit
225 # ensure existing /etc/conf.d/net is not removed
226 # undoes the hack to get around CONFIG_PROTECT in openrc-0.11.8 and earlier
227 # this needs to stay in openrc ebuilds for a long time. :(
229 if [[ -f "${EROOT}"etc/conf.d/net ]]; then
230 einfo "Modifying conf.d/net to keep it from being removed"
231 cat <<-EOF >>"${EROOT}"etc/conf.d/net
233 # The network scripts are now part of net-misc/netifrc
234 # In order to avoid sys-apps/${P} from removing this file, this comment was
235 # added; you can safely remove this comment. Please see
236 # /usr/share/doc/netifrc*/README* for more information.
240 has_version ">=sys-apps/openrc-0.14" || add_boot_init binfmt
243 # >=OpenRC-0.11.3 requires udev-mount to be in the sysinit runlevel with udev.
244 migrate_udev_mount_script() {
245 if [ -e "${EROOT}"etc/runlevels/sysinit/udev -a \
246 ! -e "${EROOT}"etc/runlevels/sysinit/udev-mount ]; then
247 add_boot_init udev-mount sysinit
253 local LIBDIR=$(get_libdir)
255 # Make our runlevels if they don't exist
256 if [[ ! -e "${EROOT}"etc/runlevels ]] || [[ -e "${EROOT}"etc/runlevels/.add_boot_init.created ]] ; then
257 einfo "Copying across default runlevels"
258 cp -RPp "${EROOT}"usr/share/${PN}/runlevels "${EROOT}"etc
259 rm -f "${EROOT}"etc/runlevels/.add_boot_init.created
261 if [[ ! -e "${EROOT}"etc/runlevels/sysinit/devfs ]] ; then
262 mkdir -p "${EROOT}"etc/runlevels/sysinit
263 cp -RPp "${EROOT}"usr/share/${PN}/runlevels/sysinit/* \
264 "${EROOT}"etc/runlevels/sysinit
266 if [[ ! -e "${EROOT}"etc/runlevels/shutdown/mount-ro ]] ; then
267 mkdir -p "${EROOT}"etc/runlevels/shutdown
268 cp -RPp "${EROOT}"usr/share/${PN}/runlevels/shutdown/* \
269 "${EROOT}"etc/runlevels/shutdown
274 elog "Setting the console font does not work on all HPPA consoles."
275 elog "You can still enable it by running:"
276 elog "# rc-update add consolefont boot"
279 # Handle the conf.d/local.{start,stop} -> local.d transition
280 if path_exists -o "${EROOT}"etc/conf.d/local.{start,stop} ; then
281 elog "Moving your ${EROOT}etc/conf.d/local.{start,stop}"
282 elog "files to ${EROOT}etc/local.d"
283 mv "${EROOT}"etc/conf.d/local.start "${EROOT}"etc/local.d/baselayout1.start
284 mv "${EROOT}"etc/conf.d/local.stop "${EROOT}"etc/local.d/baselayout1.stop
285 chmod +x "${EROOT}"etc/local.d/*{start,stop}
288 if use kernel_linux && [[ "${EROOT}" = "/" ]]; then
289 if ! /$(get_libdir)/rc/sh/migrate-to-run.sh; then
290 ewarn "The dependency data could not be migrated to /run/openrc."
291 ewarn "This means you need to reboot your system."
295 # update the dependency tree after touching all files #224171
296 [[ "${EROOT}" = "/" ]] && "${EROOT}/${LIBDIR}"/rc/bin/rc-depend -u
298 if ! use newnet && ! use netifrc; then
299 ewarn "You have emerged OpenRc without network support. This"
300 ewarn "means you need to SET UP a network manager such as"
301 ewarn " net-misc/netifrc, net-misc/dhcpcd, net-misc/wicd,"
302 ewarn "net-misc/NetworkManager, or net-misc/badvpn."
303 ewarn "Or, you have the option of emerging openrc with the newnet"
304 ewarn "use flag and configuring /etc/conf.d/network and"
305 ewarn "/etc/conf.d/staticroute if you only use static interfaces."
309 if use newnet && [ ! -e "${EROOT}"etc/runlevels/boot/network ]; then
310 ewarn "Please add the network service to your boot runlevel"
311 ewarn "as soon as possible. Not doing so could leave you with a system"
312 ewarn "without networking."
316 ewarn "In this version of OpenRC, the loopback interface no longer"
317 ewarn "satisfies the net virtual."
318 ewarn "If you have services now which do not start because of this,"
319 ewarn "They can be fixed by adding rc_need=\"!net\""
320 ewarn "to the ${EROOT}etc/conf.d/<servicename> file."
321 ewarn "You should also file a bug against the service asking that"
322 ewarn "need net be dropped from the dependencies."
323 ewarn "The bug you file should block the following tracker:"
324 ewarn "https://bugs.gentoo.org/show_bug.cgi?id=439092"
327 # Updated for 0.13.2.
328 ewarn "Bug https://bugs.gentoo.org/show_bug.cgi?id=427996 was not"
329 ewarn "fixed correctly in earlier versions of OpenRC."
330 ewarn "The correct fix is implemented in this version, but that"
331 ewarn "means netmount needs to be added to the default runlevel if"
332 ewarn "you are using nfs file systems."
335 elog "You should now update all files in /etc, using etc-update"
336 elog "or equivalent before restarting any services or this host."