Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New setup command for bin/rmt-cli for issue #987 #988

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions lib/rmt/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
72 changes: 72 additions & 0 deletions lib/rmt/cli/setup.rb
Original file line number Diff line number Diff line change
@@ -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 <systemctl restart rmt-server>'
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