diff options
Diffstat (limited to 'meta/classes/update-rc.d.bbclass')
-rw-r--r-- | meta/classes/update-rc.d.bbclass | 103 |
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 @@ | |||
1 | UPDATERCPN ?= "${PN}" | ||
2 | |||
3 | DEPENDS_append = " update-rc.d-native" | ||
4 | UPDATERCD = "update-rc.d" | ||
5 | UPDATERCD_virtclass-cross = "" | ||
6 | UPDATERCD_class-native = "" | ||
7 | UPDATERCD_class-nativesdk = "" | ||
8 | |||
9 | RRECOMMENDS_${UPDATERCPN}_append = " ${UPDATERCD}" | ||
10 | |||
11 | INITSCRIPT_PARAMS ?= "defaults" | ||
12 | |||
13 | INIT_D_DIR = "${sysconfdir}/init.d" | ||
14 | |||
15 | updatercd_postinst() { | ||
16 | if test "x$D" != "x"; then | ||
17 | OPT="-r $D" | ||
18 | else | ||
19 | OPT="-s" | ||
20 | fi | ||
21 | if type update-rc.d >/dev/null 2>/dev/null; then | ||
22 | update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS} | ||
23 | fi | ||
24 | } | ||
25 | |||
26 | updatercd_prerm() { | ||
27 | if test "x$D" = "x"; then | ||
28 | ${INIT_D_DIR}/${INITSCRIPT_NAME} stop | ||
29 | fi | ||
30 | } | ||
31 | |||
32 | updatercd_postrm() { | ||
33 | if test "$D" != ""; then | ||
34 | OPT="-f -r $D" | ||
35 | else | ||
36 | OPT="" | ||
37 | fi | ||
38 | if type update-rc.d >/dev/null 2>/dev/null; then | ||
39 | update-rc.d $OPT ${INITSCRIPT_NAME} remove | ||
40 | fi | ||
41 | } | ||
42 | |||
43 | |||
44 | def 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 | |||
51 | python __anonymous() { | ||
52 | update_rc_after_parse(d) | ||
53 | } | ||
54 | |||
55 | PACKAGESPLITFUNCS_prepend = "populate_packages_updatercd " | ||
56 | |||
57 | populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_postinst" | ||
58 | |||
59 | python 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 | } | ||