blob: 265c4be9d1ef4f7ff5a2cfbb824873108bc3a92c [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001UPDATERCPN ?= "${PN}"
2
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003DEPENDS_append_class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', ' update-rc.d initscripts', '', d)}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -06004
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005UPDATERCD = "update-rc.d"
6UPDATERCD_class-cross = ""
7UPDATERCD_class-native = ""
8UPDATERCD_class-nativesdk = ""
9
10INITSCRIPT_PARAMS ?= "defaults"
11
12INIT_D_DIR = "${sysconfdir}/init.d"
13
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014def 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 Williamsc124f4f2015-09-15 14:41:29 -050023updatercd_preinst() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024if ${@use_updatercd(d)} && [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 if [ -n "$D" ]; then
29 OPT="-f -r $D"
30 else
31 OPT="-f"
32 fi
33 update-rc.d $OPT ${INITSCRIPT_NAME} remove
34fi
35}
36
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037PACKAGE_WRITE_DEPS += "update-rc.d-native"
38
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039updatercd_postinst() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041 if [ -n "$D" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042 OPT="-f -r $D"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044 OPT="-f -s"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 fi
46 update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}
47fi
48}
49
50updatercd_prerm() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051if ${@use_updatercd(d)} && [ -z "$D" -a -x "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053fi
54}
55
56updatercd_postrm() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 if [ -n "$D" ]; then
59 OPT="-f -r $D"
60 else
61 OPT="-f"
62 fi
63 update-rc.d $OPT ${INITSCRIPT_NAME} remove
64fi
65}
66
67
68def update_rc_after_parse(d):
69 if d.getVar('INITSCRIPT_PACKAGES', False) == None:
70 if d.getVar('INITSCRIPT_NAME', False) == None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060071 bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE', False))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072 if d.getVar('INITSCRIPT_PARAMS', False) == None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060073 bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE', False))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074
75python __anonymous() {
76 update_rc_after_parse(d)
77}
78
Patrick Williamsc0f7c042017-02-23 20:41:17 -060079PACKAGESPLITFUNCS_prepend = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'populate_packages_updatercd ', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080PACKAGESPLITFUNCS_remove_class-nativesdk = "populate_packages_updatercd "
81
82populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_preinst updatercd_postinst"
83populate_packages_updatercd[vardepsexclude] += "OVERRIDES"
84
85python 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 Bishop00111322018-04-01 22:23:53 -040094 mlprefix = d.getVar('MLPREFIX') or ""
95 d.appendVar('RDEPENDS_' + pkg, ' %sinitd-functions' % (mlprefix))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096
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 Bishop6e60e8b2018-02-01 10:27:11 -0500101 overrides = localdata.getVar("OVERRIDES")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103
104 update_rcd_auto_depend(pkg)
105
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500106 preinst = d.getVar('pkg_preinst_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 if not preinst:
108 preinst = '#!/bin/sh\n'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 preinst += localdata.getVar('updatercd_preinst')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 d.setVar('pkg_preinst_%s' % pkg, preinst)
111
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 postinst = d.getVar('pkg_postinst_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 if not postinst:
114 postinst = '#!/bin/sh\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500115 postinst += localdata.getVar('updatercd_postinst')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 d.setVar('pkg_postinst_%s' % pkg, postinst)
117
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 prerm = d.getVar('pkg_prerm_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 if not prerm:
120 prerm = '#!/bin/sh\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500121 prerm += localdata.getVar('updatercd_prerm')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 d.setVar('pkg_prerm_%s' % pkg, prerm)
123
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124 postrm = d.getVar('pkg_postrm_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 if not postrm:
126 postrm = '#!/bin/sh\n'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 postrm += localdata.getVar('updatercd_postrm')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 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 Bishop6e60e8b2018-02-01 10:27:11 -0500134 if not d.getVar("INHIBIT_UPDATERCD_BBCLASS"):
135 pkgs = d.getVar('INITSCRIPT_PACKAGES')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 if pkgs == None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500137 pkgs = d.getVar('UPDATERCPN')
138 packages = (d.getVar('PACKAGES') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 if not pkgs in packages and packages != []:
140 pkgs = packages[0]
141 for pkg in pkgs.split():
142 update_rcd_package(pkg)
143}