spacepaste

  1.  
  2. # Copyright 1999-2016 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. EAPI=5
  5. inherit eutils flag-o-matic multilib pam toolchain-funcs
  6. DESCRIPTION="OpenRC manages the services, startup and shutdown of a host"
  7. HOMEPAGE="https://www.gentoo.org/proj/en/base/openrc/"
  8. if [[ ${PV} == "9999" ]]; then
  9. EGIT_REPO_URI="git://github.com/OpenRC/${PN}.git"
  10. inherit git-r3
  11. else
  12. SRC_URI="https://dev.gentoo.org/~williamh/dist/${P}.tar.bz2"
  13. KEYWORDS="alpha amd64 arm ~arm64 hppa ia64 ~m68k ~mips ppc ppc64 ~s390 ~sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
  14. fi
  15. LICENSE="BSD-2"
  16. SLOT="0"
  17. IUSE="audit debug ncurses pam newnet prefix +netifrc selinux static-libs
  18. tools unicode kernel_linux kernel_FreeBSD"
  19. COMMON_DEPEND="kernel_FreeBSD? ( || ( >=sys-freebsd/freebsd-ubin-9.0_rc sys-process/fuser-bsd ) )
  20. ncurses? ( sys-libs/ncurses:0= )
  21. pam? (
  22. sys-auth/pambase
  23. virtual/pam
  24. )
  25. tools? ( dev-lang/perl )
  26. audit? ( sys-process/audit )
  27. kernel_linux? (
  28. sys-process/psmisc
  29. !<sys-process/procps-3.3.9-r2
  30. )
  31. selinux? (
  32. sys-apps/policycoreutils
  33. sys-libs/libselinux
  34. )
  35. !<sys-apps/baselayout-2.1-r1
  36. !<sys-fs/udev-init-scripts-27"
  37. DEPEND="${COMMON_DEPEND}
  38. virtual/os-headers
  39. ncurses? ( virtual/pkgconfig )"
  40. RDEPEND="${COMMON_DEPEND}
  41. !prefix? (
  42. kernel_linux? ( >=sys-apps/sysvinit-2.86-r6 )
  43. kernel_FreeBSD? ( sys-freebsd/freebsd-sbin )
  44. )
  45. selinux? (
  46. sec-policy/selinux-base-policy
  47. sec-policy/selinux-openrc
  48. )
  49. "
  50. PDEPEND="netifrc? ( net-misc/netifrc )"
  51. src_prepare() {
  52. sed -i 's:0444:0644:' mk/sys.mk || die
  53. if [[ ${PV} == "9999" ]] ; then
  54. local ver="git-${EGIT_VERSION:0:6}"
  55. sed -i "/^GITVER[[:space:]]*=/s:=.*:=${ver}:" mk/gitver.mk || die
  56. fi
  57. # Allow user patches to be applied without modifying the ebuild
  58. epatch_user
  59. }
  60. src_compile() {
  61. unset LIBDIR #266688
  62. MAKE_ARGS="${MAKE_ARGS}
  63. LIBNAME=$(get_libdir)
  64. LIBEXECDIR=${EPREFIX}/$(get_libdir)/rc
  65. MKNET=$(usex newnet)
  66. MKSELINUX=$(usex selinux)
  67. MKAUDIT=$(usex audit)
  68. MKPAM=$(usev pam)
  69. MKSTATICLIBS=$(usex static-libs)
  70. MKTOOLS=$(usex tools)"
  71. local brand="Unknown"
  72. if use kernel_linux ; then
  73. MAKE_ARGS="${MAKE_ARGS} OS=Linux"
  74. brand="Linux"
  75. elif use kernel_FreeBSD ; then
  76. MAKE_ARGS="${MAKE_ARGS} OS=FreeBSD"
  77. brand="FreeBSD"
  78. fi
  79. export BRANDING="Gentoo ${brand}"
  80. use prefix && MAKE_ARGS="${MAKE_ARGS} MKPREFIX=yes PREFIX=${EPREFIX}"
  81. export DEBUG=$(usev debug)
  82. export MKTERMCAP=$(usev ncurses)
  83. tc-export CC AR RANLIB
  84. emake ${MAKE_ARGS}
  85. }
  86. # set_config <file> <option name> <yes value> <no value> test
  87. # a value of "#" will just comment out the option
  88. set_config() {
  89. local file="${ED}/$1" var=$2 val com
  90. eval "${@:5}" && val=$3 || val=$4
  91. [[ ${val} == "#" ]] && com="#" && val='\2'
  92. sed -i -r -e "/^#?${var}=/{s:=([\"'])?([^ ]*)\1?:=\1${val}\1:;s:^#?:${com}:}" "${file}"
  93. }
  94. set_config_yes_no() {
  95. set_config "$1" "$2" YES NO "${@:3}"
  96. }
  97. src_install() {
  98. emake ${MAKE_ARGS} DESTDIR="${D}" install
  99. # move the shared libs back to /usr so ldscript can install
  100. # more of a minimal set of files
  101. # disabled for now due to #270646
  102. #mv "${ED}"/$(get_libdir)/lib{einfo,rc}* "${ED}"/usr/$(get_libdir)/ || die
  103. #gen_usr_ldscript -a einfo rc
  104. gen_usr_ldscript libeinfo.so
  105. gen_usr_ldscript librc.so
  106. if ! use kernel_linux; then
  107. keepdir /$(get_libdir)/rc/init.d
  108. fi
  109. keepdir /$(get_libdir)/rc/tmp
  110. # Backup our default runlevels
  111. dodir /usr/share/"${PN}"
  112. cp -PR "${ED}"/etc/runlevels "${ED}"/usr/share/${PN} || die
  113. rm -rf "${ED}"/etc/runlevels
  114. # Setup unicode defaults for silly unicode users
  115. set_config_yes_no /etc/rc.conf unicode use unicode
  116. # Cater to the norm
  117. set_config_yes_no /etc/conf.d/keymaps windowkeys '(' use x86 '||' use amd64 ')'
  118. # On HPPA, do not run consolefont by default (bug #222889)
  119. if use hppa; then
  120. rm -f "${ED}"/usr/share/openrc/runlevels/boot/consolefont
  121. fi
  122. # Support for logfile rotation
  123. insinto /etc/logrotate.d
  124. newins "${FILESDIR}"/openrc.logrotate openrc
  125. # install the gentoo pam.d file
  126. newpamd "${FILESDIR}"/start-stop-daemon.pam start-stop-daemon
  127. # install documentation
  128. dodoc ChangeLog *.md
  129. if use newnet; then
  130. dodoc README.newnet
  131. fi
  132. }
  133. add_boot_init() {
  134. local initd=$1
  135. local runlevel=${2:-boot}
  136. # if the initscript is not going to be installed and is not
  137. # currently installed, return
  138. [[ -e "${ED}"/etc/init.d/${initd} || -e "${EROOT}"etc/init.d/${initd} ]] \
  139. || return
  140. [[ -e "${EROOT}"etc/runlevels/${runlevel}/${initd} ]] && return
  141. # if runlevels dont exist just yet, then create it but still flag
  142. # to pkg_postinst that it needs real setup #277323
  143. if [[ ! -d "${EROOT}"etc/runlevels/${runlevel} ]] ; then
  144. mkdir -p "${EROOT}"etc/runlevels/${runlevel}
  145. touch "${EROOT}"etc/runlevels/.add_boot_init.created
  146. fi
  147. elog "Auto-adding '${initd}' service to your ${runlevel} runlevel"
  148. ln -snf /etc/init.d/${initd} "${EROOT}"etc/runlevels/${runlevel}/${initd}
  149. }
  150. add_boot_init_mit_config() {
  151. local config=$1 initd=$2
  152. if [[ -e ${EROOT}${config} ]] ; then
  153. if [[ -n $(sed -e 's:#.*::' -e '/^[[:space:]]*$/d' "${EROOT}"${config}) ]] ; then
  154. add_boot_init ${initd}
  155. fi
  156. fi
  157. }
  158. pkg_preinst() {
  159. local f LIBDIR=$(get_libdir)
  160. # avoid default thrashing in conf.d files when possible #295406
  161. if [[ -e "${EROOT}"etc/conf.d/hostname ]] ; then
  162. (
  163. unset hostname HOSTNAME
  164. source "${EROOT}"etc/conf.d/hostname
  165. : ${hostname:=${HOSTNAME}}
  166. [[ -n ${hostname} ]] && set_config /etc/conf.d/hostname hostname "${hostname}"
  167. )
  168. fi
  169. # set default interactive shell to sulogin if it exists
  170. set_config /etc/rc.conf rc_shell /sbin/sulogin "#" test -e /sbin/sulogin
  171. # termencoding was added in 0.2.1 and needed in boot
  172. has_version ">=sys-apps/openrc-0.2.1" || add_boot_init termencoding
  173. # swapfiles was added in 0.9.9 and needed in boot (february 2012)
  174. has_version ">=sys-apps/openrc-0.9.9" || add_boot_init swapfiles
  175. if ! has_version ">=sys-apps/openrc-0.11"; then
  176. add_boot_init sysfs sysinit
  177. fi
  178. if ! has_version ">=sys-apps/openrc-0.11.3" ; then
  179. migrate_udev_mount_script
  180. add_boot_init tmpfiles.setup boot
  181. fi
  182. # these were added in 0.12.
  183. if ! has_version ">=sys-apps/openrc-0.12"; then
  184. add_boot_init loopback
  185. add_boot_init tmpfiles.dev sysinit
  186. # ensure existing /etc/conf.d/net is not removed
  187. # undoes the hack to get around CONFIG_PROTECT in openrc-0.11.8 and earlier
  188. # this needs to stay in openrc ebuilds for a long time. :(
  189. # Added in 0.12.
  190. if [[ -f "${EROOT}"etc/conf.d/net ]]; then
  191. einfo "Modifying conf.d/net to keep it from being removed"
  192. cat <<-EOF >>"${EROOT}"etc/conf.d/net
  193. # The network scripts are now part of net-misc/netifrc
  194. # In order to avoid sys-apps/${P} from removing this file, this comment was
  195. # added; you can safely remove this comment. Please see
  196. # /usr/share/doc/netifrc*/README* for more information.
  197. EOF
  198. fi
  199. fi
  200. has_version ">=sys-apps/openrc-0.14" || add_boot_init binfmt
  201. }
  202. # >=OpenRC-0.11.3 requires udev-mount to be in the sysinit runlevel with udev.
  203. migrate_udev_mount_script() {
  204. if [ -e "${EROOT}"etc/runlevels/sysinit/udev -a \
  205. ! -e "${EROOT}"etc/runlevels/sysinit/udev-mount ]; then
  206. add_boot_init udev-mount sysinit
  207. fi
  208. return 0
  209. }
  210. pkg_postinst() {
  211. local LIBDIR=$(get_libdir)
  212. # Make our runlevels if they don't exist
  213. if [[ ! -e "${EROOT}"etc/runlevels ]] || [[ -e "${EROOT}"etc/runlevels/.add_boot_init.created ]] ; then
  214. einfo "Copying across default runlevels"
  215. cp -RPp "${EROOT}"usr/share/${PN}/runlevels "${EROOT}"etc
  216. rm -f "${EROOT}"etc/runlevels/.add_boot_init.created
  217. else
  218. if [[ ! -e "${EROOT}"etc/runlevels/sysinit/devfs ]] ; then
  219. mkdir -p "${EROOT}"etc/runlevels/sysinit
  220. cp -RPp "${EROOT}"usr/share/${PN}/runlevels/sysinit/* \
  221. "${EROOT}"etc/runlevels/sysinit
  222. fi
  223. if [[ ! -e "${EROOT}"etc/runlevels/shutdown/mount-ro ]] ; then
  224. mkdir -p "${EROOT}"etc/runlevels/shutdown
  225. cp -RPp "${EROOT}"usr/share/${PN}/runlevels/shutdown/* \
  226. "${EROOT}"etc/runlevels/shutdown
  227. fi
  228. fi
  229. if use hppa; then
  230. elog "Setting the console font does not work on all HPPA consoles."
  231. elog "You can still enable it by running:"
  232. elog "# rc-update add consolefont boot"
  233. fi
  234. # Handle the conf.d/local.{start,stop} -> local.d transition
  235. if path_exists -o "${EROOT}"etc/conf.d/local.{start,stop} ; then
  236. elog "Moving your ${EROOT}etc/conf.d/local.{start,stop}"
  237. elog "files to ${EROOT}etc/local.d"
  238. mv "${EROOT}"etc/conf.d/local.start "${EROOT}"etc/local.d/baselayout1.start
  239. mv "${EROOT}"etc/conf.d/local.stop "${EROOT}"etc/local.d/baselayout1.stop
  240. chmod +x "${EROOT}"etc/local.d/*{start,stop}
  241. fi
  242. if use kernel_linux && [[ "${EROOT}" = "/" ]]; then
  243. if ! /$(get_libdir)/rc/sh/migrate-to-run.sh; then
  244. ewarn "The dependency data could not be migrated to /run/openrc."
  245. ewarn "This means you need to reboot your system."
  246. fi
  247. fi
  248. # update the dependency tree after touching all files #224171
  249. [[ "${EROOT}" = "/" ]] && "${EROOT}/${LIBDIR}"/rc/bin/rc-depend -u
  250. if ! use newnet && ! use netifrc; then
  251. ewarn "You have emerged OpenRc without network support. This"
  252. ewarn "means you need to SET UP a network manager such as"
  253. ewarn " net-misc/netifrc, net-misc/dhcpcd, net-misc/wicd,"
  254. ewarn "net-misc/NetworkManager, or net-misc/badvpn."
  255. ewarn "Or, you have the option of emerging openrc with the newnet"
  256. ewarn "use flag and configuring /etc/conf.d/network and"
  257. ewarn "/etc/conf.d/staticroute if you only use static interfaces."
  258. ewarn
  259. fi
  260. if use newnet && [ ! -e "${EROOT}"etc/runlevels/boot/network ]; then
  261. ewarn "Please add the network service to your boot runlevel"
  262. ewarn "as soon as possible. Not doing so could leave you with a system"
  263. ewarn "without networking."
  264. ewarn
  265. fi
  266. ewarn "In this version of OpenRC, the loopback interface no longer"
  267. ewarn "satisfies the net virtual."
  268. ewarn "If you have services now which do not start because of this,"
  269. ewarn "They can be fixed by adding rc_need=\"!net\""
  270. ewarn "to the ${EROOT}etc/conf.d/<servicename> file."
  271. ewarn "You should also file a bug against the service asking that"
  272. ewarn "need net be dropped from the dependencies."
  273. ewarn "The bug you file should block the following tracker:"
  274. ewarn "https://bugs.gentoo.org/show_bug.cgi?id=439092"
  275. ewarn
  276. # Updated for 0.13.2.
  277. ewarn "Bug https://bugs.gentoo.org/show_bug.cgi?id=427996 was not"
  278. ewarn "fixed correctly in earlier versions of OpenRC."
  279. ewarn "The correct fix is implemented in this version, but that"
  280. ewarn "means netmount needs to be added to the default runlevel if"
  281. ewarn "you are using nfs file systems."
  282. ewarn
  283. elog "You should now update all files in /etc, using etc-update"
  284. elog "or equivalent before restarting any services or this host."
  285. }
  286.