openrc-0.22.4.ebuild 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. inherit flag-o-matic pam toolchain-funcs
  5. DESCRIPTION="OpenRC manages the services, startup and shutdown of a host"
  6. HOMEPAGE="https://github.com/openrc/openrc/"
  7. if [[ ${PV} == "9999" ]]; then
  8. EGIT_REPO_URI="git://github.com/OpenRC/${PN}.git"
  9. inherit git-r3
  10. else
  11. SRC_URI="https://github.com/${PN}/${PN}/archive/${PV}.tar.gz -> ${P}.tar.gz"
  12. KEYWORDS="alpha amd64 arm ~arm64 hppa ia64 ~m68k ~mips ppc ppc64 ~s390 ~sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
  13. fi
  14. LICENSE="BSD-2"
  15. SLOT="0"
  16. IUSE="audit debug ncurses pam newnet prefix +netifrc selinux static-libs
  17. tools unicode kernel_linux kernel_FreeBSD"
  18. COMMON_DEPEND="kernel_FreeBSD? ( || ( >=sys-freebsd/freebsd-ubin-9.0_rc sys-process/fuser-bsd ) )
  19. ncurses? ( sys-libs/ncurses:0= )
  20. pam? (
  21. sys-auth/pambase
  22. virtual/pam
  23. )
  24. tools? ( dev-lang/perl )
  25. audit? ( sys-process/audit )
  26. kernel_linux? (
  27. sys-process/psmisc
  28. !<sys-process/procps-3.3.9-r2
  29. )
  30. selinux? (
  31. sys-apps/policycoreutils
  32. sys-libs/libselinux
  33. )
  34. !<sys-apps/baselayout-2.1-r1
  35. !<sys-fs/udev-init-scripts-27"
  36. DEPEND="${COMMON_DEPEND}
  37. virtual/os-headers
  38. ncurses? ( virtual/pkgconfig )"
  39. RDEPEND="${COMMON_DEPEND}
  40. !prefix? (
  41. kernel_linux? ( >=sys-apps/sysvinit-2.86-r6 )
  42. kernel_FreeBSD? ( sys-freebsd/freebsd-sbin )
  43. )
  44. selinux? (
  45. sec-policy/selinux-base-policy
  46. sec-policy/selinux-openrc
  47. )
  48. "
  49. PDEPEND="netifrc? ( net-misc/netifrc )"
  50. src_prepare() {
  51. sed -i 's:0444:0644:' mk/sys.mk || die
  52. if [[ ${PV} == "9999" ]] ; then
  53. local ver="git-${EGIT_VERSION:0:6}"
  54. sed -i "/^GITVER[[:space:]]*=/s:=.*:=${ver}:" mk/gitver.mk || die
  55. fi
  56. # Allow user patches to be applied without modifying the ebuild
  57. eapply_user
  58. }
  59. src_compile() {
  60. unset LIBDIR #266688
  61. MAKE_ARGS="${MAKE_ARGS}
  62. LIBNAME=$(get_libdir)
  63. LIBEXECDIR=${EPREFIX}/$(get_libdir)/rc
  64. MKNET=$(usex newnet)
  65. MKSELINUX=$(usex selinux)
  66. MKAUDIT=$(usex audit)
  67. MKPAM=$(usev pam)
  68. MKSTATICLIBS=$(usex static-libs)
  69. MKTOOLS=$(usex tools)"
  70. local brand="Unknown"
  71. if use kernel_linux ; then
  72. MAKE_ARGS="${MAKE_ARGS} OS=Linux"
  73. brand="Linux"
  74. elif use kernel_FreeBSD ; then
  75. MAKE_ARGS="${MAKE_ARGS} OS=FreeBSD"
  76. brand="FreeBSD"
  77. fi
  78. export BRANDING="Gentoo ${brand}"
  79. use prefix && MAKE_ARGS="${MAKE_ARGS} MKPREFIX=yes PREFIX=${EPREFIX}"
  80. export DEBUG=$(usev debug)
  81. export MKTERMCAP=$(usev ncurses)
  82. tc-export CC AR RANLIB
  83. emake ${MAKE_ARGS}
  84. }
  85. # set_config <file> <option name> <yes value> <no value> test
  86. # a value of "#" will just comment out the option
  87. set_config() {
  88. local file="${ED}/$1" var=$2 val com
  89. eval "${@:5}" && val=$3 || val=$4
  90. [[ ${val} == "#" ]] && com="#" && val='\2'
  91. sed -i -r -e "/^#?${var}=/{s:=([\"'])?([^ ]*)\1?:=\1${val}\1:;s:^#?:${com}:}" "${file}"
  92. }
  93. set_config_yes_no() {
  94. set_config "$1" "$2" YES NO "${@:3}"
  95. }
  96. src_install() {
  97. emake ${MAKE_ARGS} DESTDIR="${D}" install
  98. # move the shared libs back to /usr so ldscript can install
  99. # more of a minimal set of files
  100. # disabled for now due to #270646
  101. #mv "${ED}"/$(get_libdir)/lib{einfo,rc}* "${ED}"/usr/$(get_libdir)/ || die
  102. #gen_usr_ldscript -a einfo rc
  103. gen_usr_ldscript libeinfo.so
  104. gen_usr_ldscript librc.so
  105. if ! use kernel_linux; then
  106. keepdir /$(get_libdir)/rc/init.d
  107. fi
  108. keepdir /$(get_libdir)/rc/tmp
  109. # Backup our default runlevels
  110. dodir /usr/share/"${PN}"
  111. cp -PR "${ED}"/etc/runlevels "${ED}"/usr/share/${PN} || die
  112. rm -rf "${ED}"/etc/runlevels
  113. # Setup unicode defaults for silly unicode users
  114. set_config_yes_no /etc/rc.conf unicode use unicode
  115. # Cater to the norm
  116. set_config_yes_no /etc/conf.d/keymaps windowkeys '(' use x86 '||' use amd64 ')'
  117. # On HPPA, do not run consolefont by default (bug #222889)
  118. if use hppa; then
  119. rm -f "${ED}"/usr/share/openrc/runlevels/boot/consolefont
  120. fi
  121. # Support for logfile rotation
  122. insinto /etc/logrotate.d
  123. newins "${FILESDIR}"/openrc.logrotate openrc
  124. # install gentoo pam.d files
  125. newpamd "${FILESDIR}"/start-stop-daemon.pam start-stop-daemon
  126. newpamd "${FILESDIR}"/start-stop-daemon.pam supervise-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. if ! has_version ">=sys-apps/openrc-0.18.3"; then
  202. add_boot_init mtab
  203. if [[ -f "${EROOT}"etc/mtab ]] && [[ ! -L "${EROOT}"etc/mtab ]]; then
  204. ewarn "${EROOT}etc/mtab will be replaced with a"
  205. ewarn "symbolic link to /proc/self/mounts on the next"
  206. ewarn "reboot."
  207. ewarn "Change the setting in ${EROOT}etc/conf.d/mtab"
  208. ewarn "if you do not want this to happen."
  209. fi
  210. fi
  211. }
  212. # >=OpenRC-0.11.3 requires udev-mount to be in the sysinit runlevel with udev.
  213. migrate_udev_mount_script() {
  214. if [ -e "${EROOT}"etc/runlevels/sysinit/udev -a \
  215. ! -e "${EROOT}"etc/runlevels/sysinit/udev-mount ]; then
  216. add_boot_init udev-mount sysinit
  217. fi
  218. return 0
  219. }
  220. pkg_postinst() {
  221. local LIBDIR=$(get_libdir)
  222. # Make our runlevels if they don't exist
  223. if [[ ! -e "${EROOT}"etc/runlevels ]] || [[ -e "${EROOT}"etc/runlevels/.add_boot_init.created ]] ; then
  224. einfo "Copying across default runlevels"
  225. cp -RPp "${EROOT}"usr/share/${PN}/runlevels "${EROOT}"etc
  226. rm -f "${EROOT}"etc/runlevels/.add_boot_init.created
  227. else
  228. if [[ ! -e "${EROOT}"etc/runlevels/sysinit/devfs ]] ; then
  229. mkdir -p "${EROOT}"etc/runlevels/sysinit
  230. cp -RPp "${EROOT}"usr/share/${PN}/runlevels/sysinit/* \
  231. "${EROOT}"etc/runlevels/sysinit
  232. fi
  233. if [[ ! -e "${EROOT}"etc/runlevels/shutdown/mount-ro ]] ; then
  234. mkdir -p "${EROOT}"etc/runlevels/shutdown
  235. cp -RPp "${EROOT}"usr/share/${PN}/runlevels/shutdown/* \
  236. "${EROOT}"etc/runlevels/shutdown
  237. fi
  238. if [[ ! -e "${EROOT}"etc/runlevels/nonetwork/local ]]; then
  239. cp -RPp "${EROOT}"usr/share/${PN}/runlevels/nonetwork \
  240. "${EROOT}"etc/runlevels
  241. fi
  242. fi
  243. if use hppa; then
  244. elog "Setting the console font does not work on all HPPA consoles."
  245. elog "You can still enable it by running:"
  246. elog "# rc-update add consolefont boot"
  247. fi
  248. # Handle the conf.d/local.{start,stop} -> local.d transition
  249. if path_exists -o "${EROOT}"etc/conf.d/local.{start,stop} ; then
  250. elog "Moving your ${EROOT}etc/conf.d/local.{start,stop}"
  251. elog "files to ${EROOT}etc/local.d"
  252. mv "${EROOT}"etc/conf.d/local.start "${EROOT}"etc/local.d/baselayout1.start
  253. mv "${EROOT}"etc/conf.d/local.stop "${EROOT}"etc/local.d/baselayout1.stop
  254. chmod +x "${EROOT}"etc/local.d/*{start,stop}
  255. fi
  256. if use kernel_linux && [[ "${EROOT}" = "/" ]]; then
  257. if ! /$(get_libdir)/rc/sh/migrate-to-run.sh; then
  258. ewarn "The dependency data could not be migrated to /run/openrc."
  259. ewarn "This means you need to reboot your system."
  260. fi
  261. fi
  262. # update the dependency tree after touching all files #224171
  263. [[ "${EROOT}" = "/" ]] && "${EROOT}/${LIBDIR}"/rc/bin/rc-depend -u
  264. if ! use newnet && ! use netifrc; then
  265. ewarn "You have emerged OpenRc without network support. This"
  266. ewarn "means you need to SET UP a network manager such as"
  267. ewarn " net-misc/netifrc, net-misc/dhcpcd, net-misc/wicd,"
  268. ewarn "net-misc/NetworkManager, or net-vpn/badvpn."
  269. ewarn "Or, you have the option of emerging openrc with the newnet"
  270. ewarn "use flag and configuring /etc/conf.d/network and"
  271. ewarn "/etc/conf.d/staticroute if you only use static interfaces."
  272. ewarn
  273. fi
  274. if use newnet && [ ! -e "${EROOT}"etc/runlevels/boot/network ]; then
  275. ewarn "Please add the network service to your boot runlevel"
  276. ewarn "as soon as possible. Not doing so could leave you with a system"
  277. ewarn "without networking."
  278. ewarn
  279. fi
  280. }