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