blob: 73a4875df1fdd72232ebbdada890e14263d83f65 [file] [log] [blame]
Ratan Gupta653779c2016-10-01 14:57:15 -05001inherit obmc-phosphor-utils
2DISCOVERY_SVC_PACKAGES ?= "${PN}"
3
4python() {
5 avahi_enabled = bb.utils.contains(
6 'DISTRO_FEATURES', 'avahi', 'true', 'false', d)
Ratan96da4892016-11-17 16:06:21 +05307 slp_enabled = bb.utils.contains(
8 'DISTRO_FEATURES', 'slp', 'true', 'false', d)
9
Ratan Gupta653779c2016-10-01 14:57:15 -050010
11 if not avahi_enabled and slp_enabled:
12 return
13
14 syscnfdir = d.getVar('sysconfdir', True)
15 dest_dir = d.getVar('D', True)
Ratan96da4892016-11-17 16:06:21 +053016
Ratan Gupta653779c2016-10-01 14:57:15 -050017 set_append(d, 'AVAHI_SERVICES_DIR', os.path.join(
18 dest_dir+syscnfdir,
19 'avahi',
20 'services'))
Ratan96da4892016-11-17 16:06:21 +053021 set_append(d, 'SLP_SERVICES_DIR', os.path.join(
22 dest_dir+syscnfdir,
23 'slp',
24 'services'))
25
Ratan Gupta653779c2016-10-01 14:57:15 -050026
27 for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'):
28 for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg):
29 if avahi_enabled:
30 set_append(d, 'RRECOMMENDS_%s' % pkg, 'avahi-daemon')
31 svc_name, svc_type, svc_port = service.split(':')
32 set_append(d, 'FILES_%s' % pkg, os.path.join(
33 syscnfdir,
34 'avahi',
35 'services',
36 '%s.service' % svc_name))
Ratan96da4892016-11-17 16:06:21 +053037
38 if slp_enabled:
39 set_append(d, 'RRECOMMENDS_%s' % pkg, 'slpd-lite')
40 svc_name, svc_type, svc_port = service.split(':')
41 set_append(d, 'FILES_%s' % pkg, os.path.join(
42 syscnfdir,
43 'slp',
44 'services',
45 '%s.service' % svc_name))
46
Ratan Gupta653779c2016-10-01 14:57:15 -050047}
48
49python discovery_services_postinstall() {
50 avahi_enabled = bb.utils.contains(
51 'DISTRO_FEATURES', 'avahi', 'true', 'false', d)
Ratan96da4892016-11-17 16:06:21 +053052 slp_enabled = bb.utils.contains(
53 'DISTRO_FEATURES', 'slp', 'true', 'false', d)
Ratan Gupta653779c2016-10-01 14:57:15 -050054
55 if not avahi_enabled and slp_enabled:
56 return
57
Ratan Guptabd3705f2017-05-29 19:33:21 +053058 avahi_service_dir = d.getVar('AVAHI_SERVICES_DIR', True).strip()
59 slp_service_dir = d.getVar('SLP_SERVICES_DIR', True).strip()
Ratan Gupta653779c2016-10-01 14:57:15 -050060
Ratan96da4892016-11-17 16:06:21 +053061 if not os.path.exists(avahi_service_dir):
62 os.makedirs(avahi_service_dir)
63
64 if not os.path.exists(slp_service_dir):
65 os.makedirs(slp_service_dir)
Ratan Gupta653779c2016-10-01 14:57:15 -050066
67 def register_service_avahi(d, service_name, service_type, service_port):
68 service_file = os.path.join(
Ratan96da4892016-11-17 16:06:21 +053069 avahi_service_dir,
Ratan Gupta653779c2016-10-01 14:57:15 -050070 '%s.service' % service_name)
71 with open(service_file, 'w') as fd:
72 fd.write('<?xml version="1.0" ?>\n')
73 fd.write('<!DOCTYPE service-group SYSTEM "avahi-service.dtd">\n')
74 fd.write('<service-group>\n')
Ratan Gupta04fe31f2016-10-07 06:55:00 -050075 fd.write(' <name>%s</name>\n' % service_name)
Ratan Gupta653779c2016-10-01 14:57:15 -050076 fd.write(' <service>\n')
Ratan Gupta04fe31f2016-10-07 06:55:00 -050077 fd.write(' <type>%s</type>\n' % service_type)
78 fd.write(' <port>%s</port>\n' % service_port)
Ratan Gupta653779c2016-10-01 14:57:15 -050079 fd.write(' </service>\n')
80 fd.write('</service-group>\n')
81
Ratan96da4892016-11-17 16:06:21 +053082
83 def register_service_slp(d, service_name, service_type, service_port):
84 service_file = os.path.join(
85 slp_service_dir,
86 '%s.service' % service_name)
87 with open(service_file, 'w') as fd:
88 fd.write('%s %s %s' % (service_name, service_type, service_port))
89
Ratan Gupta653779c2016-10-01 14:57:15 -050090 def register_services(d,pkg):
91 for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg):
92 svc_info = service.split(":")
93 try:
94 svc_name, svc_type, svc_port = svc_info
Ratan Gupta653779c2016-10-01 14:57:15 -050095 except:
96 continue
97 if avahi_enabled:
Ratan96da4892016-11-17 16:06:21 +053098 avahi_svc_type = "_" + svc_name + "._" + svc_type
99 register_service_avahi(d, svc_name, avahi_svc_type, svc_port)
100 if slp_enabled:
101 register_service_slp(d, svc_name, svc_type, svc_port)
Ratan Gupta653779c2016-10-01 14:57:15 -0500102
103 for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'):
104 register_services(d, pkg)
105
106}
107do_install[postfuncs] += "discovery_services_postinstall"