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