blob: 18df2dc3f2f135df443dcebf7608eaf1e71c8d5b [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() {
Brad Bishop37a0e4d2017-12-04 01:01:44 -050029# Begin section update-rc.d
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030if 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
Brad Bishop37a0e4d2017-12-04 01:01:44 -050038# End section update-rc.d
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039}
40
41updatercd_prerm() {
Brad Bishop37a0e4d2017-12-04 01:01:44 -050042# Begin section update-rc.d
Patrick Williamsc0f7c042017-02-23 20:41:17 -060043if [ -z "$D" -a -x "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
44 ${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045fi
Brad Bishop37a0e4d2017-12-04 01:01:44 -050046# End section update-rc.d
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047}
48
49updatercd_postrm() {
50if type update-rc.d >/dev/null 2>/dev/null; then
51 if [ -n "$D" ]; then
52 OPT="-f -r $D"
53 else
54 OPT="-f"
55 fi
56 update-rc.d $OPT ${INITSCRIPT_NAME} remove
57fi
58}
59
60
61def update_rc_after_parse(d):
62 if d.getVar('INITSCRIPT_PACKAGES', False) == None:
63 if d.getVar('INITSCRIPT_NAME', False) == None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060064 bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE', False))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 if d.getVar('INITSCRIPT_PARAMS', False) == None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060066 bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE', False))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067
68python __anonymous() {
69 update_rc_after_parse(d)
70}
71
Patrick Williamsc0f7c042017-02-23 20:41:17 -060072PACKAGESPLITFUNCS_prepend = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'populate_packages_updatercd ', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073PACKAGESPLITFUNCS_remove_class-nativesdk = "populate_packages_updatercd "
74
75populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_preinst updatercd_postinst"
76populate_packages_updatercd[vardepsexclude] += "OVERRIDES"
77
78python populate_packages_updatercd () {
79 def update_rcd_auto_depend(pkg):
80 import subprocess
81 import os
82 path = d.expand("${D}${INIT_D_DIR}/${INITSCRIPT_NAME}")
83 if not os.path.exists(path):
84 return
85 statement = "grep -q -w '/etc/init.d/functions' %s" % path
86 if subprocess.call(statement, shell=True) == 0:
87 mlprefix = d.getVar('MLPREFIX', True) or ""
88 d.appendVar('RDEPENDS_' + pkg, ' %sinitscripts-functions' % (mlprefix))
89
90 def update_rcd_package(pkg):
91 bb.debug(1, 'adding update-rc.d calls to preinst/postinst/prerm/postrm for %s' % pkg)
92
93 localdata = bb.data.createCopy(d)
94 overrides = localdata.getVar("OVERRIDES", True)
95 localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides))
96 bb.data.update_data(localdata)
97
98 update_rcd_auto_depend(pkg)
99
100 preinst = d.getVar('pkg_preinst_%s' % pkg, True)
101 if not preinst:
102 preinst = '#!/bin/sh\n'
103 preinst += localdata.getVar('updatercd_preinst', True)
104 d.setVar('pkg_preinst_%s' % pkg, preinst)
105
106 postinst = d.getVar('pkg_postinst_%s' % pkg, True)
107 if not postinst:
108 postinst = '#!/bin/sh\n'
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500109 postinst = postinst.splitlines(True)
110 try:
111 index = postinst.index('# End section update-alternatives\n')
112 postinst.insert(index + 1, localdata.getVar('updatercd_postinst', True))
113 except ValueError:
114 postinst.append(localdata.getVar('updatercd_postinst', True))
115 postinst = ''.join(postinst)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 d.setVar('pkg_postinst_%s' % pkg, postinst)
117
118 prerm = d.getVar('pkg_prerm_%s' % pkg, True)
119 if not prerm:
120 prerm = '#!/bin/sh\n'
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500121 prerm = prerm.splitlines(True)
122 try:
123 index = prerm.index('# Begin section update-alternatives\n')
124 prerm.insert(index, localdata.getVar('updatercd_prerm', True))
125 except ValueError:
126 prerm.append(localdata.getVar('updatercd_prerm', True))
127 prerm = ''.join(prerm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 d.setVar('pkg_prerm_%s' % pkg, prerm)
129
130 postrm = d.getVar('pkg_postrm_%s' % pkg, True)
131 if not postrm:
132 postrm = '#!/bin/sh\n'
133 postrm += localdata.getVar('updatercd_postrm', True)
134 d.setVar('pkg_postrm_%s' % pkg, postrm)
135
136 d.appendVar('RRECOMMENDS_' + pkg, " ${MLPREFIX}${UPDATERCD}")
137
138 # Check that this class isn't being inhibited (generally, by
139 # systemd.bbclass) before doing any work.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600140 if not d.getVar("INHIBIT_UPDATERCD_BBCLASS", True):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141 pkgs = d.getVar('INITSCRIPT_PACKAGES', True)
142 if pkgs == None:
143 pkgs = d.getVar('UPDATERCPN', True)
144 packages = (d.getVar('PACKAGES', True) or "").split()
145 if not pkgs in packages and packages != []:
146 pkgs = packages[0]
147 for pkg in pkgs.split():
148 update_rcd_package(pkg)
149}