From 72a15268c604c9b2b980e2e7dcf66aa44b3cb4ba Mon Sep 17 00:00:00 2001 From: Vitalii Chulak Date: Mon, 25 Mar 2024 22:15:07 +0200 Subject: [PATCH] Support HCK installer as ISO Signed-off-by: Vitalii Chulak --- lib/engines/hckinstall/hckinstall.rb | 57 +++++++++++++------ lib/engines/hckinstall/kit.json | 1 - .../hckinstall/setup_scripts_helper.rb | 10 +++- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/lib/engines/hckinstall/hckinstall.rb b/lib/engines/hckinstall/hckinstall.rb index c6eced9c..534e2192 100644 --- a/lib/engines/hckinstall/hckinstall.rb +++ b/lib/engines/hckinstall/hckinstall.rb @@ -91,10 +91,10 @@ def init_config end def studio_platform(kit) - res = @kit_info + res = @kit_info['studio_platform'] @logger.info("Loading studio platform for kit: #{kit}") - @logger.fatal("Kit studio platform for kit #{kit} does not exist") unless res['studio_platform'] - res['studio_platform'] || raise(InvalidConfigFile, "Kit studio platform for kit #{kit} does not exist") + @logger.fatal("Kit studio platform for kit #{kit} does not exist") unless res + res || raise(InvalidConfigFile, "Kit studio platform for kit #{kit} does not exist") end def client_platform @@ -239,12 +239,11 @@ def run_first(studio:, client:) if studio prepare_studio_drives + iso_list = [@setup_studio_iso, @studio_iso_info['path']] + iso_list << @kit_path if @kit_is_iso vms << [ 'studio', - run_studio(scope, [ - @setup_studio_iso, - @studio_iso_info['path'] - ], keep_alive: false, snapshot: false) + run_studio(scope, iso_list, keep_alive: false, snapshot: false) ] end @@ -275,31 +274,54 @@ def run_second(client:) end def prepare_setup_scripts_config - kit_string = @platform['kit'] - kit_type = kit_string[0..2] - kit_version = '' - kit_type == 'HCK' || kit_version = kit_string[3..] + kit_type, kit_version = parse_kit_info config = { kit_type:, hlk_kit_ver: kit_version } - unless @kit_info['download_url'].nil? + @kit_path = find_kit(kit_type, kit_version) + + log_kit_status(@kit_path, kit_type, kit_version) + + unless @kit_info['download_url'].nil? || @kit_path download_kit_installer(@kit_info['download_url'], "#{kit_type}#{kit_version}", @hck_setup_scripts_path) end + @kit_is_iso = @kit_path.end_with?('.iso') + + @logger.info("HLK installer #{kit_type}#{kit_version} was found at #{@kit_path}") + + create_setup_scripts_config(@hck_setup_scripts_path, config) + end + + def parse_kit_info + kit_string = @platform['kit'] + kit_type = kit_string[0..2] + kit_version = kit_type == 'HCK' ? '' : kit_string[3..] + [kit_type, kit_version] + end + + def find_kit(kit_type, kit_version) installers = [ "#{@hck_setup_scripts_path}/Kits/#{kit_type}#{kit_version}Setup.exe", - "#{@hck_setup_scripts_path}/Kits/#{kit_type}#{kit_version}/#{kit_type}Setup.exe" + "#{@hck_setup_scripts_path}/Kits/#{kit_type}#{kit_version}/#{kit_type}Setup.exe", + "#{@hck_setup_scripts_path}/Kits/#{kit_type}#{kit_version}Setup.iso" ] - raise unless (file = installers.find { File.exist? _1 }) + return false unless (kit_path = installers.find { File.exist? _1 }) - @logger.info("HLK installer #{file} was found") + kit_path + end - create_setup_scripts_config(@hck_setup_scripts_path, config) + def log_kit_status(kit_presense, kit_type, kit_version) + if kit_presense + @logger.info("HLK installer #{kit_type}#{kit_version} already exists") + elsif @kit_info['download_url'].nil? + @logger.info('HLK installer download URL is not provided') + end end def product_key_xml(product_key) @@ -359,7 +381,8 @@ def prepare_studio_drives file_gsub(build_studio_answer_file_path(file), @hck_setup_scripts_path + "/#{file}", replacement_list) end - create_iso(@setup_studio_iso, [@hck_setup_scripts_path]) + + create_iso(@setup_studio_iso, [@hck_setup_scripts_path], @kit_is_iso ? ['Kits'] : []) @project.setup_manager.create_studio_image end diff --git a/lib/engines/hckinstall/kit.json b/lib/engines/hckinstall/kit.json index ac3f6386..5ae6bf78 100644 --- a/lib/engines/hckinstall/kit.json +++ b/lib/engines/hckinstall/kit.json @@ -70,4 +70,3 @@ "studio_platform": "Win2012R2x64" } } - diff --git a/lib/engines/hckinstall/setup_scripts_helper.rb b/lib/engines/hckinstall/setup_scripts_helper.rb index 8f311132..a9eebc86 100644 --- a/lib/engines/hckinstall/setup_scripts_helper.rb +++ b/lib/engines/hckinstall/setup_scripts_helper.rb @@ -25,7 +25,15 @@ def validate_setup_scripts_config(config) def download_kit_installer(url, kit, hck_setup_scripts_path) dw = Downloader.new(@logger) - dw.download(url, "#{hck_setup_scripts_path}/Kits/#{kit}Setup.exe") + kit_setup_path = "#{hck_setup_scripts_path}/Kits/#{kit}Setup" + temp_path = "#{kit_setup_path}.tmp" + + dw.download(url, temp_path) + + file_type = File.read(temp_path, 2) == 'MZ' ? 'exe' : 'iso' + + @kit_path = "#{kit_setup_path}.#{file_type}" + FileUtils.mv(temp_path, @kit_path) end def copy_extra_software(hck_setup_scripts_path, extra_software_path, sw_names)