Use https by default
[gentoo.git] / sys-apps / openrc / openrc-0.16.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit eutils flag-o-matic multilib pam toolchain-funcs
8
9 DESCRIPTION="OpenRC manages the services, startup and shutdown of a host"
10 HOMEPAGE="https://www.gentoo.org/proj/en/base/openrc/"
11
12 if [[ ${PV} == "9999" ]]; then
13         EGIT_REPO_URI="git://github.com/OpenRC/${PN}.git"
14         inherit git-r3
15 else
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"
18 fi
19
20 LICENSE="BSD-2"
21 SLOT="0"
22 IUSE="audit debug elibc_glibc ncurses pam newnet prefix +netifrc selinux static-libs
23         tools unicode kernel_linux kernel_FreeBSD"
24
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= )
28         pam? (
29                 sys-auth/pambase
30                 virtual/pam
31         )
32         tools? ( dev-lang/perl )
33         audit? ( sys-process/audit )
34         kernel_linux? (
35                 sys-process/psmisc
36                 !<sys-process/procps-3.3.9-r2
37         )
38         selinux? (
39                 sys-apps/policycoreutils
40                 sys-libs/libselinux
41         )
42         !<sys-apps/baselayout-2.1-r1
43         !<sys-fs/udev-init-scripts-27"
44 DEPEND="${COMMON_DEPEND}
45         virtual/os-headers
46         ncurses? ( virtual/pkgconfig )"
47 RDEPEND="${COMMON_DEPEND}
48         !prefix? (
49                 kernel_linux? ( || ( >=sys-apps/sysvinit-2.86-r6 sys-process/runit ) )
50                 kernel_FreeBSD? ( sys-freebsd/freebsd-sbin )
51         )
52         selinux? (
53                 sec-policy/selinux-base-policy
54                 sec-policy/selinux-openrc
55         )
56 "
57
58 PDEPEND="netifrc? ( net-misc/netifrc )"
59
60 src_prepare() {
61         sed -i 's:0444:0644:' mk/sys.mk || die
62
63         if [[ ${PV} == "9999" ]] ; then
64                 local ver="git-${EGIT_VERSION:0:6}"
65                 sed -i "/^GITVER[[:space:]]*=/s:=.*:=${ver}:" mk/gitver.mk || die
66         fi
67
68         # Allow user patches to be applied without modifying the ebuild
69         epatch_user
70 }
71
72 src_compile() {
73         unset LIBDIR #266688
74
75         MAKE_ARGS="${MAKE_ARGS}
76                 LIBNAME=$(get_libdir)
77                 LIBEXECDIR=${EPREFIX}/$(get_libdir)/rc
78                 MKNET=$(usex newnet)
79                 MKSELINUX=$(usex selinux)
80                 MKAUDIT=$(usex audit)
81                 MKPAM=$(usev pam)
82                 MKSTATICLIBS=$(usex static-libs)
83                 MKTOOLS=$(usex tools)"
84
85         local brand="Unknown"
86         if use kernel_linux ; then
87                 MAKE_ARGS="${MAKE_ARGS} OS=Linux"
88                 brand="Linux"
89         elif use kernel_FreeBSD ; then
90                 MAKE_ARGS="${MAKE_ARGS} OS=FreeBSD"
91                 brand="FreeBSD"
92         fi
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)
97
98         tc-export CC AR RANLIB
99         emake ${MAKE_ARGS}
100 }
101
102 # set_config <file> <option name> <yes value> <no value> test
103 # a value of "#" will just comment out the option
104 set_config() {
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}"
109 }
110
111 set_config_yes_no() {
112         set_config "$1" "$2" YES NO "${@:3}"
113 }
114
115 src_install() {
116         emake ${MAKE_ARGS} DESTDIR="${D}" install
117
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
125
126         if ! use kernel_linux; then
127                 keepdir /$(get_libdir)/rc/init.d
128         fi
129         keepdir /$(get_libdir)/rc/tmp
130
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
135
136         # Setup unicode defaults for silly unicode users
137         set_config_yes_no /etc/rc.conf unicode use unicode
138
139         # Cater to the norm
140         set_config_yes_no /etc/conf.d/keymaps windowkeys '(' use x86 '||' use amd64 ')'
141
142         # On HPPA, do not run consolefont by default (bug #222889)
143         if use hppa; then
144                 rm -f "${ED}"/usr/share/openrc/runlevels/boot/consolefont
145         fi
146
147         # Support for logfile rotation
148         insinto /etc/logrotate.d
149         newins "${FILESDIR}"/openrc.logrotate openrc
150
151         # install the gentoo pam.d file
152         newpamd "${FILESDIR}"/start-stop-daemon.pam start-stop-daemon
153
154         # install documentation
155         dodoc ChangeLog *.md
156         if use newnet; then
157                 dodoc README.newnet
158         fi
159 }
160
161 add_boot_init() {
162         local initd=$1
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} ]] \
167                 || return
168         [[ -e "${EROOT}"etc/runlevels/${runlevel}/${initd} ]] && return
169
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
175         fi
176
177         elog "Auto-adding '${initd}' service to your ${runlevel} runlevel"
178         ln -snf /etc/init.d/${initd} "${EROOT}"etc/runlevels/${runlevel}/${initd}
179 }
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}
185                 fi
186         fi
187 }
188
189 pkg_preinst() {
190         local f LIBDIR=$(get_libdir)
191
192         # avoid default thrashing in conf.d files when possible #295406
193         if [[ -e "${EROOT}"etc/conf.d/hostname ]] ; then
194                 (
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}"
199                 )
200         fi
201
202         # set default interactive shell to sulogin if it exists
203         set_config /etc/rc.conf rc_shell /sbin/sulogin "#" test -e /sbin/sulogin
204
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
207
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
210
211         if ! has_version ">=sys-apps/openrc-0.11"; then
212                 add_boot_init sysfs sysinit
213         fi
214
215         if ! has_version ">=sys-apps/openrc-0.11.3" ; then
216                 migrate_udev_mount_script
217                 add_boot_init tmpfiles.setup boot
218         fi
219
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
224
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. :(
228                 # Added in 0.12.
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
232
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.
237 EOF
238                 fi
239         fi
240         has_version ">=sys-apps/openrc-0.14" || add_boot_init binfmt
241 }
242
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
248         fi
249         return 0
250 }
251
252 pkg_postinst() {
253         local LIBDIR=$(get_libdir)
254
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
260         else
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
265                 fi
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
270                 fi
271         fi
272
273         if use hppa; then
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"
277         fi
278
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}
286         fi
287
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."
292                 fi
293         fi
294
295         # update the dependency tree after touching all files #224171
296         [[ "${EROOT}" = "/" ]] && "${EROOT}/${LIBDIR}"/rc/bin/rc-depend -u
297
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."
306                 ewarn
307         fi
308
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."
313                 ewarn
314         fi
315
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"
325         ewarn
326
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."
333         ewarn
334
335         elog "You should now update all files in /etc, using etc-update"
336         elog "or equivalent before restarting any services or this host."
337 }