From ece44ea4638a29b69cda908fee6241a857c63eea Mon Sep 17 00:00:00 2001 From: JamesDo-okta <86258006+JamesDo-okta@users.noreply.github.com> Date: Thu, 23 Feb 2023 00:14:17 -0800 Subject: [PATCH] handle err when detect amazon linux 2 platform Signed-off-by: James Do <86258006+JamesDo-okta@users.noreply.github.com> --- lib/train/platforms/detect/helpers/os_linux.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/train/platforms/detect/helpers/os_linux.rb b/lib/train/platforms/detect/helpers/os_linux.rb index 96a79a206..0862493d9 100644 --- a/lib/train/platforms/detect/helpers/os_linux.rb +++ b/lib/train/platforms/detect/helpers/os_linux.rb @@ -72,6 +72,17 @@ def lsb_release(content) } end + def amzn_release(content) + id = /^NAME=\s+(.+)$/.match(content) + release = /^PRETTY_NAME=\s+(.+)$/.match(content) + codename = /^CPE_NAME=\s+(.+)$/.match(content) + { + id: id.nil? ? nil : id[1], + release: release.nil? ? nil : release[1], + codename: codename.nil? ? nil : codename[1], + } + end + def read_linux_lsb return @lsb unless @lsb.empty? @@ -79,6 +90,8 @@ def read_linux_lsb @lsb = lsb_config(raw) elsif !(raw = unix_file_contents("/usr/bin/lsb-release")).nil? @lsb = lsb_release(raw) + elsif !(raw = unix_file_contents("/etc/os-release")).nil? + @lsb = amzn_release(raw) end end end