blob: 321924bb3eeb92223198ed35ef322d2a9eabffeb [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001UPDATERCPN ?= "${PN}"
2
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003DEPENDS_append_class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', ' update-rc.d-native update-rc.d initscripts', '', d)}"
4
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
14updatercd_preinst() {
15if [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060016 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017fi
18if 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
25fi
26}
27
28updatercd_postinst() {
29if 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}
36fi
37}
38
39updatercd_prerm() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060040if [ -z "$D" -a -x "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
41 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042fi
43}
44
45updatercd_postrm() {
46if 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
53fi
54}
55
56
57def update_rc_after_parse(d):
58 if d.getVar('INITSCRIPT_PACKAGES', False) == None:
59 if d.getVar('INITSCRIPT_NAME', False) == None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060060 bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE', False))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061 if d.getVar('INITSCRIPT_PARAMS', False) == None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062 bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE', False))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063
64python __anonymous() {
65 update_rc_after_parse(d)
66}
67
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068PACKAGESPLITFUNCS_prepend = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'populate_packages_updatercd ', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069PACKAGESPLITFUNCS_remove_class-nativesdk = "populate_packages_updatercd "
70
71populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_preinst updatercd_postinst"
72populate_packages_updatercd[vardepsexclude] += "OVERRIDES"
73
74python 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 Williamsc0f7c042017-02-23 20:41:17 -0600124 if not d.getVar("INHIBIT_UPDATERCD_BBCLASS", True):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 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}