class Propro::CLI
Constants
- INIT_TEMPLATES
Public Class Methods
source_root()
click to toggle source
# File lib/propro/cli.rb, line 26 def self.source_root File.join(File.dirname(__FILE__), 'cli/templates') end
Public Instance Methods
build(input)
click to toggle source
# File lib/propro/cli.rb, line 44 def build(input) infile = absolute_path(input) script = Script.load(input).to_bash if (output = options[:output]) File.write(absolute_path(output), script) else STDOUT << script end end
deploy(script_path)
click to toggle source
# File lib/propro/cli.rb, line 59 def deploy(script_path) require 'net/ssh' require 'net/scp' require 'io/console' puts Propro.color_banner puts script = Script.load(script_path) address = (options[:server] || script.get_server) password = (options[:password] || script.get_password || ask_password) user = (options[:user] || script.get_user) remote_home = (user == 'root' ? '/root' : "/home/#{user}") remote_log_path = "#{remote_home}/provision.log" remote_script_path = "#{remote_home}/provision.sh" remote_script_url = address + remote_script_path say_event 'build', script_path script_data = StringIO.new(script.to_bash) raise ArgumentError, 'no server address has been provided' if !address raise ArgumentError, 'no server password has been provided' if !password say_event 'connect', "#{user}@#{address}" Net::SSH.start(address, user, password: password) do |session| say_event 'upload', "#{script_path} -> #{remote_script_url}" session.scp.upload!(script_data, remote_script_path) session.exec!("chmod +x #{remote_script_path}") session.exec!("touch #{remote_log_path}") tail = session.exec("tail -f #{remote_log_path}") do |ch, stream, data| STDOUT.write(data) STDOUT.flush end sleep 1 # ughhhhhh say_event 'run', remote_script_url puts session.exec(remote_script_path) do |ch| ch.on_data { } # mute stdout end end rescue IOError # uggghhhhhhhhhh say_event 'done', "#{address} is rebooting" end
init(outname = nil)
click to toggle source
# File lib/propro/cli.rb, line 32 def init(outname = nil) key = options[:template].to_sym outfile = absolute_path(outname || "#{key}.propro") type = INIT_TEMPLATES[key] @paths = type[:paths] @desc = type[:desc] @sources = Package.sources_for_paths('lib', *@paths) template 'init.tt', outfile end
Private Instance Methods
absolute_path(path)
click to toggle source
# File lib/propro/cli.rb, line 122 def absolute_path(path) if path[0] == '/' path else File.join(Dir.pwd, path) end end
ask_password()
click to toggle source
# File lib/propro/cli.rb, line 114 def ask_password pwd = STDIN.noecho do ask 'password:' end puts pwd end
say_event(event, msg)
click to toggle source
# File lib/propro/cli.rb, line 108 def say_event(event, msg) pad = (7 - event.length) label = "#{event.upcase}" + (" " * pad) puts "\e[36m\e[1m#{label}\e[0m #{msg}" end