-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathrmt-cli
executable file
·63 lines (52 loc) · 2.51 KB
/
rmt-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
rmt_path = File.expand_path('..', __dir__)
require_relative '../config/boot'
$LOAD_PATH.unshift File.join(rmt_path, 'lib')
require 'etc'
require 'active_support'
require 'active_support/core_ext/string'
require 'active_record'
require 'erb'
require 'yaml'
require 'rmt/config'
require_relative '../config/initializers_cli/disable_deprecation_warnings'
require_relative '../config/initializers_cli/rmt_fast_gettext'
require_relative '../config/initializers_cli/rmt_fast_gettext_cli_locale'
require_relative '../engines/registration_sharing/lib/registration_sharing' if Settings[:regsharing]
relative_load_paths = %w[lib lib/rmt app/models app/services app/validators].map { |dir| File.join(rmt_path, dir) }
ActiveSupport::Dependencies.autoload_paths += relative_load_paths
# Before moving into the default user/group, let's try to fetch the login
# information for this host.
RMT::Config.set_host_system!
if RMT::CLI::Base.process_user_name == 'root'
# set group and then user, otherwise user cannot change group
Process::Sys.setegid(Etc.getgrnam(RMT::DEFAULT_GROUP).gid)
# GPG needs ruid to be set
Process::Sys.setuid(Etc.getpwnam(RMT::DEFAULT_USER).uid)
Process::Sys.seteuid(Etc.getpwnam(RMT::DEFAULT_USER).uid)
end
if File.exist?(RMT::DEFAULT_MIRROR_DIR) && !File.writable?(RMT::DEFAULT_MIRROR_DIR)
warn "Mirroring base directory (#{RMT::DEFAULT_MIRROR_DIR}) is not writable by user '#{RMT::CLI::Base.process_user_name}'"
warn 'Run as root or adjust the permissions.'
exit RMT::CLI::Error::ERROR_OTHER
end
if Settings.try(:host_system).blank? && File.exist?(RMT::CREDENTIALS_FILE_LOCATION) && !File.readable?(RMT::CREDENTIALS_FILE_LOCATION)
warn "Credentials file (#{RMT::CREDENTIALS_FILE_LOCATION}) is not readable by user '#{RMT::CLI::Base.process_user_name}'"
warn "Run as root or adjust the permissions."
end
unless Settings['database']
warn "Error loading database config."
warn 'Please make sure that /etc/rmt.conf is readable by the rmt process and has your database configured.'
exit RMT::CLI::Error::ERROR_OTHER
end
db_config = RMT::Config.db_config
ActiveRecord::Base.establish_connection(db_config)
if ActiveRecord::Base.connection.adapter_name != "Mysql2"
warn "Running with experimental support for #{ActiveRecord::Base.connection.adapter_name}."
warn 'RMT is running without locking operations, make sure not to run it in multipe processes.'
end
begin
RMT::CLI::Main.start(ARGV)
rescue Interrupt
abort "\nInterrupted! You might need to rerun this command to have a consistent state."
end