| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | UPDATERCPN ?= "${PN}" | 
|  | 2 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3 | DEPENDS_append_class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', ' update-rc.d-native update-rc.d initscripts', '', d)}" | 
|  | 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 |  | 
|  | 14 | updatercd_preinst() { | 
|  | 15 | if [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 16 | ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || : | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | fi | 
|  | 18 | if type update-rc.d >/dev/null 2>/dev/null; then | 
|  | 19 | if [ -n "$D" ]; then | 
|  | 20 | OPT="-f -r $D" | 
|  | 21 | else | 
|  | 22 | OPT="-f" | 
|  | 23 | fi | 
|  | 24 | update-rc.d $OPT ${INITSCRIPT_NAME} remove | 
|  | 25 | fi | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | updatercd_postinst() { | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 29 | # Begin section update-rc.d | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | if type update-rc.d >/dev/null 2>/dev/null; then | 
|  | 31 | if [ -n "$D" ]; then | 
|  | 32 | OPT="-r $D" | 
|  | 33 | else | 
|  | 34 | OPT="-s" | 
|  | 35 | fi | 
|  | 36 | update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS} | 
|  | 37 | fi | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 38 | # End section update-rc.d | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | } | 
|  | 40 |  | 
|  | 41 | updatercd_prerm() { | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 42 | # Begin section update-rc.d | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 43 | if [ -z "$D" -a -x "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then | 
|  | 44 | ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || : | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | fi | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 46 | # End section update-rc.d | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | } | 
|  | 48 |  | 
|  | 49 | updatercd_postrm() { | 
|  | 50 | if type update-rc.d >/dev/null 2>/dev/null; then | 
|  | 51 | if [ -n "$D" ]; then | 
|  | 52 | OPT="-f -r $D" | 
|  | 53 | else | 
|  | 54 | OPT="-f" | 
|  | 55 | fi | 
|  | 56 | update-rc.d $OPT ${INITSCRIPT_NAME} remove | 
|  | 57 | fi | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 |  | 
|  | 61 | def update_rc_after_parse(d): | 
|  | 62 | if d.getVar('INITSCRIPT_PACKAGES', False) == None: | 
|  | 63 | if d.getVar('INITSCRIPT_NAME', False) == None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 64 | 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] | 65 | if d.getVar('INITSCRIPT_PARAMS', False) == None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 66 | 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] | 67 |  | 
|  | 68 | python __anonymous() { | 
|  | 69 | update_rc_after_parse(d) | 
|  | 70 | } | 
|  | 71 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 72 | PACKAGESPLITFUNCS_prepend = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'populate_packages_updatercd ', '', d)}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | PACKAGESPLITFUNCS_remove_class-nativesdk = "populate_packages_updatercd " | 
|  | 74 |  | 
|  | 75 | populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_preinst updatercd_postinst" | 
|  | 76 | populate_packages_updatercd[vardepsexclude] += "OVERRIDES" | 
|  | 77 |  | 
|  | 78 | python populate_packages_updatercd () { | 
|  | 79 | def update_rcd_auto_depend(pkg): | 
|  | 80 | import subprocess | 
|  | 81 | import os | 
|  | 82 | path = d.expand("${D}${INIT_D_DIR}/${INITSCRIPT_NAME}") | 
|  | 83 | if not os.path.exists(path): | 
|  | 84 | return | 
|  | 85 | statement = "grep -q -w '/etc/init.d/functions' %s" % path | 
|  | 86 | if subprocess.call(statement, shell=True) == 0: | 
|  | 87 | mlprefix = d.getVar('MLPREFIX', True) or "" | 
|  | 88 | d.appendVar('RDEPENDS_' + pkg, ' %sinitscripts-functions' % (mlprefix)) | 
|  | 89 |  | 
|  | 90 | def update_rcd_package(pkg): | 
|  | 91 | bb.debug(1, 'adding update-rc.d calls to preinst/postinst/prerm/postrm for %s' % pkg) | 
|  | 92 |  | 
|  | 93 | localdata = bb.data.createCopy(d) | 
|  | 94 | overrides = localdata.getVar("OVERRIDES", True) | 
|  | 95 | localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides)) | 
|  | 96 | bb.data.update_data(localdata) | 
|  | 97 |  | 
|  | 98 | update_rcd_auto_depend(pkg) | 
|  | 99 |  | 
|  | 100 | preinst = d.getVar('pkg_preinst_%s' % pkg, True) | 
|  | 101 | if not preinst: | 
|  | 102 | preinst = '#!/bin/sh\n' | 
|  | 103 | preinst += localdata.getVar('updatercd_preinst', True) | 
|  | 104 | d.setVar('pkg_preinst_%s' % pkg, preinst) | 
|  | 105 |  | 
|  | 106 | postinst = d.getVar('pkg_postinst_%s' % pkg, True) | 
|  | 107 | if not postinst: | 
|  | 108 | postinst = '#!/bin/sh\n' | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 109 | postinst = postinst.splitlines(True) | 
|  | 110 | try: | 
|  | 111 | index = postinst.index('# End section update-alternatives\n') | 
|  | 112 | postinst.insert(index + 1, localdata.getVar('updatercd_postinst', True)) | 
|  | 113 | except ValueError: | 
|  | 114 | postinst.append(localdata.getVar('updatercd_postinst', True)) | 
|  | 115 | postinst = ''.join(postinst) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | d.setVar('pkg_postinst_%s' % pkg, postinst) | 
|  | 117 |  | 
|  | 118 | prerm = d.getVar('pkg_prerm_%s' % pkg, True) | 
|  | 119 | if not prerm: | 
|  | 120 | prerm = '#!/bin/sh\n' | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 121 | prerm = prerm.splitlines(True) | 
|  | 122 | try: | 
|  | 123 | index = prerm.index('# Begin section update-alternatives\n') | 
|  | 124 | prerm.insert(index, localdata.getVar('updatercd_prerm', True)) | 
|  | 125 | except ValueError: | 
|  | 126 | prerm.append(localdata.getVar('updatercd_prerm', True)) | 
|  | 127 | prerm = ''.join(prerm) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | d.setVar('pkg_prerm_%s' % pkg, prerm) | 
|  | 129 |  | 
|  | 130 | postrm = d.getVar('pkg_postrm_%s' % pkg, True) | 
|  | 131 | if not postrm: | 
|  | 132 | postrm = '#!/bin/sh\n' | 
|  | 133 | postrm += localdata.getVar('updatercd_postrm', True) | 
|  | 134 | d.setVar('pkg_postrm_%s' % pkg, postrm) | 
|  | 135 |  | 
|  | 136 | d.appendVar('RRECOMMENDS_' + pkg, " ${MLPREFIX}${UPDATERCD}") | 
|  | 137 |  | 
|  | 138 | # Check that this class isn't being inhibited (generally, by | 
|  | 139 | # systemd.bbclass) before doing any work. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 140 | if not d.getVar("INHIBIT_UPDATERCD_BBCLASS", True): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | pkgs = d.getVar('INITSCRIPT_PACKAGES', True) | 
|  | 142 | if pkgs == None: | 
|  | 143 | pkgs = d.getVar('UPDATERCPN', True) | 
|  | 144 | packages = (d.getVar('PACKAGES', True) or "").split() | 
|  | 145 | if not pkgs in packages and packages != []: | 
|  | 146 | pkgs = packages[0] | 
|  | 147 | for pkg in pkgs.split(): | 
|  | 148 | update_rcd_package(pkg) | 
|  | 149 | } |