class Rtprov::Initializer
Attributes
name[R]
Public Class Methods
new(name)
click to toggle source
# File lib/rtprov/initializer.rb, line 15 def initialize(name) @name = name.dup.freeze end
run(name)
click to toggle source
# File lib/rtprov/initializer.rb, line 11 def self.run(name) new(name).run end
Public Instance Methods
run()
click to toggle source
# File lib/rtprov/initializer.rb, line 19 def run raise "Already exists #{name} directory" if File.exist?(name) mkdir name Dir.chdir(name) do mkdir "routers" touch "routers/.keep" mkdir "templates" touch "templates/.keep" puts "Create encryption_key" key = Encryption.generate_key File.write("encryption_key", key) exec "bundle init" exec "bundle add rtprov -v #{VERSION}" exec "bundle binstubs rtprov" puts "Create .gitignore" gitignore = <<~EOS /encryption_key EOS File.write(".gitignore", gitignore) exec "git init" exec "git add ." end puts <<~EOS ============================================================ !!! Please remember `encryption_key`. Git ignores it. !!! ============================================================ And do below. 1. cd #{name} 2. bin/rtprov edit YOUR_ROUTER_NAME 3. bin/rtprov get YOUR_ROUTER_NAME > tempaltes/config.erb 4. Extract credentials in templates/config.erb EOS end
Private Instance Methods
exec(cmd, *args)
click to toggle source
# File lib/rtprov/initializer.rb, line 63 def exec(cmd, *args) puts "#{cmd} #{args.shelljoin}" o, e, s = Open3.capture3(cmd, *args) unless s.success? warn e raise "`#{cmd} #{args.shelljoin}` failed" end o end