2013-02-07 22:54:13 +00:00
|
|
|
UPDATERCPN ?= "${PN}"
|
|
|
|
|
2017-01-19 08:39:53 +00:00
|
|
|
DEPENDS_append_class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', ' update-rc.d initscripts', '', d)}"
|
2016-06-10 11:48:53 +00:00
|
|
|
|
2013-02-07 22:54:13 +00:00
|
|
|
UPDATERCD = "update-rc.d"
|
2014-02-12 12:11:34 +00:00
|
|
|
UPDATERCD_class-cross = ""
|
2013-02-07 22:54:13 +00:00
|
|
|
UPDATERCD_class-native = ""
|
|
|
|
UPDATERCD_class-nativesdk = ""
|
|
|
|
|
|
|
|
INITSCRIPT_PARAMS ?= "defaults"
|
|
|
|
|
|
|
|
INIT_D_DIR = "${sysconfdir}/init.d"
|
|
|
|
|
2016-11-30 12:27:28 +00:00
|
|
|
def use_updatercd(d):
|
|
|
|
# If the distro supports both sysvinit and systemd, and the current recipe
|
|
|
|
# supports systemd, only call update-rc.d on rootfs creation or if systemd
|
|
|
|
# is not running. That's because systemctl enable/disable will already call
|
|
|
|
# update-rc.d if it detects initscripts.
|
|
|
|
if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and bb.data.inherits_class('systemd', d):
|
|
|
|
return '[ -n "$D" -o ! -d /run/systemd/system ]'
|
|
|
|
return 'true'
|
|
|
|
|
2013-10-30 00:57:11 +00:00
|
|
|
updatercd_preinst() {
|
2016-11-30 12:27:28 +00:00
|
|
|
if ${@use_updatercd(d)} && [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
|
2016-10-11 12:43:28 +00:00
|
|
|
${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
|
2013-10-30 00:57:11 +00:00
|
|
|
fi
|
2016-11-30 12:27:28 +00:00
|
|
|
if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
|
2013-10-16 13:07:51 +00:00
|
|
|
if [ -n "$D" ]; then
|
2013-10-03 21:42:00 +00:00
|
|
|
OPT="-f -r $D"
|
|
|
|
else
|
|
|
|
OPT="-f"
|
|
|
|
fi
|
|
|
|
update-rc.d $OPT ${INITSCRIPT_NAME} remove
|
|
|
|
fi
|
2013-10-30 00:57:11 +00:00
|
|
|
}
|
2013-10-03 21:42:00 +00:00
|
|
|
|
2017-01-19 08:39:53 +00:00
|
|
|
PACKAGE_WRITE_DEPS += "update-rc.d-native"
|
|
|
|
|
2013-10-30 00:57:11 +00:00
|
|
|
updatercd_postinst() {
|
2016-12-20 09:47:45 +00:00
|
|
|
# Begin section update-rc.d
|
2016-11-30 12:27:28 +00:00
|
|
|
if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
|
2013-10-30 00:57:11 +00:00
|
|
|
if [ -n "$D" ]; then
|
|
|
|
OPT="-r $D"
|
|
|
|
else
|
|
|
|
OPT="-s"
|
|
|
|
fi
|
2013-03-05 11:57:00 +00:00
|
|
|
update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}
|
|
|
|
fi
|
2016-12-20 09:47:45 +00:00
|
|
|
# End section update-rc.d
|
2013-02-07 22:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updatercd_prerm() {
|
2016-12-20 09:47:45 +00:00
|
|
|
# Begin section update-rc.d
|
2016-11-30 12:27:28 +00:00
|
|
|
if ${@use_updatercd(d)} && [ -z "$D" -a -x "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
|
2016-10-11 12:43:28 +00:00
|
|
|
${INIT_D_DIR}/${INITSCRIPT_NAME} stop || :
|
2013-02-07 22:54:13 +00:00
|
|
|
fi
|
2016-12-20 09:47:45 +00:00
|
|
|
# End section update-rc.d
|
2013-02-07 22:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updatercd_postrm() {
|
2016-11-30 12:27:28 +00:00
|
|
|
if ${@use_updatercd(d)} && type update-rc.d >/dev/null 2>/dev/null; then
|
2013-10-30 00:57:11 +00:00
|
|
|
if [ -n "$D" ]; then
|
2015-02-17 02:08:14 +00:00
|
|
|
OPT="-f -r $D"
|
2013-10-30 00:57:11 +00:00
|
|
|
else
|
2015-02-17 02:08:14 +00:00
|
|
|
OPT="-f"
|
2013-10-30 00:57:11 +00:00
|
|
|
fi
|
2013-03-05 11:57:00 +00:00
|
|
|
update-rc.d $OPT ${INITSCRIPT_NAME} remove
|
2013-02-07 22:54:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def update_rc_after_parse(d):
|
2015-06-18 14:14:16 +00:00
|
|
|
if d.getVar('INITSCRIPT_PACKAGES', False) == None:
|
|
|
|
if d.getVar('INITSCRIPT_NAME', False) == None:
|
2016-10-01 02:46:59 +00:00
|
|
|
bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_NAME" % d.getVar('FILE', False))
|
2015-06-18 14:14:16 +00:00
|
|
|
if d.getVar('INITSCRIPT_PARAMS', False) == None:
|
2016-10-01 02:46:59 +00:00
|
|
|
bb.fatal("%s inherits update-rc.d but doesn't set INITSCRIPT_PARAMS" % d.getVar('FILE', False))
|
2013-02-07 22:54:13 +00:00
|
|
|
|
|
|
|
python __anonymous() {
|
|
|
|
update_rc_after_parse(d)
|
|
|
|
}
|
|
|
|
|
2016-06-10 11:48:53 +00:00
|
|
|
PACKAGESPLITFUNCS_prepend = "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'populate_packages_updatercd ', '', d)}"
|
2014-06-06 00:09:02 +00:00
|
|
|
PACKAGESPLITFUNCS_remove_class-nativesdk = "populate_packages_updatercd "
|
2013-02-07 22:54:13 +00:00
|
|
|
|
2013-10-30 00:57:11 +00:00
|
|
|
populate_packages_updatercd[vardeps] += "updatercd_prerm updatercd_postrm updatercd_preinst updatercd_postinst"
|
2014-09-23 19:00:31 +00:00
|
|
|
populate_packages_updatercd[vardepsexclude] += "OVERRIDES"
|
2013-10-04 11:29:08 +00:00
|
|
|
|
2013-02-07 22:54:13 +00:00
|
|
|
python populate_packages_updatercd () {
|
2014-01-23 12:12:35 +00:00
|
|
|
def update_rcd_auto_depend(pkg):
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
path = d.expand("${D}${INIT_D_DIR}/${INITSCRIPT_NAME}")
|
|
|
|
if not os.path.exists(path):
|
|
|
|
return
|
|
|
|
statement = "grep -q -w '/etc/init.d/functions' %s" % path
|
|
|
|
if subprocess.call(statement, shell=True) == 0:
|
2016-12-14 21:13:04 +00:00
|
|
|
mlprefix = d.getVar('MLPREFIX') or ""
|
2014-05-09 00:39:22 +00:00
|
|
|
d.appendVar('RDEPENDS_' + pkg, ' %sinitscripts-functions' % (mlprefix))
|
2014-01-23 12:12:35 +00:00
|
|
|
|
2013-02-07 22:54:13 +00:00
|
|
|
def update_rcd_package(pkg):
|
2013-10-30 00:57:11 +00:00
|
|
|
bb.debug(1, 'adding update-rc.d calls to preinst/postinst/prerm/postrm for %s' % pkg)
|
2013-04-10 10:21:33 +00:00
|
|
|
|
|
|
|
localdata = bb.data.createCopy(d)
|
2016-12-14 21:13:04 +00:00
|
|
|
overrides = localdata.getVar("OVERRIDES")
|
2013-04-10 10:21:33 +00:00
|
|
|
localdata.setVar("OVERRIDES", "%s:%s" % (pkg, overrides))
|
|
|
|
|
2014-01-23 12:12:35 +00:00
|
|
|
update_rcd_auto_depend(pkg)
|
|
|
|
|
2016-12-14 21:13:04 +00:00
|
|
|
preinst = d.getVar('pkg_preinst_%s' % pkg)
|
2013-10-30 00:57:11 +00:00
|
|
|
if not preinst:
|
|
|
|
preinst = '#!/bin/sh\n'
|
2016-12-14 21:13:04 +00:00
|
|
|
preinst += localdata.getVar('updatercd_preinst')
|
2013-10-30 00:57:11 +00:00
|
|
|
d.setVar('pkg_preinst_%s' % pkg, preinst)
|
|
|
|
|
2016-12-14 21:13:04 +00:00
|
|
|
postinst = d.getVar('pkg_postinst_%s' % pkg)
|
2013-02-07 22:54:13 +00:00
|
|
|
if not postinst:
|
|
|
|
postinst = '#!/bin/sh\n'
|
2016-12-20 09:47:45 +00:00
|
|
|
postinst = postinst.splitlines(True)
|
|
|
|
try:
|
|
|
|
index = postinst.index('# End section update-alternatives\n')
|
|
|
|
postinst.insert(index + 1, localdata.getVar('updatercd_postinst'))
|
|
|
|
except ValueError:
|
|
|
|
postinst.append(localdata.getVar('updatercd_postinst'))
|
|
|
|
postinst = ''.join(postinst)
|
2013-02-07 22:54:13 +00:00
|
|
|
d.setVar('pkg_postinst_%s' % pkg, postinst)
|
|
|
|
|
2016-12-14 21:13:04 +00:00
|
|
|
prerm = d.getVar('pkg_prerm_%s' % pkg)
|
2013-02-07 22:54:13 +00:00
|
|
|
if not prerm:
|
|
|
|
prerm = '#!/bin/sh\n'
|
2016-12-20 09:47:45 +00:00
|
|
|
prerm = prerm.splitlines(True)
|
|
|
|
try:
|
|
|
|
index = prerm.index('# Begin section update-alternatives\n')
|
|
|
|
prerm.insert(index, localdata.getVar('updatercd_prerm'))
|
|
|
|
except ValueError:
|
|
|
|
prerm.append(localdata.getVar('updatercd_prerm'))
|
|
|
|
prerm = ''.join(prerm)
|
2013-02-07 22:54:13 +00:00
|
|
|
d.setVar('pkg_prerm_%s' % pkg, prerm)
|
|
|
|
|
2016-12-14 21:13:04 +00:00
|
|
|
postrm = d.getVar('pkg_postrm_%s' % pkg)
|
2013-02-07 22:54:13 +00:00
|
|
|
if not postrm:
|
|
|
|
postrm = '#!/bin/sh\n'
|
2016-12-14 21:13:04 +00:00
|
|
|
postrm += localdata.getVar('updatercd_postrm')
|
2013-02-07 22:54:13 +00:00
|
|
|
d.setVar('pkg_postrm_%s' % pkg, postrm)
|
|
|
|
|
2015-06-10 03:15:37 +00:00
|
|
|
d.appendVar('RRECOMMENDS_' + pkg, " ${MLPREFIX}${UPDATERCD}")
|
2015-05-27 16:28:12 +00:00
|
|
|
|
2013-03-06 15:11:54 +00:00
|
|
|
# Check that this class isn't being inhibited (generally, by
|
|
|
|
# systemd.bbclass) before doing any work.
|
2016-12-14 21:13:04 +00:00
|
|
|
if not d.getVar("INHIBIT_UPDATERCD_BBCLASS"):
|
|
|
|
pkgs = d.getVar('INITSCRIPT_PACKAGES')
|
2013-02-08 22:43:16 +00:00
|
|
|
if pkgs == None:
|
2016-12-14 21:13:04 +00:00
|
|
|
pkgs = d.getVar('UPDATERCPN')
|
|
|
|
packages = (d.getVar('PACKAGES') or "").split()
|
2013-02-08 22:43:16 +00:00
|
|
|
if not pkgs in packages and packages != []:
|
|
|
|
pkgs = packages[0]
|
|
|
|
for pkg in pkgs.split():
|
|
|
|
update_rcd_package(pkg)
|
2013-02-07 22:54:13 +00:00
|
|
|
}
|