Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 1 | inherit obmc-phosphor-utils |
| 2 | DISCOVERY_SVC_PACKAGES ?= "${PN}" |
| 3 | |
| 4 | python() { |
| 5 | avahi_enabled = bb.utils.contains( |
Ratan Gupta | 37855b2 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 6 | 'DISTRO_FEATURES', 'avahi', True, False, d) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 7 | slp_enabled = bb.utils.contains( |
Ratan Gupta | 37855b2 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 8 | 'DISTRO_FEATURES', 'slp', True, False, d) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 9 | |
Ratan Gupta | 37855b2 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 10 | if not avahi_enabled and not slp_enabled: |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 11 | return |
| 12 | |
| 13 | syscnfdir = d.getVar('sysconfdir', True) |
| 14 | dest_dir = d.getVar('D', True) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 15 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 16 | set_append(d, 'AVAHI_SERVICES_DIR', os.path.join( |
| 17 | dest_dir+syscnfdir, |
| 18 | 'avahi', |
| 19 | 'services')) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 20 | set_append(d, 'SLP_SERVICES_DIR', os.path.join( |
| 21 | dest_dir+syscnfdir, |
| 22 | 'slp', |
| 23 | 'services')) |
| 24 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 25 | |
| 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') |
asmithakarun | 2d6aedf | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 30 | svc_name, svc_type, svc_port, svc_txt_data = service.split(':') |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 31 | set_append(d, 'FILES_%s' % pkg, os.path.join( |
| 32 | syscnfdir, |
| 33 | 'avahi', |
| 34 | 'services', |
| 35 | '%s.service' % svc_name)) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 36 | |
| 37 | if slp_enabled: |
| 38 | set_append(d, 'RRECOMMENDS_%s' % pkg, 'slpd-lite') |
asmithakarun | 2d6aedf | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 39 | svc_name, svc_type, svc_port, svc_txt_data = service.split(':') |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 40 | set_append(d, 'FILES_%s' % pkg, os.path.join( |
| 41 | syscnfdir, |
| 42 | 'slp', |
| 43 | 'services', |
| 44 | '%s.service' % svc_name)) |
| 45 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | python discovery_services_postinstall() { |
| 49 | avahi_enabled = bb.utils.contains( |
Ratan Gupta | 37855b2 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 50 | 'DISTRO_FEATURES', 'avahi', True, False, d) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 51 | slp_enabled = bb.utils.contains( |
Ratan Gupta | 37855b2 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 52 | 'DISTRO_FEATURES', 'slp', True, False, d) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 53 | |
Ratan Gupta | 37855b2 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 54 | if not avahi_enabled and not slp_enabled: |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 55 | return |
| 56 | |
Ratan Gupta | bd3705f | 2017-05-29 19:33:21 +0530 | [diff] [blame] | 57 | avahi_service_dir = d.getVar('AVAHI_SERVICES_DIR', True).strip() |
| 58 | slp_service_dir = d.getVar('SLP_SERVICES_DIR', True).strip() |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 59 | |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 60 | 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 Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 65 | |
asmithakarun | 2d6aedf | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 66 | def register_service_avahi(d, service_name, service_type, service_port, service_txt_data): |
| 67 | service_txt_data = service_txt_data.split('|') |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 68 | service_file = os.path.join( |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 69 | avahi_service_dir, |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 70 | '%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 Kerr | d4e212e | 2020-09-03 18:04:56 +0800 | [diff] [blame] | 75 | fd.write(' <name replace-wildcards="yes">%s on %%h</name>\n' |
| 76 | % service_name) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 77 | fd.write(' <service>\n') |
Ratan Gupta | 04fe31f | 2016-10-07 06:55:00 -0500 | [diff] [blame] | 78 | fd.write(' <type>%s</type>\n' % service_type) |
| 79 | fd.write(' <port>%s</port>\n' % service_port) |
asmithakarun | 2d6aedf | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 80 | 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 Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 87 | fd.write(' </service>\n') |
| 88 | fd.write('</service-group>\n') |
| 89 | |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 90 | 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 Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 97 | def register_services(d,pkg): |
| 98 | for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg): |
| 99 | svc_info = service.split(":") |
| 100 | try: |
asmithakarun | 2d6aedf | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 101 | svc_name, svc_type, svc_port, svc_txt_data = svc_info |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 102 | except: |
| 103 | continue |
| 104 | if avahi_enabled: |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 105 | avahi_svc_type = "_" + svc_name + "._" + svc_type |
asmithakarun | 2d6aedf | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 106 | register_service_avahi(d, svc_name, avahi_svc_type, svc_port, svc_txt_data) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 107 | if slp_enabled: |
| 108 | register_service_slp(d, svc_name, svc_type, svc_port) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 109 | |
| 110 | for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'): |
| 111 | register_services(d, pkg) |
| 112 | |
| 113 | } |
| 114 | do_install[postfuncs] += "discovery_services_postinstall" |