blob: 8dc6fdc04d7f4a7d801a6d8fda7296aa30b80039 [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(
6 'DISTRO_FEATURES', 'avahi', 'true', 'false', d)
7 slp_enabled = False # later
8
9 if not avahi_enabled and slp_enabled:
10 return
11
12 syscnfdir = d.getVar('sysconfdir', True)
13 dest_dir = d.getVar('D', True)
14 set_append(d, 'AVAHI_SERVICES_DIR', os.path.join(
15 dest_dir+syscnfdir,
16 'avahi',
17 'services'))
18
19 for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'):
20 for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg):
21 if avahi_enabled:
22 set_append(d, 'RRECOMMENDS_%s' % pkg, 'avahi-daemon')
23 svc_name, svc_type, svc_port = service.split(':')
24 set_append(d, 'FILES_%s' % pkg, os.path.join(
25 syscnfdir,
26 'avahi',
27 'services',
28 '%s.service' % svc_name))
29}
30
31python discovery_services_postinstall() {
32 avahi_enabled = bb.utils.contains(
33 'DISTRO_FEATURES', 'avahi', 'true', 'false', d)
34 slp_enabled = False # later
35
36 if not avahi_enabled and slp_enabled:
37 return
38
39 service_dir = d.getVar('AVAHI_SERVICES_DIR', True)
40
41 if not os.path.exists(service_dir):
42 os.makedirs(service_dir)
43
44 def register_service_avahi(d, service_name, service_type, service_port):
45 service_file = os.path.join(
46 service_dir,
47 '%s.service' % service_name)
48 with open(service_file, 'w') as fd:
49 fd.write('<?xml version="1.0" ?>\n')
50 fd.write('<!DOCTYPE service-group SYSTEM "avahi-service.dtd">\n')
51 fd.write('<service-group>\n')
Ratan Guptae0501bc2016-10-07 06:55:00 -050052 fd.write(' <name>%s</name>\n' % service_name)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050053 fd.write(' <service>\n')
Ratan Guptae0501bc2016-10-07 06:55:00 -050054 fd.write(' <type>%s</type>\n' % service_type)
55 fd.write(' <port>%s</port>\n' % service_port)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050056 fd.write(' </service>\n')
57 fd.write('</service-group>\n')
58
59 def register_services(d,pkg):
60 for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg):
61 svc_info = service.split(":")
62 try:
63 svc_name, svc_type, svc_port = svc_info
64 svc_type = "_" + svc_name + "._" + svc_type
65 except:
66 continue
67 if avahi_enabled:
68 register_service_avahi(d, svc_name, svc_type, svc_port)
69
70 for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'):
71 register_services(d, pkg)
72
73}
74do_install[postfuncs] += "discovery_services_postinstall"
75
76