diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /meta/classes/update-rc.d.bbclass | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/classes/update-rc.d.bbclass')
-rw-r--r-- | meta/classes/update-rc.d.bbclass | 135 |
1 files changed, 135 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..bc1aa7dad6 --- /dev/null +++ b/meta/classes/update-rc.d.bbclass | |||
@@ -0,0 +1,135 @@ | |||
1 | UPDATERCPN ?= "${PN}" | ||
2 | |||
3 | DEPENDS_append = " update-rc.d-native" | ||
4 | VIRTUAL-RUNTIME_initscripts ?= "initscripts" | ||
5 | DEPENDS_append_class-target = " ${VIRTUAL-RUNTIME_initscripts}" | ||
6 | UPDATERCD = "update-rc.d" | ||
7 | UPDATERCD_class-cross = "" | ||
8 | UPDATERCD_class-native = "" | ||
9 | UPDATERCD_class-nativesdk = "" | ||
10 | |||
11 | RRECOMMENDS_${UPDATERCPN}_append = " ${UPDATERCD}" | ||
12 | |||
13 | INITSCRIPT_PARAMS ?= "defaults" | ||
14 | |||
15 | INIT_D_DIR = "${sysconfdir}/init.d" | ||
16 | |||
17 | updatercd_preinst() { | ||
18 | if [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then | ||
19 | ${INIT_D_DIR}/${INITSCRIPT_NAME} stop | ||
20 | fi | ||
21 | if type update-rc.d >/dev/null 2>/dev/null; then | ||
22 | if [ -n "$D" ]; then | ||
23 | OPT="-f -r $D" | ||
24 | else | ||
25 | OPT="-f" | ||
26 | fi | ||
27 | update-rc.d $OPT ${INITSCRIPT_NAME} remove | ||
28 | fi | ||
29 | } | ||
30 | |||
31 | updatercd_postinst() { | ||
32 | if type update-rc.d >/dev/null 2>/dev/null; then | ||
33 | if [ -n "$D" ]; then | ||
34 | OPT="-r $D" | ||
35 | else | ||
36 | OPT="-s" | ||
37 | fi | ||
38 | update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS} | ||
39 | fi | ||
40 | } | ||
41 | |||
42 | updatercd_prerm() { | ||
43 | if [ -z "$D" ]; then | ||
44 | ${INIT_D_DIR}/${INITSCRIPT_NAME} stop | ||
45 | fi | ||
46 | } | ||
47 | |||
48 | updatercd_postrm() { | ||
49 | if type update-rc.d >/dev/null 2>/dev/null; then | ||
50 | if [ -n "$D" ]; then | ||
51 | OPT="-r $D" | ||
52 | else | ||
53 | OPT="" | ||
54 | fi | ||
55 | update-rc.d $OPT ${INITSCRIPT_NAME} remove | ||
56 | fi | ||
57 | } | ||
58 | |||
59 | |||
60 | def update_rc_after_parse(d): | ||
61 | if d.getVar('INITSCRIPT_PACKAGES') == None: | ||
62 | if d.getVar('INITSCRIPT_NAME') == None: | ||
63 | raise bb.build.FuncFailed("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE')) | ||
64 | if d.getVar('INITSCRIPT_PARAMS') == None: | ||
65 | raise bb.build.FuncFailed("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE')) | ||
66 | |||
67 | python __anonymous() { | ||
68 | update_rc_after_parse(d) | ||
69 | } | ||
70 | |||
71 | PACKAGESPLITFUNCS_prepend = "populate_packages_updatercd " | ||
72 | PACKAGESPLITFUNCS_remove_class-nativesdk = "populate_packages_updatercd " | ||
73 | |||
74 | populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_preinst updatercd_postinst" | ||
75 | populate_packages_updatercd[vardepsexclude] += "OVERRIDES" | ||
76 | |||
77 | python populate_packages_updatercd () { | ||
78 | def update_rcd_auto_depend(pkg): | ||
79 | import subprocess | ||
80 | import os | ||
81 | path = d.expand("${D}${INIT_D_DIR}/${INITSCRIPT_NAME}") | ||
82 | if not os.path.exists(path): | ||
83 | return | ||
84 | statement = "grep -q -w '/etc/init.d/functions' %s" % path | ||
85 | if subprocess.call(statement, shell=True) == 0: | ||
86 | mlprefix = d.getVar('MLPREFIX', True) or "" | ||
87 | d.appendVar('RDEPENDS_' + pkg, ' %sinitscripts-functions' % (mlprefix)) | ||
88 | |||
89 | def update_rcd_package(pkg): | ||
90 | bb.debug(1, 'adding update-rc.d calls to preinst/postinst/prerm/postrm for %s' % pkg) | ||
91 | |||
92 | localdata = bb.data.createCopy(d) | ||
93 | overrides = localdata.getVar("OVERRIDES", True) | ||
94 | localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides)) | ||
95 | bb.data.update_data(localdata) | ||
96 | |||
97 | update_rcd_auto_depend(pkg) | ||
98 | |||
99 | preinst = d.getVar('pkg_preinst_%s' % pkg, True) | ||
100 | if not preinst: | ||
101 | preinst = '#!/bin/sh\n' | ||
102 | preinst += localdata.getVar('updatercd_preinst', True) | ||
103 | d.setVar('pkg_preinst_%s' % pkg, preinst) | ||
104 | |||
105 | postinst = d.getVar('pkg_postinst_%s' % pkg, True) | ||
106 | if not postinst: | ||
107 | postinst = '#!/bin/sh\n' | ||
108 | postinst += localdata.getVar('updatercd_postinst', True) | ||
109 | d.setVar('pkg_postinst_%s' % pkg, postinst) | ||
110 | |||
111 | prerm = d.getVar('pkg_prerm_%s' % pkg, True) | ||
112 | if not prerm: | ||
113 | prerm = '#!/bin/sh\n' | ||
114 | prerm += localdata.getVar('updatercd_prerm', True) | ||
115 | d.setVar('pkg_prerm_%s' % pkg, prerm) | ||
116 | |||
117 | postrm = d.getVar('pkg_postrm_%s' % pkg, True) | ||
118 | if not postrm: | ||
119 | postrm = '#!/bin/sh\n' | ||
120 | postrm += localdata.getVar('updatercd_postrm', True) | ||
121 | d.setVar('pkg_postrm_%s' % pkg, postrm) | ||
122 | |||
123 | # Check that this class isn't being inhibited (generally, by | ||
124 | # systemd.bbclass) before doing any work. | ||
125 | if bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d) or \ | ||
126 | not d.getVar("INHIBIT_UPDATERCD_BBCLASS", True): | ||
127 | pkgs = d.getVar('INITSCRIPT_PACKAGES', True) | ||
128 | if pkgs == None: | ||
129 | pkgs = d.getVar('UPDATERCPN', True) | ||
130 | packages = (d.getVar('PACKAGES', True) or "").split() | ||
131 | if not pkgs in packages and packages != []: | ||
132 | pkgs = packages[0] | ||
133 | for pkg in pkgs.split(): | ||
134 | update_rcd_package(pkg) | ||
135 | } | ||