Module: IsaacToolbelt::Helper
Instance Method Summary collapse
- #check_file(filename) ⇒ Object
- #config_network ⇒ Object
- #host ⇒ Object
- #mkdir_if_not(destination_path) ⇒ Object
- #reboot ⇒ Object
-
#ssh_run_command(cmd_string) ⇒ Object
ssh options: -o LogLevel=info.
- #temp_path ⇒ Object
- #transfer_files(destination_path) ⇒ Object
- #upload_string_as_file(string, dst) ⇒ Object
- #waitfor(message = nil) ⇒ Object
- #waitfor_network ⇒ Object
Instance Method Details
#check_file(filename) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/isaac_toolbelt.rb', line 87 def check_file(filename) unless File.exist?(File.join(Dir.pwd, filename)) STDERR.puts "#{filename} not found!" exit(1) end end |
#config_network ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/isaac_toolbelt.rb', line 126 def config_network SSHKit::Coordinator.new(host).each do dns_settings = StringIO.new("nameserver 8.8.8.8\n") upload! dns_settings, '/etc/resolv.conf' execute :ip, *%w(route replace default via 192.168.2.1) end end |
#host ⇒ Object
94 95 96 |
# File 'lib/isaac_toolbelt.rb', line 94 def host SSHKit::Host.new("#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}") end |
#mkdir_if_not(destination_path) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/isaac_toolbelt.rb', line 102 def mkdir_if_not(destination_path) SSHKit::Coordinator.new(host).each do unless test("[ -d #{destination_path} ]") execute :mkdir, '-p', destination_path end end end |
#reboot ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/isaac_toolbelt.rb', line 150 def reboot puts 'rebooting...' ssh_run_command 'reboot' sleep 10 waitfor puts 'rebooted!' end |
#ssh_run_command(cmd_string) ⇒ Object
ssh options:
-o LogLevel=info
162 163 164 165 166 167 |
# File 'lib/isaac_toolbelt.rb', line 162 def ssh_run_command(cmd_string) Process.fork do exec 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ServerAliveInterval=1 -o ServerAliveCountMax=3 -t %s@%s "%s"' % ['root', DEVICE_IP_ADDRESS, cmd_string] end Process.waitall end |
#temp_path ⇒ Object
98 99 100 |
# File 'lib/isaac_toolbelt.rb', line 98 def temp_path File.join(TEMP_ROOT, Digest::SHA1.hexdigest(Dir.pwd)); end |
#transfer_files(destination_path) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/isaac_toolbelt.rb', line 117 def transfer_files(destination_path) check_file('Procfile') check_file('.gitignore') mkdir_if_not(destination_path) puts "Uploading files to: #{destination_path}" pwd = Dir.pwd ret = system("rsync -av -e \"ssh #{SSH_OPTIONS}\" -C --include=\".env\" --exclude=\".git\" --filter=\":- .gitignore\" #{File.join(pwd, '/')} #{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}:#{destination_path}") end |
#upload_string_as_file(string, dst) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/isaac_toolbelt.rb', line 110 def upload_string_as_file(string, dst) SSHKit::Coordinator.new(host).each do io = StringIO.new(string) upload! io, dst end end |
#waitfor(message = nil) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/isaac_toolbelt.rb', line 134 def waitfor(=nil) until system('ping -c 1 192.168.2.15 > /dev/null 2>&1') do puts || 'waiting board...' sleep 1 end end |
#waitfor_network ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/isaac_toolbelt.rb', line 141 def waitfor_network SSHKit::Coordinator.new(host).each do until test(:ping, *%w(-c 1 8.8.8.8)) do puts 'The board waiting network...' sleep 1 end end end |