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.bbclass130
1 files changed, 130 insertions, 0 deletions
diff --git a/meta/classes/update-rc.d.bbclass b/meta/classes/update-rc.d.bbclass
new file mode 100644
index 0000000..0ac2af7
--- /dev/null
+++ b/meta/classes/update-rc.d.bbclass
@@ -0,0 +1,130 @@
1UPDATERCPN ?= "${PN}"
2
3DEPENDS_append = " update-rc.d-native"
4UPDATERCD = "update-rc.d"
5UPDATERCD_class-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_preinst() {
16if [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
17 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop
18fi
19if type update-rc.d >/dev/null 2>/dev/null; then
20 if [ -n "$D" ]; then
21 OPT="-f -r $D"
22 else
23 OPT="-f"
24 fi
25 update-rc.d $OPT ${INITSCRIPT_NAME} remove
26fi
27}
28
29updatercd_postinst() {
30if type update-rc.d >/dev/null 2>/dev/null; then
31 if [ -n "$D" ]; then
32 OPT="-r $D"
33 else
34 OPT="-s"
35 fi
36 update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}
37fi
38}
39
40updatercd_prerm() {
41if [ -z "$D" ]; then
42 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop
43fi
44}
45
46updatercd_postrm() {
47if type update-rc.d >/dev/null 2>/dev/null; then
48 if [ -n "$D" ]; then
49 OPT="-r $D"
50 else
51 OPT=""
52 fi
53 update-rc.d $OPT ${INITSCRIPT_NAME} remove
54fi
55}
56
57
58def update_rc_after_parse(d):
59 if d.getVar('INITSCRIPT_PACKAGES') == None:
60 if d.getVar('INITSCRIPT_NAME') == None:
61 raise bb.build.FuncFailed("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE'))
62 if d.getVar('INITSCRIPT_PARAMS') == None:
63 raise bb.build.FuncFailed("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE'))
64
65python __anonymous() {
66 update_rc_after_parse(d)
67}
68
69PACKAGESPLITFUNCS_prepend = "populate_packages_updatercd "
70
71populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_preinst updatercd_postinst"
72
73python 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 d.appendVar('RDEPENDS_' + pkg, ' initscripts-functions')
83
84 def update_rcd_package(pkg):
85 bb.debug(1, 'adding update-rc.d calls to preinst/postinst/prerm/postrm for %s' % pkg)
86
87 localdata = bb.data.createCopy(d)
88 overrides = localdata.getVar("OVERRIDES", True)
89 localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides))
90 bb.data.update_data(localdata)
91
92 update_rcd_auto_depend(pkg)
93
94 preinst = d.getVar('pkg_preinst_%s' % pkg, True)
95 if not preinst:
96 preinst = '#!/bin/sh\n'
97 preinst += localdata.getVar('updatercd_preinst', True)
98 d.setVar('pkg_preinst_%s' % pkg, preinst)
99
100 postinst = d.getVar('pkg_postinst_%s' % pkg, True)
101 if not postinst:
102 postinst = '#!/bin/sh\n'
103 postinst += localdata.getVar('updatercd_postinst', True)
104 d.setVar('pkg_postinst_%s' % pkg, postinst)
105
106 prerm = d.getVar('pkg_prerm_%s' % pkg, True)
107 if not prerm:
108 prerm = '#!/bin/sh\n'
109 prerm += localdata.getVar('updatercd_prerm', True)
110 d.setVar('pkg_prerm_%s' % pkg, prerm)
111
112 postrm = d.getVar('pkg_postrm_%s' % pkg, True)
113 if not postrm:
114 postrm = '#!/bin/sh\n'
115 postrm += localdata.getVar('updatercd_postrm', True)
116 d.setVar('pkg_postrm_%s' % pkg, postrm)
117
118 # Check that this class isn't being inhibited (generally, by
119 # systemd.bbclass) before doing any work.
120 if oe.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d) and \
121 not d.getVar("INHIBIT_UPDATERCD_BBCLASS", True):
122 pkgs = d.getVar('INITSCRIPT_PACKAGES', True)
123 if pkgs == None:
124 pkgs = d.getVar('UPDATERCPN', True)
125 packages = (d.getVar('PACKAGES', True) or "").split()
126 if not pkgs in packages and packages != []:
127 pkgs = packages[0]
128 for pkg in pkgs.split():
129 update_rcd_package(pkg)
130}