dev-lua/luarocks: version bump to 3.2.1
[gentoo.git] / sys-process / runit / runit-2.1.2-r1.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit toolchain-funcs flag-o-matic
7
8 DESCRIPTION="A UNIX init scheme with service supervision"
9 HOMEPAGE="http://smarden.org/runit/"
10 SRC_URI="http://smarden.org/runit/${P}.tar.gz"
11
12 LICENSE="BSD"
13 SLOT="0"
14 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
15 IUSE="static"
16
17 RDEPEND="sys-apps/openrc"
18
19 S=${WORKDIR}/admin/${P}/src
20
21 src_prepare() {
22         default
23
24         # we either build everything or nothing static
25         sed -i -e 's:-static: :' Makefile
26
27         # see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=726008
28         [[ ${COMPILER} == "diet" ]] &&
29                 use ppc &&
30                 filter-flags "-mpowerpc-gpopt"
31 }
32
33 src_configure() {
34         use static && append-ldflags -static
35
36         echo "$(tc-getCC) ${CFLAGS}"  > conf-cc
37         echo "$(tc-getCC) ${LDFLAGS}" > conf-ld
38 }
39
40 src_install() {
41         into /
42         dobin $(<../package/commands)
43         dodir /sbin
44         mv "${ED}"/bin/{runit-init,runit,utmpset} "${ED}"/sbin/ || die "dosbin"
45         dosym ../etc/runit/2 /sbin/runsvdir-start
46
47         DOCS=( ../package/{CHANGES,README,THANKS,TODO} )
48         HTML_DOCS=( ../doc/*.html )
49         einstalldocs
50         doman ../man/*.[18]
51
52 dodir /etc/runit
53         exeinto /etc/runit
54         doexe "${FILESDIR}"/ctrlaltdel
55         newexe "${FILESDIR}"/1-${PV} 1
56         newexe "${FILESDIR}"/2-${PV} 2
57         newexe "${FILESDIR}"/3-${PV} 3
58
59         dodir /etc/sv
60         for tty in tty1 tty2 tty3 tty4 tty5 tty6; do
61                 exeinto /etc/sv/getty-$tty/
62                 newexe "${FILESDIR}"/finish.getty finish
63                 newexe "${FILESDIR}"/run.getty-${PV} run
64                 for script in finish run; do
65                         sed -i -e "s:TTY:${tty}:g" "${ED}"/etc/sv/getty-$tty/$script
66                 done
67         done
68
69         # make sv command work
70         cat <<-EOF > "${T}"/env.d
71                 #/etc/env.d/20runit
72                 SVDIR="/etc/service/"
73         EOF
74         insinto /etc/env.d
75         newins "${T}"/env.d 20runit
76 }
77
78 pkg_preinst() {
79         if has_version 'sys-process/runit' &&
80                 has_version '<sys-process/runit-2.1.2' &&
81                 [ -d "${EROOT}"etc/runit/runsvdir/all ]; then
82                 if [ -e "${EROOT}"etc/sv ]; then
83                         mv -f "${EROOT}"etc/sv "${EROOT}"etc/sv.bak || die
84                         ewarn "${EROOT}etc/sv was moved to ${EROOT}etc/sv.bak"
85                 fi
86                 mv "${EROOT}"etc/runit/runsvdir/all "${EROOT}"etc/sv|| die
87                 ln -sf "${EROOT}"etc/sv "${EROOT}"etc/runit/runsvdir/all || die
88                 cp -a "${EROOT}"etc/runit/runsvdir "${T}" || die
89                 touch "${T}"/make_var_service || die
90         fi
91 }
92
93 default_config() {
94         local sv="${EROOT}"etc/sv
95         local service="${EROOT}"etc/service
96         mkdir -p "${service}" || die
97         for x in tty1 tty2 tty3 tty4 tty5 tty6; do
98         ln -sf "${sv}"/getty-$x "${service}"/getty-$x || die
99         done
100         einfo "The links to services runit will supervise are installed"
101         einfo "in $service."
102         einfo "If you need multiple runlevels, please see the documentation"
103         einfo "for how to set them up."
104         einfo
105 }
106
107 migrate_from_211() {
108         # Create /etc/service and /var/service if requested
109         if [ -e "${T}"/make_var_service ]; then
110                 ln -sf "${EROOT}"etc/runit/runsvdir/current "${EROOT}"etc/service || die
111                 ln -sf "${EROOT}"etc/runit/runsvdir/current "${EROOT}"var/service || die
112         fi
113         if [ -d "${T}"/runsvdir ]; then
114                 cp -a "${T}"/runsvdir "${EROOT}"etc/runit || die
115         fi
116         return 0
117 }
118
119 pkg_preinst() {
120         if  has_version '<sys-process/runit-2.1.2'; then
121                 pre_212=yes
122         fi
123 }
124
125 pkg_postinst() {
126         if [[ -z $REPLACING_VERSIONS ]]; then
127                 default_config
128         elif [[ -n $pre_212 ]]; then
129                 migrate_from_211
130         fi
131
132         ewarn "To make sure sv works correctly in your currently open"
133         ewarn "shells, please run the following command:"
134         ewarn
135         ewarn "source /etc/profile"
136         ewarn
137
138         if [ -L "${EROOT}"var/service ]; then
139                 ewarn "Once this version of runit is active, please remove the"
140                 ewarn "compatibility symbolic link at ${EROOT}var/service"
141                 ewarn "The correct path now is ${EROOT}etc/service"
142                 ewarn
143         fi
144
145         if [ -L "${EROOT}"etc/runit/runsvdir/all ]; then
146                 ewarn "${EROOT}etc/runit/runsvdir/all has moved to"
147                 iewarn "${EROOT}etc/sv."
148                 ewarn "Any symbolic links under ${EROOT}etc/runit/runsvdir"
149                 ewarn "which point to services through ../all should be updated to"
150                 ewarn "point to them through ${EROOT}etc/sv."
151                 ewarn "Once that is done, ${EROOT}etc/runit/runsvdir/all should be"
152                 ewarn "removed."
153                 ewarn
154         fi
155 }