update-rc.d.bbclass 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. UPDATERCPN ?= "${PN}"
  2. DEPENDS_append_class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', ' update-rc.d initscripts', '', d)}"
  3. UPDATERCD = "update-rc.d"
  4. UPDATERCD_class-cross = ""
  5. UPDATERCD_class-native = ""
  6. UPDATERCD_class-nativesdk = ""
  7. INITSCRIPT_PARAMS ?= "defaults"
  8. INIT_D_DIR = "${sysconfdir}/init.d"
  9. def use_updatercd(d):
  10. # If the distro supports both sysvinit and systemd, and the current recipe
  11. # supports systemd, only call update-rc.d on rootfs creation or if systemd
  12. # is not running. That's because systemctl enable/disable will already call
  13. # update-rc.d if it detects initscripts.
  14. if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and bb.data.inherits_class('systemd', d):
  15. return '[ -n "$D" -o ! -d /run/systemd/system ]'
  16. return 'true'
  17. PACKAGE_WRITE_DEPS += "update-rc.d-native"
  18. updatercd_postinst() {
  19. if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
  20. if [ -n "$D" ]; then
  21. OPT="-r $D"
  22. else
  23. OPT="-s"
  24. fi
  25. update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}
  26. fi
  27. }
  28. updatercd_prerm() {
  29. if ${@use_updatercd(d)} && [ -z "$D" -a -x "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
  30. ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
  31. fi
  32. }
  33. updatercd_postrm() {
  34. if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
  35. if [ -n "$D" ]; then
  36. OPT="-f -r $D"
  37. else
  38. OPT="-f"
  39. fi
  40. update-rc.d $OPT ${INITSCRIPT_NAME} remove
  41. fi
  42. }
  43. def update_rc_after_parse(d):
  44. if d.getVar('INITSCRIPT_PACKAGES', False) == None:
  45. if d.getVar('INITSCRIPT_NAME', False) == None:
  46. bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE', False))
  47. if d.getVar('INITSCRIPT_PARAMS', False) == None:
  48. bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE', False))
  49. python __anonymous() {
  50. update_rc_after_parse(d)
  51. }
  52. PACKAGESPLITFUNCS_prepend = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'populate_packages_updatercd ', '', d)}"
  53. PACKAGESPLITFUNCS_remove_class-nativesdk = "populate_packages_updatercd "
  54. populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_postinst"
  55. populate_packages_updatercd[vardepsexclude] += "OVERRIDES"
  56. python populate_packages_updatercd () {
  57. def update_rcd_auto_depend(pkg):
  58. import subprocess
  59. import os
  60. path = d.expand("${D}${INIT_D_DIR}/${INITSCRIPT_NAME}")
  61. if not os.path.exists(path):
  62. return
  63. statement = "grep -q -w '/etc/init.d/functions' %s" % path
  64. if subprocess.call(statement, shell=True) == 0:
  65. mlprefix = d.getVar('MLPREFIX') or ""
  66. d.appendVar('RDEPENDS_' + pkg, ' %sinitd-functions' % (mlprefix))
  67. def update_rcd_package(pkg):
  68. bb.debug(1, 'adding update-rc.d calls to postinst/prerm/postrm for %s' % pkg)
  69. localdata = bb.data.createCopy(d)
  70. overrides = localdata.getVar("OVERRIDES")
  71. localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides))
  72. update_rcd_auto_depend(pkg)
  73. postinst = d.getVar('pkg_postinst_%s' % pkg)
  74. if not postinst:
  75. postinst = '#!/bin/sh\n'
  76. postinst += localdata.getVar('updatercd_postinst')
  77. d.setVar('pkg_postinst_%s' % pkg, postinst)
  78. prerm = d.getVar('pkg_prerm_%s' % pkg)
  79. if not prerm:
  80. prerm = '#!/bin/sh\n'
  81. prerm += localdata.getVar('updatercd_prerm')
  82. d.setVar('pkg_prerm_%s' % pkg, prerm)
  83. postrm = d.getVar('pkg_postrm_%s' % pkg)
  84. if not postrm:
  85. postrm = '#!/bin/sh\n'
  86. postrm += localdata.getVar('updatercd_postrm')
  87. d.setVar('pkg_postrm_%s' % pkg, postrm)
  88. d.appendVar('RRECOMMENDS_' + pkg, " ${MLPREFIX}${UPDATERCD}")
  89. # Check that this class isn't being inhibited (generally, by
  90. # systemd.bbclass) before doing any work.
  91. if not d.getVar("INHIBIT_UPDATERCD_BBCLASS"):
  92. pkgs = d.getVar('INITSCRIPT_PACKAGES')
  93. if pkgs == None:
  94. pkgs = d.getVar('UPDATERCPN')
  95. packages = (d.getVar('PACKAGES') or "").split()
  96. if not pkgs in packages and packages != []:
  97. pkgs = packages[0]
  98. for pkg in pkgs.split():
  99. update_rcd_package(pkg)
  100. }