summaryrefslogtreecommitdiffstats
path: root/meta/classes/update-rc.d.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/update-rc.d.bbclass')
-rw-r--r--meta/classes/update-rc.d.bbclass103
1 files changed, 103 insertions, 0 deletions
diff --git a/meta/classes/update-rc.d.bbclass b/meta/classes/update-rc.d.bbclass
new file mode 100644
index 0000000000..f726f2f4b1
--- /dev/null
+++ b/meta/classes/update-rc.d.bbclass
@@ -0,0 +1,103 @@
1UPDATERCPN ?= "${PN}"
2
3DEPENDS_append = " update-rc.d-native"
4UPDATERCD = "update-rc.d"
5UPDATERCD_virtclass-cross = ""
6UPDATERCD_class-native = ""
7UPDATERCD_class-nativesdk = ""
8
9RRECOMMENDS_${UPDATERCPN}_append = " ${UPDATERCD}"
10
11INITSCRIPT_PARAMS ?= "defaults"
12
13INIT_D_DIR = "${sysconfdir}/init.d"
14
15updatercd_postinst() {
16if test "x$D" != "x"; then
17 OPT="-r $D"
18else
19 OPT="-s"
20fi
21if type update-rc.d >/dev/null 2>/dev/null; then
22 update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}
23fi
24}
25
26updatercd_prerm() {
27if test "x$D" = "x"; then
28 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop
29fi
30}
31
32updatercd_postrm() {
33if test "$D" != ""; then
34 OPT="-f -r $D"
35else
36 OPT=""
37fi
38if type update-rc.d >/dev/null 2>/dev/null; then
39 update-rc.d $OPT ${INITSCRIPT_NAME} remove
40fi
41}
42
43
44def update_rc_after_parse(d):
45 if d.getVar('INITSCRIPT_PACKAGES') == None:
46 if d.getVar('INITSCRIPT_NAME') == None:
47 raise bb.build.FuncFailed("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE'))
48 if d.getVar('INITSCRIPT_PARAMS') == None:
49 raise bb.build.FuncFailed("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE'))
50
51python __anonymous() {
52 update_rc_after_parse(d)
53}
54
55PACKAGESPLITFUNCS_prepend = "populate_packages_updatercd "
56
57populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_postinst"
58
59python populate_packages_updatercd () {
60 def update_rcd_package(pkg):
61 bb.debug(1, 'adding update-rc.d calls to postinst/postrm for %s' % pkg)
62 """
63 update_rc.d postinst is appended here because pkg_postinst may require to
64 execute on the target. Not doing so may cause update_rc.d postinst invoked
65 twice to cause unwanted warnings.
66 """
67
68 localdata = bb.data.createCopy(d)
69 overrides = localdata.getVar("OVERRIDES", True)
70 localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides))
71 bb.data.update_data(localdata)
72
73 postinst = d.getVar('pkg_postinst_%s' % pkg, True)
74 if not postinst:
75 postinst = '#!/bin/sh\n'
76 postinst += localdata.getVar('updatercd_postinst', True)
77 d.setVar('pkg_postinst_%s' % pkg, postinst)
78
79 prerm = d.getVar('pkg_prerm_%s' % pkg, True)
80 if not prerm:
81 prerm = '#!/bin/sh\n'
82 prerm += localdata.getVar('updatercd_prerm', True)
83 d.setVar('pkg_prerm_%s' % pkg, prerm)
84
85 postrm = d.getVar('pkg_postrm_%s' % pkg, True)
86 if not postrm:
87 postrm = '#!/bin/sh\n'
88 postrm += localdata.getVar('updatercd_postrm', True)
89 d.setVar('pkg_postrm_%s' % pkg, postrm)
90
91 # Check that this class isn't being inhibited (generally, by
92 # systemd.bbclass) before doing any work.
93 if "sysvinit" in d.getVar("DISTRO_FEATURES").split() or \
94 not d.getVar("INHIBIT_UPDATERCD_BBCLASS", True):
95 pkgs = d.getVar('INITSCRIPT_PACKAGES', True)
96 if pkgs == None:
97 pkgs = d.getVar('UPDATERCPN', True)
98 packages = (d.getVar('PACKAGES', True) or "").split()
99 if not pkgs in packages and packages != []:
100 pkgs = packages[0]
101 for pkg in pkgs.split():
102 update_rcd_package(pkg)
103}