blob: 9b66e7ea91314facbed7b7287f39fcbb419ab752 [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)
Ratan269c5e02016-11-17 16:06:21 +05307 slp_enabled = bb.utils.contains(
8 'DISTRO_FEATURES', 'slp', 'true', 'false', d)
9
Ratan Guptadf7dfd42016-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)
Ratan269c5e02016-11-17 16:06:21 +053016
Ratan Guptadf7dfd42016-10-01 14:57:15 -050017 set_append(d, 'AVAHI_SERVICES_DIR', os.path.join(
18 dest_dir+syscnfdir,
19 'avahi',
20 'services'))
Ratan269c5e02016-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 Guptadf7dfd42016-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))
Ratan269c5e02016-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 Guptadf7dfd42016-10-01 14:57:15 -050047}
48
49python discovery_services_postinstall() {
50 avahi_enabled = bb.utils.contains(
51 'DISTRO_FEATURES', 'avahi', 'true', 'false', d)
Ratan269c5e02016-11-17 16:06:21 +053052 slp_enabled = bb.utils.contains(
53 'DISTRO_FEATURES', 'slp', 'true', 'false', d)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050054
55 if not avahi_enabled and slp_enabled:
56 return
57
Ratan269c5e02016-11-17 16:06:21 +053058 avahi_service_dir = d.getVar('AVAHI_SERVICES_DIR', True)
59 slp_service_dir = d.getVar('SLP_SERVICES_DIR', True)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050060
Ratan269c5e02016-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 Guptadf7dfd42016-10-01 14:57:15 -050066
67 def register_service_avahi(d, service_name, service_type, service_port):
68 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')
Ratan Guptae0501bc2016-10-07 06:55:00 -050075 fd.write(' <name>%s</name>\n' % service_name)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050076 fd.write(' <service>\n')
Ratan Guptae0501bc2016-10-07 06:55:00 -050077 fd.write(' <type>%s</type>\n' % service_type)
78 fd.write(' <port>%s</port>\n' % service_port)
Ratan Guptadf7dfd42016-10-01 14:57:15 -050079 fd.write(' </service>\n')
80 fd.write('</service-group>\n')
81
Ratan269c5e02016-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 Guptadf7dfd42016-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 Guptadf7dfd42016-10-01 14:57:15 -050095 except:
96 continue
97 if avahi_enabled:
Ratan269c5e02016-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 Guptadf7dfd42016-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"