blob: 4afd9e0bd5948145958aa4da1a3024319077b55f [file] [log] [blame]
Ratan Guptadf7dfd42016-10-01 14:57:15 -05001inherit obmc-phosphor-utils
2DISCOVERY_SVC_PACKAGES ?= "${PN}"
3
4python() {
5 avahi_enabled = bb.utils.contains(
Ratan Gupta9274d012017-12-06 18:21:37 +05306 'DISTRO_FEATURES', 'avahi', True, False, d)
Ratan269c5e02016-11-17 16:06:21 +05307 slp_enabled = bb.utils.contains(
Ratan Gupta9274d012017-12-06 18:21:37 +05308 'DISTRO_FEATURES', 'slp', True, False, d)
Ratan269c5e02016-11-17 16:06:21 +05309
Ratan Gupta9274d012017-12-06 18:21:37 +053010 if not avahi_enabled and not slp_enabled:
Ratan Guptadf7dfd42016-10-01 14:57:15 -050011 return
12
13 syscnfdir = d.getVar('sysconfdir', True)
14 dest_dir = d.getVar('D', True)
Ratan269c5e02016-11-17 16:06:21 +053015
Patrick Williams12fc9392021-08-06 09:16:53 -050016 set_doappend(d, 'AVAHI_SERVICES_DIR', os.path.join(
Ratan Guptadf7dfd42016-10-01 14:57:15 -050017 dest_dir+syscnfdir,
18 'avahi',
19 'services'))
Patrick Williams12fc9392021-08-06 09:16:53 -050020 set_doappend(d, 'SLP_SERVICES_DIR', os.path.join(
Ratan269c5e02016-11-17 16:06:21 +053021 dest_dir+syscnfdir,
22 'slp',
23 'services'))
24
Ratan Guptadf7dfd42016-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:
Patrick Williams12fc9392021-08-06 09:16:53 -050029 set_doappend(d, 'RRECOMMENDS:%s' % pkg, 'avahi-daemon')
asmithakarunee903932019-06-24 05:28:05 -050030 svc_name, svc_type, svc_port, svc_txt_data = service.split(':')
Patrick Williams12fc9392021-08-06 09:16:53 -050031 set_doappend(d, 'FILES:%s' % pkg, os.path.join(
Ratan Guptadf7dfd42016-10-01 14:57:15 -050032 syscnfdir,
33 'avahi',
34 'services',
35 '%s.service' % svc_name))
Ratan269c5e02016-11-17 16:06:21 +053036
37 if slp_enabled:
Patrick Williams12fc9392021-08-06 09:16:53 -050038 set_doappend(d, 'RRECOMMENDS:%s' % pkg, 'slpd-lite')
asmithakarunee903932019-06-24 05:28:05 -050039 svc_name, svc_type, svc_port, svc_txt_data = service.split(':')
Patrick Williams12fc9392021-08-06 09:16:53 -050040 set_doappend(d, 'FILES:%s' % pkg, os.path.join(
Ratan269c5e02016-11-17 16:06:21 +053041 syscnfdir,
42 'slp',
43 'services',
44 '%s.service' % svc_name))
45
Ratan Guptadf7dfd42016-10-01 14:57:15 -050046}
47
48python discovery_services_postinstall() {
49 avahi_enabled = bb.utils.contains(
Ratan Gupta9274d012017-12-06 18:21:37 +053050 'DISTRO_FEATURES', 'avahi', True, False, d)
Ratan269c5e02016-11-17 16:06:21 +053051 slp_enabled = bb.utils.contains(
Ratan Gupta9274d012017-12-06 18:21:37 +053052 'DISTRO_FEATURES', 'slp', True, False, d)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050053
Ratan Gupta9274d012017-12-06 18:21:37 +053054 if not avahi_enabled and not slp_enabled:
Ratan Guptadf7dfd42016-10-01 14:57:15 -050055 return
56
Ratan Guptafb9ac662017-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 Guptadf7dfd42016-10-01 14:57:15 -050059
Ratan269c5e02016-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 Guptadf7dfd42016-10-01 14:57:15 -050065
asmithakarunee903932019-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 Guptadf7dfd42016-10-01 14:57:15 -050068 service_file = os.path.join(
Ratan269c5e02016-11-17 16:06:21 +053069 avahi_service_dir,
Ratan Guptadf7dfd42016-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')
Jeremy Kerrd8952bd2020-09-03 18:04:56 +080075 fd.write(' <name replace-wildcards="yes">%s on %%h</name>\n'
Patrick Williams9129b242020-10-15 10:03:35 -050076 % service_name)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050077 fd.write(' <service>\n')
Ratan Guptae0501bc2016-10-07 06:55:00 -050078 fd.write(' <type>%s</type>\n' % service_type)
79 fd.write(' <port>%s</port>\n' % service_port)
asmithakarunee903932019-06-24 05:28:05 -050080 for txt_record in service_txt_data:
81 if txt_record:
82 key, value = txt_record.split('=')
83 if key.strip() and value.strip():
84 fd.write(' <txt-record>%s</txt-record>\n' % txt_record)
85 else:
86 bb.fatal('Invalid Additional data : \'%s\'. Ignoring!' % txt_record)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050087 fd.write(' </service>\n')
88 fd.write('</service-group>\n')
89
Ratan269c5e02016-11-17 16:06:21 +053090 def register_service_slp(d, service_name, service_type, service_port):
91 service_file = os.path.join(
92 slp_service_dir,
93 '%s.service' % service_name)
94 with open(service_file, 'w') as fd:
95 fd.write('%s %s %s' % (service_name, service_type, service_port))
96
Ratan Guptadf7dfd42016-10-01 14:57:15 -050097 def register_services(d,pkg):
98 for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg):
99 svc_info = service.split(":")
100 try:
asmithakarunee903932019-06-24 05:28:05 -0500101 svc_name, svc_type, svc_port, svc_txt_data = svc_info
Ratan Guptadf7dfd42016-10-01 14:57:15 -0500102 except:
103 continue
104 if avahi_enabled:
Ratan269c5e02016-11-17 16:06:21 +0530105 avahi_svc_type = "_" + svc_name + "._" + svc_type
asmithakarunee903932019-06-24 05:28:05 -0500106 register_service_avahi(d, svc_name, avahi_svc_type, svc_port, svc_txt_data)
Ratan269c5e02016-11-17 16:06:21 +0530107 if slp_enabled:
108 register_service_slp(d, svc_name, svc_type, svc_port)
Ratan Guptadf7dfd42016-10-01 14:57:15 -0500109
110 for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'):
111 register_services(d, pkg)
112
113}
114do_install[postfuncs] += "discovery_services_postinstall"