xinetd: create and install ${PN}-xinetd packages
[opendreambox.git] / meta-opendreambox / classes / xinetd.bbclass
1 #
2 # xinetd.bbclass
3 #
4
5 DEPENDS += "xinetd"
6
7 XINETD_PACKAGES ??= "${PN}-xinetd"
8
9 do_install_append() {
10         install -d ${D}${sysconfdir}/xinetd.d
11         for srcfile in ${WORKDIR}/*.xinetd.in; do
12                 dstfile=`basename $srcfile .xinetd.in`
13                 sed -e 's,@BINDIR@,${bindir},' \
14                     -e 's,@SBINDIR@,${sbindir},' \
15                     $srcfile > ${D}${sysconfdir}/xinetd.d/$dstfile
16                 chmod 644 ${D}${sysconfdir}/xinetd.d/$dstfile
17         done
18 }
19
20 xinetd_reload() {
21 [ -z "$D" ] && PID=`pidof xinetd` && kill -HUP $PID || true
22 }
23
24 def xinetd_after_parse(d):
25         def xinetd_create_package(pkg):
26                 packages = d.getVar('PACKAGES', True).split()
27                 if not pkg in packages:
28                         packages.insert(0, pkg)
29                         d.setVar('PACKAGES', ' '.join(packages))
30
31         bpn = d.getVar('BPN', 1)
32         if bpn + "-native" != d.getVar('PN', 1) and \
33            bpn + "-cross" != d.getVar('PN', 1) and \
34            bpn + "-nativesdk" != d.getVar('PN', 1):
35                 for pkg in d.getVar('XINETD_PACKAGES', True).split():
36                         xinetd_create_package(pkg)
37
38 python __anonymous() {
39         xinetd_after_parse(d)
40 }
41
42 python populate_packages_prepend () {
43         def xinetd_generate_package_scripts(pkg):
44                 bb.note('adding xinetd postinst and postrm scripts to %s' % pkg)
45
46                 postinst = d.getVar('pkg_postinst_%s' % pkg, True) or d.getVar('pkg_postinst', True)
47                 if not postinst:
48                         postinst = '#!/bin/sh\n'
49                 postinst += d.getVar('xinetd_reload', True)
50                 d.setVar('pkg_postinst_%s' % pkg, postinst)
51
52                 postrm = d.getVar('pkg_postrm_%s' % pkg, True) or d.getVar('pkg_postrm', True)
53                 if not postrm:
54                         postrm = '#!/bin/sh\n'
55                 postrm += d.getVar('xinetd_reload', True)
56                 d.setVar('pkg_postrm_%s' % pkg, postrm)
57
58         def xinetd_add_rdepends(pkg):
59                 bb.note("adding xinetd dependency to %s" % pkg)
60
61                 rdepends = (d.getVar('RDEPENDS_%s' % pkg, True) or "").split()
62                 if pkg.endswith('-xinetd'):
63                         basepkg = pkg[:-len('-xinetd')]
64                         if not basepkg in rdepends:
65                                 rdepends.append(basepkg)
66                 if not 'xinetd' in rdepends:
67                         rdepends.append('xinetd')
68                 d.setVar('RDEPENDS_%s' % pkg, ' '.join(rdepends))
69
70         def xinetd_add_rconflicts(pkg):
71                 bb.note("adding xinetd conflicts to %s" % pkg)
72
73                 if pkg.endswith('-xinetd'):
74                         rconflicts = (d.getVar('RCONFLICTS_%s' % pkg, True) or "").split()
75                         conflictpkg = pkg[:-len('-xinetd')] + '-systemd'
76                         if not conflictpkg in rconflicts:
77                                 rconflicts.append(conflictpkg)
78                         d.setVar('RCONFLICTS_%s' % pkg, ' '.join(rconflicts))
79
80         # run all modifications once when creating package
81         xinetd_dir = '%s/xinetd.d' % d.getVar('sysconfdir', True)
82         if os.path.exists('${D}' + xinetd_dir):
83                 for pkg in d.getVar('XINETD_PACKAGES', True).split():
84                         services = d.getVar('XINETD_SERVICE_%s' % pkg, True) or d.getVar('XINETD_SERVICE', True) or ""
85                         if services:
86                                 xinetd_generate_package_scripts(pkg)
87                                 xinetd_add_rdepends(pkg)
88                                 xinetd_add_rconflicts(pkg)
89
90                         for service in services.split():
91                                 file_append = '%s/%s' % (xinetd_dir, service)
92                                 if os.path.exists('${D}' + file_append):
93                                         var_name = 'FILES_%s' % pkg
94                                         files = (d.getVar(var_name, False) or "").split()
95                                         if file_append not in files:
96                                                 files.append(file_append)
97                                                 d.setVar(var_name, ' '.join(files))
98 }