From b046a70a11ae142d8a29ff8b4c8630ba55ba08bb Mon Sep 17 00:00:00 2001 From: Prateek Singh Date: Wed, 19 Apr 2023 17:10:29 +0530 Subject: [PATCH 1/3] Add CLI setup file --- lib/rmt/cli/setup.rb | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/rmt/cli/setup.rb diff --git a/lib/rmt/cli/setup.rb b/lib/rmt/cli/setup.rb new file mode 100644 index 000000000..028d983d5 --- /dev/null +++ b/lib/rmt/cli/setup.rb @@ -0,0 +1,72 @@ +require 'yaml' +class RMT::CLI::Setup < RMT::CLI::Base + DESTINATION_PATH = '/etc/rmt.conf'.freeze + SOURCE_PATH = 'config/rmt.yml'.freeze + POSITIVE_FEEDBACK = %w[Y y].freeze + + no_commands do + def copy_conf_if_not_exists + if File.exist?(DESTINATION_PATH) + puts "File already exists at #{DESTINATION_PATH}." + else + puts "Copying file from #{SOURCE_PATH} to #{DESTINATION_PATH} as #{DESTINATION_PATH} does not exists" + FileUtils.cp(SOURCE_PATH, DESTINATION_PATH) + puts "File copied to #{DESTINATION_PATH}." + end + end + + def update_file(config_hash) + file_contents = File.read(DESTINATION_PATH) + file_data = YAML.load(file_contents) + file_data['scc']['username'] = config_hash[:scc_username] + file_data['scc']['password'] = config_hash[:scc_password] + file_data['database']['database'] = config_hash[:db_dbname] + file_data['database']['host'] = config_hash[:db_host] + file_data['database']['username'] = config_hash[:db_username] + file_data['database']['password'] = config_hash[:db_password] + File.write(DESTINATION_PATH, file_data.to_yaml) + end + end + + def start_setup + puts 'We are setting up system' + copy_conf_if_not_exists + loop do + input = ask("Press enter/return to continue, else type 'exit' for exiting the cli") + + case input + when 'exit' + break + else + config_hash = {} + config_hash[:scc_username] = ask('Enter SCC username, default is', default: 'root') + config_hash[:scc_password] = ask('Enter SCC password, default is ', default: 'example', echo: false) + puts "\n" + config_hash[:db_host] = ask('Enter database host, default is ', default: 'localhost') + config_hash[:db_username] = ask('Enter database username, default is ', default: 'rmt') + config_hash[:db_password] = ask('Enter database password, default is ', default: 'rmt', echo: false) + puts "\n" + config_hash[:db_dbname] = ask('Enter database dbname, default is ', default: 'rmt_development') + + verify_data = ask("You have entered following data:\n + scc_username: #{config_hash[:scc_username]}\n + scc_password: ****\n + db_host: #{config_hash[:db_host]}\n + db_username: #{config_hash[:db_username]}\n + db_password: ****\n + db_dbname: #{config_hash[:db_dbname]}\n + Enter Y(y) to continue else press enter/return to restart entering values: ") + if POSITIVE_FEEDBACK.include?(verify_data) + update_file(config_hash) + puts 'Config updated, server restart is required using ' + restart_rmt = ask('Do you wish to restart rmt server? (Enter Y(y) for yes else press enter to skip restart') + if POSITIVE_FEEDBACK.include?(restart_rmt) + puts 'Restarting Server....' + `systemctl restart rmt-server` + end + break + end + end + end + end +end From 130c8e93f06ebb0b7fecbf57d33979fc44e5ac36 Mon Sep 17 00:00:00 2001 From: Prateek Singh Date: Wed, 19 Apr 2023 17:12:05 +0530 Subject: [PATCH 2/3] Add method to start rmt-cli setup --- lib/rmt/cli/main.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/rmt/cli/main.rb b/lib/rmt/cli/main.rb index ffabfc87f..8bfe06009 100644 --- a/lib/rmt/cli/main.rb +++ b/lib/rmt/cli/main.rb @@ -33,6 +33,11 @@ def sync def version puts RMT::VERSION end + + desc 'setup', _('Configure RMT') + def setup + RMT::CLI::Setup.new.start_setup + end map %w[--version -v] => :version From d2ab223660c6a95c1f361ec712909356668b302e Mon Sep 17 00:00:00 2001 From: Prateek Singh Date: Wed, 19 Apr 2023 17:23:19 +0530 Subject: [PATCH 3/3] Update manual with rmt-cli setup command --- MANUAL.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MANUAL.md b/MANUAL.md index 7657852cf..d9f7ff9cc 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -25,6 +25,12 @@ You can install and run this wizard like this: * `rmt-cli sync`: RMT comes with a preconfigured systemd timer to automatically get the latest product and repository data from the SUSE Customer Center over night. This command triggers the same synchronization instantly. + + * `rmt-cli setup`: + As a part of the configuration of RMT, users can create and edit /etc/rmt.conf file to overwrite specific configurations for their need. + This requires manual work. + This command provides an interactive cli to the user to enter values such as SCC credentials, DB credentials and saves changes to /etc/rmt.conf + User can also choose to restart the server after config update from the cli itself. * `rmt-cli systems list`: Lists systems registered against RMT.