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