Ratan Gupta | df7dfd4 | 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 | 9274d01 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 6 | 'DISTRO_FEATURES', 'avahi', True, False, d) |
Ratan | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 7 | slp_enabled = bb.utils.contains( |
Ratan Gupta | 9274d01 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 8 | 'DISTRO_FEATURES', 'slp', True, False, d) |
Ratan | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 9 | |
Ratan Gupta | 9274d01 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 10 | if not avahi_enabled and not slp_enabled: |
Ratan Gupta | df7dfd4 | 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 | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 15 | |
Ratan Gupta | df7dfd4 | 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 | 269c5e0 | 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 | df7dfd4 | 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 | ee90393 | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 30 | svc_name, svc_type, svc_port, svc_txt_data = service.split(':') |
Ratan Gupta | df7dfd4 | 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 | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 36 | |
| 37 | if slp_enabled: |
| 38 | set_append(d, 'RRECOMMENDS_%s' % pkg, 'slpd-lite') |
asmithakarun | ee90393 | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 39 | svc_name, svc_type, svc_port, svc_txt_data = service.split(':') |
Ratan | 269c5e0 | 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 | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | python discovery_services_postinstall() { |
| 49 | avahi_enabled = bb.utils.contains( |
Ratan Gupta | 9274d01 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 50 | 'DISTRO_FEATURES', 'avahi', True, False, d) |
Ratan | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 51 | slp_enabled = bb.utils.contains( |
Ratan Gupta | 9274d01 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 52 | 'DISTRO_FEATURES', 'slp', True, False, d) |
Ratan Gupta | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 53 | |
Ratan Gupta | 9274d01 | 2017-12-06 18:21:37 +0530 | [diff] [blame] | 54 | if not avahi_enabled and not slp_enabled: |
Ratan Gupta | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 55 | return |
| 56 | |
Ratan Gupta | fb9ac66 | 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 | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 59 | |
Ratan | 269c5e0 | 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 | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 65 | |
asmithakarun | ee90393 | 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 | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 68 | service_file = os.path.join( |
Ratan | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 69 | avahi_service_dir, |
Ratan Gupta | df7dfd4 | 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') |
Ratan Gupta | e0501bc | 2016-10-07 06:55:00 -0500 | [diff] [blame] | 75 | fd.write(' <name>%s</name>\n' % service_name) |
Ratan Gupta | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 76 | fd.write(' <service>\n') |
Ratan Gupta | e0501bc | 2016-10-07 06:55:00 -0500 | [diff] [blame] | 77 | fd.write(' <type>%s</type>\n' % service_type) |
| 78 | fd.write(' <port>%s</port>\n' % service_port) |
asmithakarun | ee90393 | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 79 | 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 Gupta | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 86 | fd.write(' </service>\n') |
| 87 | fd.write('</service-group>\n') |
| 88 | |
Ratan | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 89 | 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 Gupta | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 96 | def register_services(d,pkg): |
| 97 | for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg): |
| 98 | svc_info = service.split(":") |
| 99 | try: |
asmithakarun | ee90393 | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 100 | svc_name, svc_type, svc_port, svc_txt_data = svc_info |
Ratan Gupta | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 101 | except: |
| 102 | continue |
| 103 | if avahi_enabled: |
Ratan | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 104 | avahi_svc_type = "_" + svc_name + "._" + svc_type |
asmithakarun | ee90393 | 2019-06-24 05:28:05 -0500 | [diff] [blame] | 105 | register_service_avahi(d, svc_name, avahi_svc_type, svc_port, svc_txt_data) |
Ratan | 269c5e0 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 106 | if slp_enabled: |
| 107 | register_service_slp(d, svc_name, svc_type, svc_port) |
Ratan Gupta | df7dfd4 | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 108 | |
| 109 | for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'): |
| 110 | register_services(d, pkg) |
| 111 | |
| 112 | } |
| 113 | do_install[postfuncs] += "discovery_services_postinstall" |