blob: e912beadc1f18274edf2e70d120e188bc36878aa [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(
Ratan Gupta37855b22017-12-06 18:21:37 +05306 'DISTRO_FEATURES', 'avahi', True, False, d)
Ratan96da4892016-11-17 16:06:21 +05307 slp_enabled = bb.utils.contains(
Ratan Gupta37855b22017-12-06 18:21:37 +05308 'DISTRO_FEATURES', 'slp', True, False, d)
Ratan96da4892016-11-17 16:06:21 +05309
Ratan Gupta37855b22017-12-06 18:21:37 +053010 if not avahi_enabled and not slp_enabled:
Ratan Gupta653779c2016-10-01 14:57:15 -050011 return
12
13 syscnfdir = d.getVar('sysconfdir', True)
14 dest_dir = d.getVar('D', True)
Ratan96da4892016-11-17 16:06:21 +053015
Ratan Gupta653779c2016-10-01 14:57:15 -050016 set_append(d, 'AVAHI_SERVICES_DIR', os.path.join(
17 dest_dir+syscnfdir,
18 'avahi',
19 'services'))
Ratan96da4892016-11-17 16:06:21 +053020 set_append(d, 'SLP_SERVICES_DIR', os.path.join(
21 dest_dir+syscnfdir,
22 'slp',
23 'services'))
24
Ratan Gupta653779c2016-10-01 14:57:15 -050025
26 for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'):
27 for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg):
28 if avahi_enabled:
29 set_append(d, 'RRECOMMENDS_%s' % pkg, 'avahi-daemon')
asmithakarun2d6aedf2019-06-24 05:28:05 -050030 svc_name, svc_type, svc_port, svc_txt_data = service.split(':')
Ratan Gupta653779c2016-10-01 14:57:15 -050031 set_append(d, 'FILES_%s' % pkg, os.path.join(
32 syscnfdir,
33 'avahi',
34 'services',
35 '%s.service' % svc_name))
Ratan96da4892016-11-17 16:06:21 +053036
37 if slp_enabled:
38 set_append(d, 'RRECOMMENDS_%s' % pkg, 'slpd-lite')
asmithakarun2d6aedf2019-06-24 05:28:05 -050039 svc_name, svc_type, svc_port, svc_txt_data = service.split(':')
Ratan96da4892016-11-17 16:06:21 +053040 set_append(d, 'FILES_%s' % pkg, os.path.join(
41 syscnfdir,
42 'slp',
43 'services',
44 '%s.service' % svc_name))
45
Ratan Gupta653779c2016-10-01 14:57:15 -050046}
47
48python discovery_services_postinstall() {
49 avahi_enabled = bb.utils.contains(
Ratan Gupta37855b22017-12-06 18:21:37 +053050 'DISTRO_FEATURES', 'avahi', True, False, d)
Ratan96da4892016-11-17 16:06:21 +053051 slp_enabled = bb.utils.contains(
Ratan Gupta37855b22017-12-06 18:21:37 +053052 'DISTRO_FEATURES', 'slp', True, False, d)
Ratan Gupta653779c2016-10-01 14:57:15 -050053
Ratan Gupta37855b22017-12-06 18:21:37 +053054 if not avahi_enabled and not slp_enabled:
Ratan Gupta653779c2016-10-01 14:57:15 -050055 return
56
Ratan Guptabd3705f2017-05-29 19:33:21 +053057 avahi_service_dir = d.getVar('AVAHI_SERVICES_DIR', True).strip()
58 slp_service_dir = d.getVar('SLP_SERVICES_DIR', True).strip()
Ratan Gupta653779c2016-10-01 14:57:15 -050059
Ratan96da4892016-11-17 16:06:21 +053060 if not os.path.exists(avahi_service_dir):
61 os.makedirs(avahi_service_dir)
62
63 if not os.path.exists(slp_service_dir):
64 os.makedirs(slp_service_dir)
Ratan Gupta653779c2016-10-01 14:57:15 -050065
asmithakarun2d6aedf2019-06-24 05:28:05 -050066 def register_service_avahi(d, service_name, service_type, service_port, service_txt_data):
67 service_txt_data = service_txt_data.split('|')
Ratan Gupta653779c2016-10-01 14:57:15 -050068 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)
asmithakarun2d6aedf2019-06-24 05:28:05 -050079 for txt_record in service_txt_data:
80 if txt_record:
81 key, value = txt_record.split('=')
82 if key.strip() and value.strip():
83 fd.write(' <txt-record>%s</txt-record>\n' % txt_record)
84 else:
85 bb.fatal('Invalid Additional data : \'%s\'. Ignoring!' % txt_record)
Ratan Gupta653779c2016-10-01 14:57:15 -050086 fd.write(' </service>\n')
87 fd.write('</service-group>\n')
88
Ratan96da4892016-11-17 16:06:21 +053089 def register_service_slp(d, service_name, service_type, service_port):
90 service_file = os.path.join(
91 slp_service_dir,
92 '%s.service' % service_name)
93 with open(service_file, 'w') as fd:
94 fd.write('%s %s %s' % (service_name, service_type, service_port))
95
Ratan Gupta653779c2016-10-01 14:57:15 -050096 def register_services(d,pkg):
97 for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg):
98 svc_info = service.split(":")
99 try:
asmithakarun2d6aedf2019-06-24 05:28:05 -0500100 svc_name, svc_type, svc_port, svc_txt_data = svc_info
Ratan Gupta653779c2016-10-01 14:57:15 -0500101 except:
102 continue
103 if avahi_enabled:
Ratan96da4892016-11-17 16:06:21 +0530104 avahi_svc_type = "_" + svc_name + "._" + svc_type
asmithakarun2d6aedf2019-06-24 05:28:05 -0500105 register_service_avahi(d, svc_name, avahi_svc_type, svc_port, svc_txt_data)
Ratan96da4892016-11-17 16:06:21 +0530106 if slp_enabled:
107 register_service_slp(d, svc_name, svc_type, svc_port)
Ratan Gupta653779c2016-10-01 14:57:15 -0500108
109 for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'):
110 register_services(d, pkg)
111
112}
113do_install[postfuncs] += "discovery_services_postinstall"